Hi All,
I am trying to configure Lateral TCP Cache. I have some questions and a problem which
i am not able to solve.
Questions:
1) cache.ccf file should be there in classpath of idividual server or jcs client who
is accessing jcs.
2) Client hast to run on the same jvm of tomcat servers or it can be standalone java
client.
3) What value should be given to following property in cache.ccf file
- jcs.auxiliary.LTCP.attributes.TcpServers=10.1.35.167:8090,10.1.35.167:8080
- jcs.auxiliary.LTCP.attributes.TcpListenerPort=1110
Or
If some one can give steps of configuring Lateral TCP Cache on more than one server.
Problem:
I am running an example with following setting. Two tomcat servers are running on two
different port localhost:8080 and localhost:8090. Now i am running the example but i
am getting following error:
D:\Yomesh\JBProjects\Caching\classes>java com.genericbookstore.data.BookVObjMana
ger ..\cache.ccf
Creating cache manager from config file: ..\cache.ccf
Nov 24, 2003 2:21:30 PM org.apache.jcs.engine.control.CompositeCacheConfigurator
setDefaultAuxValues
INFO: setting defaults to LTCP
Nov 24, 2003 2:21:30 PM org.apache.jcs.engine.control.CompositeCacheConfigurator
setDefaultCompositeCacheAttributes
INFO: setting defaultCompositeCacheAttributes to [ useLateral = true, useRemote
= true, useDisk = true, maxObjs = 2000 ]
Nov 24, 2003 2:21:30 PM org.apache.jcs.engine.control.CompositeCacheConfigurator
setDefaultElementAttributes
INFO: setting defaultElementAttributes to [ IS_LATERAL = false, IS_SPOOL = false
, IS_REMOTE = false, IS_ETERNAL = false, MaxLifeSeconds = 2400, IdleTime = 1800,
CreateTime = 1069663890818, LastAccessTime = 1069663890818, getTimeToLiveSecond
s() = 2399985, createTime = 1069663890818 ]
Nov 24, 2003 2:21:30 PM org.apache.jcs.engine.memory.lru.LRUMemoryCache initiali
ze
INFO: initialized LRUMemoryCache for JCSTest$Dog
Nov 24, 2003 2:21:30 PM org.apache.jcs.engine.control.CompositeCache <init>
INFO: Constructed cache with name: JCSTest$Dog
Nov 24, 2003 2:21:30 PM org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPLi
stener$ListenerThread run
INFO: Listening on port 1110
Nov 24, 2003 2:21:31 PM org.apache.jcs.engine.memory.lru.LRUMemoryCache initiali
ze
INFO: initialized LRUMemoryCache for bookCache
Nov 24, 2003 2:21:31 PM org.apache.jcs.engine.control.CompositeCache <init>
INFO: Constructed cache with name: bookCache
Nov 24, 2003 2:21:31 PM org.apache.jcs.engine.memory.lru.LRUMemoryCache initiali
ze
INFO: initialized LRUMemoryCache for JCSTest$Cat
Nov 24, 2003 2:21:31 PM org.apache.jcs.engine.control.CompositeCache <init>
INFO: Constructed cache with name: JCSTest$Cat
Book cache is NOT null
Nov 24, 2003 2:21:41 PM org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPSe
nder sendAndReceive
SEVERE: Could not open ObjectInputStream to Socket[addr=/10.1.35.167,port=8090,l
ocalport=1929]
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java
:2150)
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream
.java:2163)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputS
tream.java:2631)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:734
)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)
at org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPSender.sendAndR
eceive(LateralTCPSender.java:229)
at org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPService.get(Lat
eralTCPService.java:196)
at org.apache.jcs.auxiliary.lateral.LateralCache.get(LateralCache.java:1
25)
at org.apache.jcs.auxiliary.lateral.LateralCacheNoWait.get(LateralCacheN
oWait.java:76)
at org.apache.jcs.auxiliary.lateral.LateralCacheNoWaitFacade.get(Lateral
CacheNoWaitFacade.java:74)
at org.apache.jcs.engine.control.CompositeCache.get(CompositeCache.java:
533)
at org.apache.jcs.engine.control.CompositeCache.get(CompositeCache.java:
440)
at org.apache.jcs.access.CacheAccess.get(CacheAccess.java:236)
at com.genericbookstore.data.BookVObjManager.getBookVObj(BookVObjManager
.java:85)
at com.genericbookstore.data.BookVObjManager.getBookVObj(BookVObjManager
.java:70)
at com.genericbookstore.data.BookVObjManager.main(BookVObjManager.java:2
03)
vObj is null. loading vObj
Author name is Yomesh
Removing vObj
Nov 24, 2003 2:21:52 PM org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPSe
nder sendAndReceive
SEVERE: Could not open ObjectInputStream to Socket[addr=/10.1.35.167,port=8090,l
ocalport=1929]
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java
:2150)
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream
.java:2163)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputS
tream.java:2631)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:734
)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)
at org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPSender.sendAndR
eceive(LateralTCPSender.java:229)
at org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPService.get(Lat
eralTCPService.java:196)
at org.apache.jcs.auxiliary.lateral.LateralCache.get(LateralCache.java:1
25)
at org.apache.jcs.auxiliary.lateral.LateralCacheNoWait.get(LateralCacheN
oWait.java:76)
at org.apache.jcs.auxiliary.lateral.LateralCacheNoWaitFacade.get(Lateral
CacheNoWaitFacade.java:74)
at org.apache.jcs.engine.control.CompositeCache.get(CompositeCache.java:
533)
at org.apache.jcs.engine.control.CompositeCache.get(CompositeCache.java:
440)
at org.apache.jcs.access.CacheAccess.get(CacheAccess.java:236)
at com.genericbookstore.data.BookVObjManager.storeBookVObj(BookVObjManag
er.java:151)
at com.genericbookstore.data.BookVObjManager.main(BookVObjManager.java:2
10)
vObj is successfuly removed
Author name is Sachin
Author name has already changed
.
The cache.ccf file
# DEFAULT CACHE REGION
# sets the default aux value for any non configured caches
jcs.default=LTCP
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=2000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.elementattributes.MaxLifeSeconds=2400
jcs.default.elementattributes.IdleTime=1800
jcs.default.elementattributes.IsSpool=false
jcs.default.elementattributes.IsRemote=false
jcs.default.elementattributes.IsLateral=false
jcs.auxiliary.LTCP=org.apache.jcs.auxiliary.lateral.LateralCacheFactory
jcs.auxiliary.LTCP.attributes=org.apache.jcs.auxiliary.lateral.LateralCacheAttributes
jcs.auxiliary.LTCP.attributes.TransmissionTypeName=TCP
jcs.auxiliary.LTCP.attributes.TcpServers=10.1.35.167:8090,10.1.35.167:8080
jcs.auxiliary.LTCP.attributes.TcpListenerPort=1110
jcs.auxiliary.LTCP.attributes.PutOnlyMode=false
#Book Cache
jcs.region.bookCache=LTCP
jcs.region.bookCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.bookCache.cacheattributes.MaxObjects=4000
jcs.region.bookCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.bookCache.cacheattributes.UseMemoryShrinker=true
jcs.region.bookCache.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.region.bookCache.cacheattributes.ShrinkerIntervalSeconds=600
jcs.region.bookCache.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.bookCache.elementattributes.IsEternal=false
jcs.region.bookCache.elementattributes.MaxLifeSeconds=2400
jcs.region.bookCache.elementattributes.IdleTime=180
jcs.region.bookCache.elementattributes.IsSpool=false
jcs.region.bookCache.elementattributes.IsRemote=false
jcs.region.bookCache.elementattributes.IsLateral=true
===============
The code is
// java com.genericbookstore.data.BookVObjManager
package com.genericbookstore.data;
import org.apache.jcs.JCS;
// in case we want to set some special behavior
import org.apache.jcs.engine.behavior.IElementAttributes;
import org.apache.jcs.engine.control.CompositeCacheManager;
import java.io.*;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class BookVObjManager {
private static BookVObjManager instance;
private static int checkedOut = 0;
private static JCS bookCache;
private BookVObjManager() {
try {
bookCache = JCS.getInstance("bookCache");
if (bookCache == null) {
System.out.println("Book cache is null");
}
else {
System.out.println("Book cache is NOT null");
}
}
catch (Exception e) {
// Handle cache region initialization failure
System.out.println("Error in creating object");
e.printStackTrace();
}
// Do other initialization that may be necessary, such as getting
// references to any data access classes we may need to populate
// value objects later
}
/**
* Singleton access point to the manager.
*/
public static BookVObjManager getInstance() {
if (instance == null) {
synchronized (BookVObjManager.class) {
if (instance == null) {
instance = new BookVObjManager();
}
}
}
synchronized (instance) {
instance.checkedOut++;
}
return instance;
}
/**
* Retrieves a BookVObj. Default to look in the cache.
*/
public BookVObj getBookVObj(int id) {
return getBookVObj(id, true);
}
/**
* Retrieves a BookVObj. Second argument decides whether to look
* in the cache. Returns a new value object if one can't be
* loaded from the database. Database cache synchronization is
* handled by removing cache elements upon modification.
*/
public BookVObj getBookVObj(int id, boolean fromCache) {
BookVObj vObj = null;
// First, if requested, attempt to load from cache
if (fromCache) {
vObj = (BookVObj) bookCache.get("BookVObj" + id);
}
// Either fromCache was false or the object was not found, so
// call loadBookVObj to create it
if (vObj == null) {
System.out.println("vObj is null. loading vObj");
vObj = loadBookVObj(id);
}
return vObj;
}
/**
* Creates a BookVObj based on the id of the BOOK table. Data
* access could be direct JDBC, some or mapping tool, or an EJB.
*/
public BookVObj loadBookVObj(int id) {
BookVObj vObj = new BookVObj();
vObj.bookID = id;
vObj.author = "Yomesh";
try {
boolean found = false;
// load the data and set the rest of the fields
// set found to true if it was found
found = true;
// cache the value object if found
if (found) {
// could use the defaults like this
// bookCache.put( "BookVObj" + id, vObj );
// or specify special characteristics
// put to cache
bookCache.put("BookVObj" + id, vObj);
}
}
catch (Exception e) {
// Handle failure putting object to cache
}
return vObj;
}
/**
* Stores BookVObj's in database. Clears old items and caches
* new.
*/
public int storeBookVObj(BookVObj vObj) {
try {
// since any cached data is no longer valid, we should
// remove the item from the cache if it an update.
if (vObj.bookID != 0) {
bookCache.remove("BookVObj" + vObj.bookID);
System.out.println("Removing vObj");
BookVObj aObj = (BookVObj) bookCache.get("BookVObj" + vObj.bookID);
if (aObj == null) {
System.out.println("vObj is successfuly removed");
// put the new object in the cache
bookCache.put("BookVObj" + vObj.bookID, vObj);
}
else {
System.out.println("Could not remove vObj");
}
}
}
catch (Exception e) {
// Handle failure removing object or putting object to cache.
}
return vObj.bookID;
}
public static void configure(String propFile) {
System.out.println("Creating cache manager from config file: " + propFile);
Properties props = new Properties();
InputStream is = null;
try {
//Check to see if we can get the file in propFile from the claspath.
is = new FileInputStream(new File(propFile));
props.load(is);
}
catch (IOException ex) {
System.out.println("Failed to load properties");
ex.printStackTrace();
throw new IllegalStateException(ex.getMessage());
}
finally {
try {
is.close();
}
catch (Exception ignore) {
// Ignored
}
}
CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance();
cm.configure(props);
}
public static void main(String args[]) {
configure(args[0]);
BookVObjManager mb = BookVObjManager.getInstance();
BookVObj obj = mb.getBookVObj(20);
System.out.println("Author name is " + obj.author);
if (obj.author.equals("Sachin")) {
System.out.println("Author name has already changed");
}
else {
obj.author = "Sachin";
mb.storeBookVObj(obj);
}
obj = mb.getBookVObj(20);
System.out.println("Author name is " + obj.author);
if (obj.author.equals("Sachin")) {
System.out.println("Author name has already changed");
}
else {
System.out.println("Author name has not changed");
}
}
}
======
The data class is
package com.genericbookstore.data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class BookVObj implements Serializable
{
public int bookID = 0;
public String title;
public String author;
public String ISBN;
public String price;
public Date publishDate;
public BookVObj()
{
}
}
=====================
DISCLAIMER:
Information contained and transmitted by this E-MAIL is proprietary to Hexaware
Technologies Limited and is intended for use only by the individual or entity to which
it is addressed and may contain information that is privileged, confidential or exempt
from disclosure under applicable law. If this is a forwarded message, the content of
this E-MAIL may not have been sent with the authority of the Company. If you are not
the intended recipient, an agent of the intended recipient or a person responsible for
delivering the information to the named recipient, you are notified that any use,
distribution, transmission, printing, copying or dissemination of this information in
any way or in any manner is strictly prohibited. If you have received this
communication in error, please delete this mail & notify us immediately at [EMAIL
PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]