[jboss-cvs] JBossCache/src/org/jboss/cache/loader ...
Manik Surtani
msurtani at jboss.com
Wed Oct 25 08:49:31 EDT 2006
User: msurtani
Date: 06/10/25 08:49:31
Modified: src/org/jboss/cache/loader TcpDelegatingCacheLoader.java
Log:
JBCACHE-690
JBCACHE-800
JBCACHE-810
Revision Changes Path
1.5 +139 -85 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.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- TcpDelegatingCacheLoader.java 23 Oct 2006 05:46:39 -0000 1.4
+++ TcpDelegatingCacheLoader.java 25 Oct 2006 12:49:31 -0000 1.5
@@ -10,6 +10,8 @@
import org.jboss.cache.Modification;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -31,7 +33,7 @@
* </pre>
*
* @author Bela Ban
- * @version $Id: TcpDelegatingCacheLoader.java,v 1.4 2006/10/23 05:46:39 bstansberry Exp $
+ * @version $Id: TcpDelegatingCacheLoader.java,v 1.5 2006/10/25 12:49:31 msurtani Exp $
*/
public class TcpDelegatingCacheLoader extends DelegatingCacheLoader
{
@@ -63,7 +65,7 @@
/**
* Allows configuration via XML config file.
*
- * @see DelegatingCacheLoader#setConfig(java.util.Properties)
+ * @see DelegatingCacheLoader#setConfig(org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig)
*/
public void setConfig(IndividualCacheLoaderConfig base)
{
@@ -116,8 +118,9 @@
private void init() throws IOException
{
sock = new Socket(config.getHost(), config.getPort());
- out = new ObjectOutputStream(sock.getOutputStream());
- in = new ObjectInputStream(sock.getInputStream());
+ out = new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream()));
+ out.flush();
+ in = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));
}
/**
@@ -125,20 +128,25 @@
*/
protected Set delegateGetChildrenNames(Fqn fqn) throws Exception
{
+ synchronized (out)
+ {
+ out.reset();
out.writeInt(DelegatingCacheLoader.delegateGetChildrenNames);
out.writeObject(fqn);
+ out.flush();
Object retval = in.readObject();
if (retval instanceof Exception)
{
- throw (Exception) retval;
+ throw(Exception) retval;
}
return (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)
+ * @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);
@@ -152,53 +160,75 @@
*/
protected Map delegateGet(Fqn name) throws Exception
{
+ synchronized (out)
+ {
+ out.reset();
+
out.writeInt(DelegatingCacheLoader.delegateGet);
out.writeObject(name);
+ out.flush();
Object retval = in.readObject();
if (retval instanceof Exception)
{
- throw (Exception) retval;
+ throw(Exception) retval;
}
return (Map) retval;
}
+ }
/**
* @see org.jboss.cache.loader.DelegatingCacheLoader#delegateExists(org.jboss.cache.Fqn)
*/
protected boolean delegateExists(Fqn name) throws Exception
{
+ synchronized (out)
+ {
+ out.reset();
+
out.writeInt(DelegatingCacheLoader.delegateExists);
out.writeObject(name);
+ out.flush();
Object retval = in.readObject();
if (retval instanceof Exception)
{
- throw (Exception) retval;
+ throw(Exception) retval;
+ }
+ return (Boolean) retval;
}
- return ((Boolean) retval).booleanValue();
}
/**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegatePut(org.jboss.cache.Fqn, Object, Object)
+ * @see org.jboss.cache.loader.DelegatingCacheLoader#delegatePut(org.jboss.cache.Fqn,Object,Object)
*/
protected Object delegatePut(Fqn name, Object key, Object value) throws Exception
{
+ synchronized (out)
+ {
+ out.reset();
+
out.writeInt(DelegatingCacheLoader.delegatePutKeyVal);
out.writeObject(name);
out.writeObject(key);
out.writeObject(value);
+ out.flush();
Object retval = in.readObject();
if (retval instanceof Exception)
{
- throw (Exception) retval;
+ throw(Exception) retval;
}
return retval;
}
+ }
/**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegatePut(org.jboss.cache.Fqn, java.util.Map)
+ * @see org.jboss.cache.loader.DelegatingCacheLoader#delegatePut(org.jboss.cache.Fqn,java.util.Map)
*/
protected void delegatePut(Fqn name, Map attributes) throws Exception
{
+ synchronized (out)
+ {
+ out.reset();
+
out.writeInt(DelegatingCacheLoader.delegatePut);
out.writeObject(name);
out.writeObject(attributes);
@@ -206,13 +236,18 @@
Object retval = in.readObject();
if (retval instanceof Exception)
{
- throw (Exception) retval;
+ throw(Exception) retval;
+ }
}
}
@Override
public void put(List<Modification> modifications) throws Exception
{
+ synchronized (out)
+ {
+ out.reset();
+
out.writeInt(DelegatingCacheLoader.putList);
int length = modifications != null ? modifications.size() : 0;
out.writeInt(length);
@@ -227,38 +262,50 @@
Object retval = in.readObject();
if (retval instanceof Exception)
{
- throw (Exception) retval;
+ throw(Exception) retval;
+ }
}
}
/**
- * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateRemove(org.jboss.cache.Fqn, Object)
+ * @see org.jboss.cache.loader.DelegatingCacheLoader#delegateRemove(org.jboss.cache.Fqn,Object)
*/
protected Object delegateRemove(Fqn name, Object key) throws Exception
{
+ synchronized (out)
+ {
+ out.reset();
+
out.writeInt(DelegatingCacheLoader.delegateRemoveKey);
out.writeObject(name);
out.writeObject(key);
+ out.flush();
Object retval = in.readObject();
if (retval instanceof Exception)
{
- throw (Exception) retval;
+ throw(Exception) retval;
}
return retval;
}
+ }
/**
* @see org.jboss.cache.loader.DelegatingCacheLoader#delegateRemove(org.jboss.cache.Fqn)
*/
protected void delegateRemove(Fqn name) throws Exception
{
+ synchronized (out)
+ {
+ out.reset();
+
out.writeInt(DelegatingCacheLoader.delegateRemove);
out.writeObject(name);
out.flush();
Object retval = in.readObject();
if (retval instanceof Exception)
{
- throw (Exception) retval;
+ throw(Exception) retval;
+ }
}
}
@@ -267,13 +314,18 @@
*/
protected void delegateRemoveData(Fqn name) throws Exception
{
+ synchronized (out)
+ {
+ out.reset();
+
out.writeInt(DelegatingCacheLoader.delegateRemoveData);
out.writeObject(name);
out.flush();
Object retval = in.readObject();
if (retval instanceof Exception)
{
- throw (Exception) retval;
+ throw(Exception) retval;
+ }
}
}
@@ -303,11 +355,13 @@
public static class Config extends IndividualCacheLoaderConfig
{
- /** The serialVersionUID */
+ /**
+ * The serialVersionUID
+ */
private static final long serialVersionUID = -3138555335000168505L;
private String host = "localhost";
- private int port;;
+ private int port = 7500;
public Config()
{
More information about the jboss-cvs-commits
mailing list