Search in sources :

Example 1 with ClusterPacketRouter

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

the class ClusteredCacheFactory method startCluster.

public boolean startCluster() {
    state = State.starting;
    // Set the serialization strategy to use for transmitting objects between node clusters
    serializationStrategy = ExternalizableUtil.getInstance().getStrategy();
    ExternalizableUtil.getInstance().setStrategy(new ClusterExternalizableUtil());
    // Set session locator to use when in a cluster
    XMPPServer.getInstance().setRemoteSessionLocator(new RemoteSessionLocator());
    // Set packet router to use to deliver packets to remote cluster nodes
    XMPPServer.getInstance().getRoutingTable().setRemotePacketRouter(new ClusterPacketRouter());
    ClassLoader oldLoader = null;
    // Store previous class loader (in case we change it)
    oldLoader = Thread.currentThread().getContextClassLoader();
    ClassLoader loader = new ClusterClassLoader();
    Thread.currentThread().setContextClassLoader(loader);
    int retry = 0;
    do {
        try {
            Config config = new ClasspathXmlConfig(HAZELCAST_CONFIG_FILE);
            config.setInstanceName("openfire");
            config.setClassLoader(loader);
            if (JMXManager.isEnabled() && HAZELCAST_JMX_ENABLED) {
                config.setProperty("hazelcast.jmx", "true");
                config.setProperty("hazelcast.jmx.detailed", "true");
            }
            hazelcast = Hazelcast.newHazelcastInstance(config);
            cluster = hazelcast.getCluster();
            // Update the running state of the cluster
            state = cluster != null ? State.started : State.stopped;
            // Set the ID of this cluster node
            XMPPServer.getInstance().setNodeID(NodeID.getInstance(getClusterMemberID()));
            // CacheFactory is now using clustered caches. We can add our listeners.
            clusterListener = new ClusterListener(cluster);
            lifecycleListener = hazelcast.getLifecycleService().addLifecycleListener(clusterListener);
            membershipListener = cluster.addMembershipListener(clusterListener);
            break;
        } catch (Exception e) {
            if (retry < CLUSTER_STARTUP_RETRY_COUNT) {
                logger.warn("Failed to start clustering (" + e.getMessage() + "); " + "will retry in " + CLUSTER_STARTUP_RETRY_TIME + " seconds");
                try {
                    Thread.sleep(CLUSTER_STARTUP_RETRY_TIME * 1000);
                } catch (InterruptedException ie) {
                /* ignore */
                }
            } else {
                logger.error("Unable to start clustering - continuing in local mode", e);
                state = State.stopped;
            }
        }
    } while (retry++ < CLUSTER_STARTUP_RETRY_COUNT);
    if (oldLoader != null) {
        // Restore previous class loader
        Thread.currentThread().setContextClassLoader(oldLoader);
    }
    return cluster != null;
}
Also used : ClusterPacketRouter(org.jivesoftware.openfire.plugin.util.cluster.ClusterPacketRouter) RemoteSessionLocator(org.jivesoftware.openfire.plugin.session.RemoteSessionLocator) Config(com.hazelcast.config.Config) ClasspathXmlConfig(com.hazelcast.config.ClasspathXmlConfig) ClasspathXmlConfig(com.hazelcast.config.ClasspathXmlConfig) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ClasspathXmlConfig (com.hazelcast.config.ClasspathXmlConfig)1 Config (com.hazelcast.config.Config)1 TimeoutException (java.util.concurrent.TimeoutException)1 RemoteSessionLocator (org.jivesoftware.openfire.plugin.session.RemoteSessionLocator)1 ClusterPacketRouter (org.jivesoftware.openfire.plugin.util.cluster.ClusterPacketRouter)1