Search in sources :

Example 1 with ClasspathXmlConfig

use of com.hazelcast.config.ClasspathXmlConfig 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)

Example 2 with ClasspathXmlConfig

use of com.hazelcast.config.ClasspathXmlConfig in project okapi by folio-org.

the class MainDeploy method parseOptions.

private boolean parseOptions(String[] args, Handler<AsyncResult<Vertx>> fut) {
    int i = 0;
    while (i < args.length) {
        if (!args[i].startsWith("-")) {
            if ("help".equals(args[i])) {
                out.println("Usage: command [options]\n" + "Commands:\n" + "  help         Display help\n" + "  cluster      Run in clustered mode\n" + "  dev          Development mode\n" + "  deployment   Deployment only. Clustered mode\n" + "  proxy        Proxy + discovery. Clustered mode\n" + "Options:\n" + "  -hazelcast-config-cp file     Read config from class path\n" + "  -hazelcast-config-file file   Read config from local file\n" + "  -hazelcast-config-url url     Read config from URL\n" + "  -cluster-host ip              Vertx cluster host\n" + "  -cluster-port port            Vertx cluster port\n" + "  -enable-metrics\n");
                fut.handle(Future.succeededFuture(null));
                return true;
            }
            conf.put("mode", args[i]);
        } else if ("-hazelcast-config-cp".equals(args[i]) && i < args.length - 1) {
            i++;
            String resource = args[i];
            try {
                hConfig = new ClasspathXmlConfig(resource);
            } catch (Exception e) {
                fut.handle(Future.failedFuture(CANNOT_LOAD_STR + resource + ": " + e));
                return true;
            }
        } else if ("-hazelcast-config-file".equals(args[i]) && i < args.length - 1) {
            i++;
            String resource = args[i];
            try {
                hConfig = new FileSystemXmlConfig(resource);
            } catch (Exception e) {
                fut.handle(Future.failedFuture(CANNOT_LOAD_STR + resource + ": " + e));
                return true;
            }
        } else if ("-hazelcast-config-url".equals(args[i]) && i < args.length - 1) {
            i++;
            String resource = args[i];
            try {
                hConfig = new UrlXmlConfig(resource);
            } catch (Exception e) {
                fut.handle(Future.failedFuture(CANNOT_LOAD_STR + resource + ": " + e));
                return true;
            }
        } else if ("-cluster-host".equals(args[i]) && i < args.length - 1) {
            i++;
            clusterHost = args[i];
        } else if ("-cluster-port".equals(args[i]) && i < args.length - 1) {
            i++;
            clusterPort = Integer.parseInt(args[i]);
        } else if ("-enable-metrics".equals(args[i])) {
            final String graphiteHost = getProperty("graphiteHost", "localhost");
            final Integer graphitePort = parseInt(getProperty("graphitePort", "2003"));
            final TimeUnit tu = TimeUnit.valueOf(getProperty("reporterTimeUnit", "SECONDS"));
            final Integer reporterPeriod = parseInt(getProperty("reporterPeriod", "1"));
            final String hostName = getProperty("host", "localhost");
            DropwizardHelper.config(graphiteHost, graphitePort, tu, reporterPeriod, vopt, hostName);
        } else {
            fut.handle(Future.failedFuture("Invalid option: " + args[i]));
            return true;
        }
        i++;
    }
    return false;
}
Also used : UrlXmlConfig(com.hazelcast.config.UrlXmlConfig) Integer(java.lang.Integer) ClasspathXmlConfig(com.hazelcast.config.ClasspathXmlConfig) TimeUnit(java.util.concurrent.TimeUnit) FileSystemXmlConfig(com.hazelcast.config.FileSystemXmlConfig)

Example 3 with ClasspathXmlConfig

use of com.hazelcast.config.ClasspathXmlConfig in project qi4j-sdk by Qi4j.

the class HazelcastEntityStoreMixin method createConfig.

private Config createConfig(HazelcastConfiguration configuration) throws IOException {
    String hzConfLocation = configuration.configXmlLocation().get();
    if (hzConfLocation == null) {
        hzConfLocation = "org/qi4j/entitystore/hazelcast/defaultConfiguration.xml";
    }
    Config conf;
    if (hzConfLocation.contains(":")) {
        conf = new UrlXmlConfig(hzConfLocation);
    } else {
        conf = new ClasspathXmlConfig(hzConfLocation);
    }
    return conf;
}
Also used : UrlXmlConfig(com.hazelcast.config.UrlXmlConfig) Config(com.hazelcast.config.Config) UrlXmlConfig(com.hazelcast.config.UrlXmlConfig) ClasspathXmlConfig(com.hazelcast.config.ClasspathXmlConfig) ClasspathXmlConfig(com.hazelcast.config.ClasspathXmlConfig)

Example 4 with ClasspathXmlConfig

use of com.hazelcast.config.ClasspathXmlConfig in project SSM by Intel-bigdata.

the class GetConf method getSmartServers.

public static int getSmartServers(PrintStream p) {
    ClasspathXmlConfig conf = new ClasspathXmlConfig("hazelcast.xml");
    List<String> ret = conf.getNetworkConfig().getJoin().getTcpIpConfig().getMembers();
    for (String s : ret) {
        p.println(s);
    }
    return 0;
}
Also used : ClasspathXmlConfig(com.hazelcast.config.ClasspathXmlConfig)

Example 5 with ClasspathXmlConfig

use of com.hazelcast.config.ClasspathXmlConfig in project gora by apache.

the class GoraHazelcastTestDriver method setUpClass.

@Override
public void setUpClass() {
    log.info("Starting Hazelcast server side cache provider.");
    Config config = new ClasspathXmlConfig(CONFIG);
    hazelcastInstance = Hazelcast.newHazelcastInstance(config);
}
Also used : Config(com.hazelcast.config.Config) ClasspathXmlConfig(com.hazelcast.config.ClasspathXmlConfig) ClasspathXmlConfig(com.hazelcast.config.ClasspathXmlConfig)

Aggregations

ClasspathXmlConfig (com.hazelcast.config.ClasspathXmlConfig)9 Config (com.hazelcast.config.Config)6 UrlXmlConfig (com.hazelcast.config.UrlXmlConfig)2 FileSystemXmlConfig (com.hazelcast.config.FileSystemXmlConfig)1 MemberGroupConfig (com.hazelcast.config.MemberGroupConfig)1 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)1 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 FileNotFoundException (java.io.FileNotFoundException)1 Integer (java.lang.Integer)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 RemoteSessionLocator (org.jivesoftware.openfire.plugin.session.RemoteSessionLocator)1 ClusterPacketRouter (org.jivesoftware.openfire.plugin.util.cluster.ClusterPacketRouter)1 Before (org.junit.Before)1 Test (org.junit.Test)1