[jbosscache-commits] JBoss Cache SVN: r7366 - core/trunk/src/main/java/org/jboss/cache/loader/tcp.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Mon Jan 5 08:42:44 EST 2009
Author: manik.surtani at jboss.com
Date: 2009-01-05 08:42:43 -0500 (Mon, 05 Jan 2009)
New Revision: 7366
Modified:
core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java
Log:
JBCACHE-1457 - TcpCacheServer: Listening thread should attempt recovery
Modified: core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java 2009-01-05 11:59:09 UTC (rev 7365)
+++ core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java 2009-01-05 13:42:43 UTC (rev 7366)
@@ -46,6 +46,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -162,6 +163,7 @@
@Override
public void run()
{
+ boolean attemptRestart = false;
try
{
while (running)
@@ -182,13 +184,28 @@
}
else
{
- log.error("Caught exception! Shutting down server thread.", se);
+ log.error("Caught exception! Attempting a server restart", se);
+ attemptRestart = true;
}
}
catch (IOException e)
{
- log.error("Caught exception! Shutting down server thread.", e);
+ log.error("Caught exception! Attempting a server restart", e);
+ attemptRestart = true;
}
+
+ if (attemptRestart)
+ {
+ try
+ {
+ TcpCacheServer.this.stop();
+ TcpCacheServer.this.start();
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Caught exception trying to restart cache server", e);
+ }
+ }
}
};
serverThread.setDaemon(daemon);
@@ -198,30 +215,33 @@
public void stop()
{
- running = false;
- synchronized (conns)
+ if (running)
{
- // Connection.close() removes conn from the list,
- // so copy off the list first to avoid ConcurrentModificationException
- List<Connection> copy = new ArrayList<Connection>(conns);
- for (Connection conn : copy)
+ running = false;
+ synchronized (conns)
{
- conn.close();
+ // Connection.close() removes conn from the list,
+ // so copy off the list first to avoid ConcurrentModificationException
+ List<Connection> copy = new ArrayList<Connection>(conns);
+ for (Connection conn : copy)
+ {
+ conn.close();
+ }
+ conns.clear();
}
- conns.clear();
- }
- if (srv_sock != null)
- {
- try
+ if (srv_sock != null)
{
- srv_sock.close();
+ try
+ {
+ srv_sock.close();
+ }
+ catch (IOException e)
+ {
+ // nada
+ }
srv_sock = null;
}
- catch (IOException e)
- {
- // nada
- }
}
}
@@ -341,7 +361,7 @@
case TcpCacheOperations.GET_CHILDREN_NAMES:
fqn = (Fqn) input.readObject();
Node node = c.getRoot().getChild(fqn);
- Set<Object> children = node == null ? Collections.emptySet() : node.getChildrenNames();
+ Set<Object> children = node == null ? Collections.emptySet() : new HashSet(node.getChildrenNames());
output.writeObject(children);
break;
case TcpCacheOperations.GET_KEY:
@@ -360,7 +380,14 @@
break;
}
Map map = n.getData();
- if (map == null) map = new HashMap();
+ if (map == null)
+ {
+ map = Collections.emptyMap();
+ }
+ else
+ {
+ map = new HashMap(map); // TODO: copy this since FastCopyHashMap has issues with serialization at the moment
+ }
output.writeObject(map);
break;
case TcpCacheOperations.EXISTS:
More information about the jbosscache-commits
mailing list