[jboss-cvs] JBossCache/src/org/jboss/cache/loader ...
Manik Surtani
manik at jboss.org
Tue Jul 17 13:22:13 EDT 2007
User: msurtani
Date: 07/07/17 13:22:13
Modified: src/org/jboss/cache/loader
TcpDelegatingCacheLoader.java
LocalDelegatingCacheLoader.java
AbstractCacheLoader.java FileCacheLoader.java
AdjListJDBCCacheLoader.java
ClusteredCacheLoader.java
Removed: src/org/jboss/cache/loader DelegatingCacheLoader.java
Log:
JBCACHE-1134
Revision Changes Path
1.8 +75 -104 JBossCache/src/org/jboss/cache/loader/TcpDelegatingCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TcpDelegatingCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/TcpDelegatingCacheLoader.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- TcpDelegatingCacheLoader.java 30 Dec 2006 17:50:01 -0000 1.7
+++ TcpDelegatingCacheLoader.java 17 Jul 2007 17:22:13 -0000 1.8
@@ -9,6 +9,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.loader.tcp.TcpCacheOperations;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -32,9 +33,9 @@
* </pre>
*
* @author Bela Ban
- * @version $Id: TcpDelegatingCacheLoader.java,v 1.7 2006/12/30 17:50:01 msurtani Exp $
+ * @version $Id: TcpDelegatingCacheLoader.java,v 1.8 2007/07/17 17:22:13 msurtani Exp $
*/
-public class TcpDelegatingCacheLoader extends DelegatingCacheLoader
+public class TcpDelegatingCacheLoader extends AbstractCacheLoader
{
private Socket sock;
private TcpDelegatingCacheLoaderConfig config;
@@ -63,8 +64,6 @@
/**
* Allows configuration via XML config file.
- *
- * @see DelegatingCacheLoader#setConfig(org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig)
*/
public void setConfig(IndividualCacheLoaderConfig base)
{
@@ -83,54 +82,13 @@
return config;
}
- public void start() throws Exception
- {
- init();
- }
-
- public void stop()
- {
- try
- {
- if (in != null) in.close();
- }
- catch (IOException e)
- {
- }
- try
- {
- if (out != null) out.close();
- }
- catch (IOException e)
- {
- }
- try
- {
- if (sock != null) sock.close();
- }
- catch (IOException e)
- {
- }
- }
-
-
- private void init() throws IOException
- {
- sock = new Socket(config.getHost(), config.getPort());
- out = new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream()));
- out.flush();
- in = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));
- }
-
- /**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateGetChildrenNames(org.jboss.cache.Fqn)
- */
- protected Set delegateGetChildrenNames(Fqn fqn) throws Exception
+ public Set<?> getChildrenNames(Fqn fqn) throws Exception
{
+ Set cn = null;
synchronized (out)
{
out.reset();
- out.writeInt(DelegatingCacheLoader.delegateGetChildrenNames);
+ out.writeByte(TcpCacheOperations.GET_CHILDREN_NAMES);
out.writeObject(fqn);
out.flush();
Object retval = in.readObject();
@@ -138,32 +96,21 @@
{
throw (Exception) retval;
}
- return (Set) retval;
+ cn = (Set) retval;
}
- }
-
- // See http://jira.jboss.com/jira/browse/JBCACHE-118 for why this is commented out.
- /**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateGet(org.jboss.cache.Fqn,Object)
- */
-// protected Object delegateGet(Fqn name, Object key) throws Exception {
-// out.writeInt(DelegatingCacheLoader.delegateGetKey);
-// out.writeObject(name);
-// out.writeObject(key);
-// return in.readObject();
-// }
+ // the cache loader contract is a bit different from the cache when it comes to dealing with childrenNames
+ if (cn.isEmpty()) return null;
+ return cn;
+ }
- /**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateGet(org.jboss.cache.Fqn)
- */
- protected Map delegateGet(Fqn name) throws Exception
+ public Map<Object, Object> get(Fqn name) throws Exception
{
synchronized (out)
{
out.reset();
- out.writeInt(DelegatingCacheLoader.delegateGet);
+ out.writeByte(TcpCacheOperations.GET);
out.writeObject(name);
out.flush();
Object retval = in.readObject();
@@ -175,16 +122,13 @@
}
}
- /**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateExists(org.jboss.cache.Fqn)
- */
- protected boolean delegateExists(Fqn name) throws Exception
+ public boolean exists(Fqn name) throws Exception
{
synchronized (out)
{
out.reset();
- out.writeInt(DelegatingCacheLoader.delegateExists);
+ out.writeByte(TcpCacheOperations.EXISTS);
out.writeObject(name);
out.flush();
Object retval = in.readObject();
@@ -196,16 +140,13 @@
}
}
- /**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegatePut(org.jboss.cache.Fqn,Object,Object)
- */
- protected Object delegatePut(Fqn name, Object key, Object value) throws Exception
+ public Object put(Fqn name, Object key, Object value) throws Exception
{
synchronized (out)
{
out.reset();
- out.writeInt(DelegatingCacheLoader.delegatePutKeyVal);
+ out.writeByte(TcpCacheOperations.PUT_KEY_VAL);
out.writeObject(name);
out.writeObject(key);
out.writeObject(value);
@@ -219,16 +160,13 @@
}
}
- /**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegatePut(org.jboss.cache.Fqn,java.util.Map)
- */
- protected void delegatePut(Fqn name, Map attributes) throws Exception
+ public void put(Fqn name, Map<Object, Object> attributes) throws Exception
{
synchronized (out)
{
out.reset();
- out.writeInt(DelegatingCacheLoader.delegatePut);
+ out.writeByte(TcpCacheOperations.PUT);
out.writeObject(name);
out.writeObject(attributes);
out.flush();
@@ -241,13 +179,55 @@
}
@Override
+ public void start() throws Exception
+ {
+ init();
+ }
+
+ @Override
+ public void stop()
+ {
+ try
+ {
+ if (in != null) in.close();
+ }
+ catch (IOException e)
+ {
+ }
+ try
+ {
+ if (out != null) out.close();
+ }
+ catch (IOException e)
+ {
+ }
+ try
+ {
+ if (sock != null) sock.close();
+ }
+ catch (IOException e)
+ {
+ }
+ }
+
+
+ private void init() throws IOException
+ {
+ sock = new Socket(config.getHost(), config.getPort());
+ out = new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream()));
+ out.flush();
+ in = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));
+ }
+
+
+ @Override
public void put(List<Modification> modifications) throws Exception
{
synchronized (out)
{
out.reset();
- out.writeInt(DelegatingCacheLoader.putList);
+ out.writeByte(TcpCacheOperations.PUT_LIST);
int length = modifications != null ? modifications.size() : 0;
out.writeInt(length);
if (length > 0)
@@ -266,17 +246,14 @@
}
}
- /**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateRemove(org.jboss.cache.Fqn,Object)
- */
- protected Object delegateRemove(Fqn name, Object key) throws Exception
+ public Object remove(Fqn fqn, Object key) throws Exception
{
synchronized (out)
{
out.reset();
- out.writeInt(DelegatingCacheLoader.delegateRemoveKey);
- out.writeObject(name);
+ out.writeByte(TcpCacheOperations.REMOVE_KEY);
+ out.writeObject(fqn);
out.writeObject(key);
out.flush();
Object retval = in.readObject();
@@ -288,17 +265,14 @@
}
}
- /**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateRemove(org.jboss.cache.Fqn)
- */
- protected void delegateRemove(Fqn name) throws Exception
+ public void remove(Fqn fqn) throws Exception
{
synchronized (out)
{
out.reset();
- out.writeInt(DelegatingCacheLoader.delegateRemove);
- out.writeObject(name);
+ out.writeByte(TcpCacheOperations.REMOVE);
+ out.writeObject(fqn);
out.flush();
Object retval = in.readObject();
if (retval instanceof Exception)
@@ -308,17 +282,14 @@
}
}
- /**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateRemoveData(org.jboss.cache.Fqn)
- */
- protected void delegateRemoveData(Fqn name) throws Exception
+ public void removeData(Fqn fqn) throws Exception
{
synchronized (out)
{
out.reset();
- out.writeInt(DelegatingCacheLoader.delegateRemoveData);
- out.writeObject(name);
+ out.writeByte(TcpCacheOperations.REMOVE_DATA);
+ out.writeObject(fqn);
out.flush();
Object retval = in.readObject();
if (retval instanceof Exception)
@@ -329,25 +300,25 @@
}
@Override
- protected void delegateLoadEntireState(ObjectOutputStream os) throws Exception
+ public void loadEntireState(ObjectOutputStream os) throws Exception
{
throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
}
@Override
- protected void delegateLoadState(Fqn subtree, ObjectOutputStream os) throws Exception
+ public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
{
throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
}
@Override
- protected void delegateStoreEntireState(ObjectInputStream is) throws Exception
+ public void storeEntireState(ObjectInputStream is) throws Exception
{
throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
}
@Override
- protected void delegateStoreState(Fqn subtree, ObjectInputStream is) throws Exception
+ public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
{
throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
}
1.17 +27 -28 JBossCache/src/org/jboss/cache/loader/LocalDelegatingCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocalDelegatingCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/LocalDelegatingCacheLoader.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- LocalDelegatingCacheLoader.java 14 Jun 2007 15:30:15 -0000 1.16
+++ LocalDelegatingCacheLoader.java 17 Jul 2007 17:22:13 -0000 1.17
@@ -31,9 +31,9 @@
*
* @author Bela Ban
* @author Daniel Gredler
- * @version $Id: LocalDelegatingCacheLoader.java,v 1.16 2007/06/14 15:30:15 msurtani Exp $
+ * @version $Id: LocalDelegatingCacheLoader.java,v 1.17 2007/07/17 17:22:13 msurtani Exp $
*/
-public class LocalDelegatingCacheLoader extends DelegatingCacheLoader
+public class LocalDelegatingCacheLoader extends AbstractCacheLoader
{
IndividualCacheLoaderConfig config;
@@ -58,17 +58,16 @@
return config;
}
- protected Set delegateGetChildrenNames(Fqn fqn) throws Exception
+ public Set<?> getChildrenNames(Fqn fqn) throws Exception
{
- return delegate.getChildrenNames(fqn);
- }
+ Set cn = delegate.getChildrenNames(fqn);
- // See http://jira.jboss.com/jira/browse/JBCACHE-118 for why this is commented out.
- // protected Object delegateGet(Fqn name, Object key) throws Exception {
- // return delegate.get(name, key);
- // }
+ // the cache loader contract is a bit different from the cache when it comes to dealing with childrenNames
+ if (cn.isEmpty()) return null;
+ return cn;
+ }
- protected Map delegateGet(Fqn name) throws Exception
+ public Map<Object, Object> get(Fqn name) throws Exception
{
NodeSPI n = (NodeSPI) delegate.get(name);
if (n == null) return null;
@@ -78,42 +77,42 @@
return m;
}
- protected void setDelegateCache(CacheImpl delegate)
- {
- this.delegate = delegate;
- }
-
- protected boolean delegateExists(Fqn name) throws Exception
+ public boolean exists(Fqn name) throws Exception
{
return delegate.exists(name);
}
- protected Object delegatePut(Fqn name, Object key, Object value) throws Exception
+ public Object put(Fqn name, Object key, Object value) throws Exception
{
return delegate.put(name, key, value);
}
- protected void delegatePut(Fqn name, Map attributes) throws Exception
+ public void put(Fqn name, Map<Object, Object> attributes) throws Exception
{
delegate.put(name, attributes);
}
- protected Object delegateRemove(Fqn name, Object key) throws Exception
+ public Object remove(Fqn fqn, Object key) throws Exception
+ {
+ return delegate.remove(fqn, key);
+ }
+
+ public void remove(Fqn fqn) throws Exception
{
- return delegate.remove(name, key);
+ delegate.remove(fqn);
}
- protected void delegateRemove(Fqn name) throws Exception
+ public void removeData(Fqn fqn) throws Exception
{
- delegate.remove(name);
+ delegate.removeData(fqn);
}
- protected void delegateRemoveData(Fqn name) throws Exception
+ protected void setDelegateCache(CacheImpl delegate)
{
- delegate.removeData(name);
+ this.delegate = delegate;
}
- protected void delegateLoadEntireState(ObjectOutputStream os) throws Exception
+ public void loadEntireState(ObjectOutputStream os) throws Exception
{
try
{
@@ -138,18 +137,18 @@
}
}
- protected void delegateLoadState(Fqn subtree, ObjectOutputStream os) throws Exception
+ public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
{
throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
}
- protected void delegateStoreEntireState(ObjectInputStream is) throws Exception
+ public void storeEntireState(ObjectInputStream is) throws Exception
{
delegate.getStateTransferManager().setState(is, Fqn.ROOT);
}
- protected void delegateStoreState(Fqn subtree, ObjectInputStream is) throws Exception
+ public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
{
throw new UnsupportedOperationException("setting and loading state for specific Fqns not supported");
}
1.27 +55 -1 JBossCache/src/org/jboss/cache/loader/AbstractCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AbstractCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/AbstractCacheLoader.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- AbstractCacheLoader.java 11 Jun 2007 15:06:07 -0000 1.26
+++ AbstractCacheLoader.java 17 Jul 2007 17:22:13 -0000 1.27
@@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
/**
* A convenience abstract implementation of a {@link CacheLoader}. Specific methods to note are methods like
@@ -45,6 +46,12 @@
protected CacheSPI cache;
protected RegionManager regionManager;
private static final Log log = LogFactory.getLog(AbstractCacheLoader.class);
+ /**
+ * HashMap<Object,List<Modification>>. List of open transactions. Note that this is purely transient, as
+ * we don't use a log, recovery is not available
+ */
+ protected Map<Object, List<Modification>> transactions = new ConcurrentHashMap<Object, List<Modification>>();
+
public void put(Fqn fqn, Map<Object, Object> attributes, boolean erase) throws Exception
{
@@ -272,4 +279,51 @@
{
return cache.getMarshaller();
}
+
+ // empty implementations for loaders that do not wish to implement lifecycle.
+ public void create() throws Exception
+ {
+ }
+
+ public void start() throws Exception
+ {
+ }
+
+ public void stop()
+ {
+ }
+
+ public void destroy()
+ {
+ }
+
+ // Adds simple transactional capabilities to cache loaders that are inherently non-transactional. If your cache loader implementation
+ // is tansactional though, then override these.
+
+ public void prepare(Object tx, List<Modification> modifications, boolean one_phase) throws Exception
+ {
+ if (one_phase)
+ {
+ put(modifications);
+ }
+ else
+ {
+ transactions.put(tx, modifications);
+ }
+ }
+
+ public void commit(Object tx) throws Exception
+ {
+ List<Modification> modifications = transactions.remove(tx);
+ if (modifications == null)
+ {
+ throw new Exception("transaction " + tx + " not found in transaction table");
+ }
+ put(modifications);
+ }
+
+ public void rollback(Object tx)
+ {
+ transactions.remove(tx);
+ }
}
1.36 +1 -48 JBossCache/src/org/jboss/cache/loader/FileCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FileCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/FileCacheLoader.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- FileCacheLoader.java 19 Jun 2007 18:49:33 -0000 1.35
+++ FileCacheLoader.java 17 Jul 2007 17:22:13 -0000 1.36
@@ -4,7 +4,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.Modification;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.lock.StripedLock;
import org.jboss.cache.marshall.ObjectSerializationFactory;
@@ -22,7 +21,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -48,7 +46,7 @@
* @author Bela Ban
* @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
- * @version $Id: FileCacheLoader.java,v 1.35 2007/06/19 18:49:33 msurtani Exp $
+ * @version $Id: FileCacheLoader.java,v 1.36 2007/07/17 17:22:13 msurtani Exp $
*/
@ThreadSafe
public class FileCacheLoader extends AbstractCacheLoader
@@ -62,12 +60,6 @@
private FileCacheLoaderConfig config;
/**
- * HashMap<Object,List<Modification>>. List of open transactions. Note that this is purely transient, as
- * we don't use a log, recovery is not available
- */
- Map<Object, List<Modification>> transactions = new ConcurrentHashMap<Object, List<Modification>>();
-
- /**
* CacheImpl data file.
*/
public static final String DATA = "data.dat";
@@ -154,18 +146,6 @@
}
}
- public void start() throws Exception
- {
- }
-
- public void stop()
- {
- }
-
- public void destroy()
- {
- }
-
public Set<String> getChildrenNames(Fqn fqn) throws Exception
{
lock.acquireLock(fqn, true);
@@ -331,33 +311,6 @@
}
}
- public void prepare(Object tx, List<Modification> modifications, boolean one_phase) throws Exception
- {
- if (one_phase)
- {
- put(modifications);
- }
- else
- {
- transactions.put(tx, modifications);
- }
- }
-
- public void commit(Object tx) throws Exception
- {
- List modifications = transactions.remove(tx);
- if (modifications == null)
- {
- throw new Exception("transaction " + tx + " not found in transaction table");
- }
- put(modifications);
- }
-
- public void rollback(Object tx)
- {
- transactions.remove(tx);
- }
-
/* ----------------------- Private methods ------------------------ */
File getDirectory(Fqn fqn, boolean create)
1.8 +3 -10 JBossCache/src/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AdjListJDBCCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/AdjListJDBCCacheLoader.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- AdjListJDBCCacheLoader.java 29 Jun 2007 10:27:02 -0000 1.7
+++ AdjListJDBCCacheLoader.java 17 Jul 2007 17:22:13 -0000 1.8
@@ -227,10 +227,7 @@
// Service implementation
- public void create() throws Exception
- {
- }
-
+ @Override
public void start() throws Exception
{
cf.start();
@@ -262,6 +259,7 @@
}
}
+ @Override
public void stop()
{
if (config.getDropTable())
@@ -293,11 +291,6 @@
}
}
- public void destroy()
- {
- }
-
-
/**
* Checks that there is a row for the fqn in the database.
*
1.26 +9 -17 JBossCache/src/org/jboss/cache/loader/ClusteredCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ClusteredCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/ClusteredCacheLoader.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- ClusteredCacheLoader.java 2 Jul 2007 10:21:25 -0000 1.25
+++ ClusteredCacheLoader.java 17 Jul 2007 17:22:13 -0000 1.26
@@ -212,6 +212,7 @@
/**
* Does nothing; replication handles put.
*/
+ @Override
public void put(List<Modification> modifications) throws Exception
{
}
@@ -269,6 +270,7 @@
/**
* Does nothing.
*/
+ @Override
public void prepare(Object tx, List modifications, boolean one_phase) throws Exception
{
}
@@ -276,6 +278,7 @@
/**
* Does nothing.
*/
+ @Override
public void commit(Object tx) throws Exception
{
}
@@ -283,48 +286,37 @@
/**
* Does nothing.
*/
+ @Override
public void rollback(Object tx)
{
}
+ @Override
public void loadEntireState(ObjectOutputStream os) throws Exception
{
//intentional no-op
}
+ @Override
public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
{
// intentional no-op
}
+ @Override
public void storeEntireState(ObjectInputStream is) throws Exception
{
// intentional no-op
}
+ @Override
public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
{
// intentional no-op
}
+ @Override
public void setRegionManager(RegionManager manager)
{
}
-
- public void create() throws Exception
- {
- }
-
- public void start() throws Exception
- {
- }
-
- public void stop()
- {
- }
-
- public void destroy()
- {
- }
-
}
More information about the jboss-cvs-commits
mailing list