Search in sources :

Example 1 with ClusterPacketRouter

use of org.jivesoftware.openfire.cluster.ClusterPacketRouter in project Openfire by igniterealtime.

the class CacheFactory method startClustering.

public static void startClustering() {
    if (isClusteringAvailable()) {
        clusteringStarting = true;
        // Set session locator to use when in a cluster
        XMPPServer.getInstance().setRemoteSessionLocator(new RemoteSessionLocatorImpl());
        // Set packet router to use to deliver packets to remote cluster nodes
        XMPPServer.getInstance().getRoutingTable().setRemotePacketRouter(new ClusterPacketRouter());
        clusteringStarted = clusteredCacheFactoryStrategy.startCluster();
        clusteringStarting = false;
    }
    if (clusteringStarted) {
        if (statsThread == null) {
            // Start a timing thread with 1 second of accuracy.
            statsThread = new Thread("Cache Stats") {

                private volatile boolean destroyed = false;

                @Override
                public void run() {
                    XMPPServer.getInstance().addServerListener(new XMPPServerListener() {

                        @Override
                        public void serverStarted() {
                        }

                        @Override
                        public void serverStopping() {
                            destroyed = true;
                        }
                    });
                    ClusterManager.addListener(new ClusterEventListener() {

                        @Override
                        public void joinedCluster() {
                        }

                        @Override
                        public void joinedCluster(byte[] nodeID) {
                        }

                        @Override
                        public void leftCluster() {
                            destroyed = true;
                            ClusterManager.removeListener(this);
                            log.debug("CacheFactory is not listening for cluster events anymore because it left the cluster");
                        }

                        @Override
                        public void leftCluster(byte[] nodeID) {
                        }

                        @Override
                        public void markedAsSeniorClusterMember() {
                        }
                    });
                    // Run the timer indefinitely.
                    while (!destroyed && ClusterManager.isClusteringEnabled()) {
                        // enabled and there are stats to publish).
                        try {
                            cacheFactoryStrategy.updateCacheStats(caches);
                        } catch (Exception e) {
                            log.error(e.getMessage(), e);
                        }
                        try {
                            // Sleep 10 seconds.
                            sleep(10000);
                        } catch (InterruptedException ie) {
                        // Ignore.
                        }
                    }
                    statsThread = null;
                    log.debug("Cache stats thread terminated.");
                }
            };
            statsThread.setDaemon(true);
            statsThread.start();
        }
    }
}
Also used : XMPPServerListener(org.jivesoftware.openfire.XMPPServerListener) ClusterPacketRouter(org.jivesoftware.openfire.cluster.ClusterPacketRouter) RemoteSessionLocatorImpl(org.jivesoftware.openfire.session.RemoteSessionLocatorImpl) ClusterEventListener(org.jivesoftware.openfire.cluster.ClusterEventListener) InitializationException(org.jivesoftware.util.InitializationException)

Aggregations

XMPPServerListener (org.jivesoftware.openfire.XMPPServerListener)1 ClusterEventListener (org.jivesoftware.openfire.cluster.ClusterEventListener)1 ClusterPacketRouter (org.jivesoftware.openfire.cluster.ClusterPacketRouter)1 RemoteSessionLocatorImpl (org.jivesoftware.openfire.session.RemoteSessionLocatorImpl)1 InitializationException (org.jivesoftware.util.InitializationException)1