Commit 3b5df0f1 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

More clustering work.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8644 b35dd754-fafc-0310-a699-88a17e54d16e
parent 183b2eeb
...@@ -145,6 +145,7 @@ public class ClusterManager { ...@@ -145,6 +145,7 @@ public class ClusterManager {
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Should never happen // Should never happen
Log.error(e);
} }
} }
...@@ -168,6 +169,7 @@ public class ClusterManager { ...@@ -168,6 +169,7 @@ public class ClusterManager {
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Should never happen // Should never happen
Log.error(e);
} }
} }
...@@ -175,30 +177,41 @@ public class ClusterManager { ...@@ -175,30 +177,41 @@ public class ClusterManager {
* Triggers event indicating that this JVM is no longer part of the cluster. This could * Triggers event indicating that this JVM is no longer part of the cluster. This could
* happen when disabling clustering support or removing the enterprise plugin that provides * happen when disabling clustering support or removing the enterprise plugin that provides
* clustering support.<p> * clustering support.<p>
* <p/> *
* Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the * Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the
* island were this JVM belonged was marked as "old" then all nodes of that island will * island were this JVM belonged was marked as "old" then all nodes of that island will
* get the <tt>left cluster event</tt> and <tt>joined cluster events</tt>. That means that * get the <tt>left cluster event</tt> and <tt>joined cluster events</tt>. That means that
* caches will be reset and thus will need to be repopulated again with fresh data from this JVM. * caches will be reset and thus will need to be repopulated again with fresh data from this JVM.
* This also includes the case where this JVM was the senior cluster member and when the islands * This also includes the case where this JVM was the senior cluster member and when the islands
* met again then this JVM stopped being the senior member.<p> * met again then this JVM stopped being the senior member.
* <p/> */
* This event will be triggered in another thread. This will avoid potential deadlocks public static void fireLeftCluster() {
* in Coherence. CacheFactory.leftCluster();
// Now notify rest of the listeners
for (ClusterEventListener listener : listeners) {
try {
listener.leftCluster();
}
catch (Exception e) {
Log.error(e);
}
}
}
/**
* Triggers event indicating that another JVM is no longer part of the cluster. This could
* happen when disabling clustering support or removing the enterprise plugin that provides
* clustering support.
* *
* @param asynchronous true if event will be triggered in background * @param nodeID nodeID assigned to the JVM when joining the cluster.
*/ */
public static void fireLeftCluster(boolean asynchronous) { public static void fireLeftCluster(byte[] nodeID) {
try { try {
Event event = new Event(EventType.left_cluster, null); Event event = new Event(EventType.left_cluster, nodeID);
events.put(event); events.put(event);
if (!asynchronous) {
while (!event.isProcessed()) {
Thread.sleep(50);
}
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Should never happen // Should never happen
Log.error(e);
} }
} }
...@@ -211,7 +224,7 @@ public class ClusterManager { ...@@ -211,7 +224,7 @@ public class ClusterManager {
* island will have its own senior cluster member. However, when the islands meet again there * island will have its own senior cluster member. However, when the islands meet again there
* could only be one senior cluster member so one of the senior cluster members will stop playing * could only be one senior cluster member so one of the senior cluster members will stop playing
* that role. When that happens the JVM no longer playing that role will receive the * that role. When that happens the JVM no longer playing that role will receive the
* {@link #fireLeftCluster(boolean)} and {@link #fireJoinedCluster(boolean)} events.<p> * {@link #fireLeftCluster()} and {@link #fireJoinedCluster(boolean)} events.<p>
* <p/> * <p/>
* This event will be triggered in another thread. This will avoid potential deadlocks * This event will be triggered in another thread. This will avoid potential deadlocks
* in Coherence. * in Coherence.
...@@ -260,13 +273,13 @@ public class ClusterManager { ...@@ -260,13 +273,13 @@ public class ClusterManager {
public static synchronized void shutdown() { public static synchronized void shutdown() {
// Reset the LockFactory to the default one // Reset the LockFactory to the default one
LockManager.setLockFactory(new LocalLockFactory()); LockManager.setLockFactory(new LocalLockFactory());
// Reset the session locator to use
XMPPServer.getInstance().setRemoteSessionLocator(null);
// Reset packet router to use to deliver packets to remote cluster nodes // Reset packet router to use to deliver packets to remote cluster nodes
XMPPServer.getInstance().getRoutingTable().setRemotePacketRouter(null); XMPPServer.getInstance().getRoutingTable().setRemotePacketRouter(null);
if (isClusteringStarted()) { if (isClusteringStarted()) {
CacheFactory.shutdown(); CacheFactory.shutdown();
} }
// Reset the session locator to use
XMPPServer.getInstance().setRemoteSessionLocator(null);
} }
/** /**
......
...@@ -379,16 +379,13 @@ public class CacheFactory { ...@@ -379,16 +379,13 @@ public class CacheFactory {
private static void stopClustering() { private static void stopClustering() {
try { try {
CacheFactoryStrategy clusteredFactory = cacheFactoryStrategy; // Stop the cluster
cacheFactoryStrategy.stopCluster();
// Set the strategy to local
cacheFactoryStrategy = (CacheFactoryStrategy) Class.forName(localCacheFactoryClass) cacheFactoryStrategy = (CacheFactoryStrategy) Class.forName(localCacheFactoryClass)
.newInstance(); .newInstance();
clusteringStarted = false; clusteringStarted = false;
// Reset the node ID
XMPPServer.getInstance().setNodeID(null);
// Stop the cluster
clusteredFactory.stopCluster();
} }
catch (Exception e) { catch (Exception e) {
Log.error("Unable to stop clustering - continuing in clustered mode", e); Log.error("Unable to stop clustering - continuing in clustered mode", e);
...@@ -412,10 +409,16 @@ public class CacheFactory { ...@@ -412,10 +409,16 @@ public class CacheFactory {
*/ */
public static void leftCluster() { public static void leftCluster() {
// Loop through clustered caches and change them to local caches (migrate content) // Loop through clustered caches and change them to local caches (migrate content)
for (Cache cache : getAllCaches()) { try {
CacheWrapper cacheWrapper = ((CacheWrapper) cache); CacheFactoryStrategy localStrategy = (CacheFactoryStrategy) Class.forName(localCacheFactoryClass).newInstance();
Cache standaloneCache = cacheFactoryStrategy.createCache(cacheWrapper.getName());
cacheWrapper.setWrappedCache(standaloneCache); for (Cache cache : getAllCaches()) {
CacheWrapper cacheWrapper = ((CacheWrapper) cache);
Cache standaloneCache = localStrategy.createCache(cacheWrapper.getName());
cacheWrapper.setWrappedCache(standaloneCache);
}
} catch (Exception e) {
Log.error("Error reverting caches to local caches", e);
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment