Java 类com.hazelcast.config.JoinConfig 实例源码

项目:hazelcast-demo    文件:HazelcastConfigRuntimeModify.java   
public static void main(String[] args) {
    // 创建默认config对象
    Config config = new Config();

    // 获取network元素<network></network>
    NetworkConfig netConfig = config.getNetworkConfig();
    System.out.println("Default port:" + netConfig.getPort());

    // 设置组网起始监听端口
    netConfig.setPort(9701);
    System.out.println("Customer port:" + netConfig.getPort());
    // 获取join元素<join></join>
    JoinConfig joinConfig = netConfig.getJoin();
    // 获取multicast元素<multicast></multicast>
    MulticastConfig multicastConfig = joinConfig.getMulticastConfig();
    // 输出组播协议端口
    System.out.println(multicastConfig.getMulticastPort());
    // 禁用multicast协议
    multicastConfig.setEnabled(false);

    // 初始化Hazelcast
    Hazelcast.newHazelcastInstance(config);
}
项目:hazelcast-jclouds    文件:JCloudsDiscoveryFactoryTest.java   
@Test
public void discoveryStrategyFactoryTest() {
    JCloudsDiscoveryStrategyFactory jCloudsDiscoveryStrategyFactory = new JCloudsDiscoveryStrategyFactory();
    String xmlFileName = "test-jclouds-config.xml";
    InputStream xmlResource = JCloudsDiscoveryFactoryTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();

    JoinConfig joinConfig = config.getNetworkConfig().getJoin();
    DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();
    DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();

    assertEquals(jCloudsDiscoveryStrategyFactory.getDiscoveryStrategyType(), JCloudsDiscoveryStrategy.class);
    assertEquals(JCloudsDiscoveryStrategy.class.getName(), providerConfig.getClassName());
    assertEquals(jCloudsDiscoveryStrategyFactory.getConfigurationProperties().size(), providerConfig.getProperties().size());
    assertTrue(jCloudsDiscoveryStrategyFactory.
            newDiscoveryStrategy(null, null, new HashMap<String, Comparable>()) instanceof DiscoveryStrategy);
}
项目:app-ms    文件:HazelcastConfiguration.java   
@Bean
public Config hazelcastConfig() {

    final EntryListenerConfig listener = new EntryListenerConfig();
    final Config config = new Config()
        .setNetworkConfig(new NetworkConfig()
            .setJoin(new JoinConfig()
                .setMulticastConfig(new MulticastConfig()
                    .setEnabled(true))))
        .setInstanceName(instanceName)
        .setProperty("hazelcast.logging.type", "slf4j")
        .addMapConfig(new MapConfig()
            .setName(SERVER_STATE)
            .setTimeToLiveSeconds(serverStateExpiration)
            .setMaxIdleSeconds(serverStateExpiration))
        .addMapConfig(new MapConfig()
            .setName(CacheNames.NONCE)
            .setTimeToLiveSeconds(nonceExpirationInSeconds)
            .setMaxIdleSeconds(nonceExpirationInSeconds))
        .addMapConfig(new MapConfig()
            .setName(CacheNames.JWKS)
            .setTimeToLiveSeconds(jwkExpirationInSeconds)
            .setMaxIdleSeconds(jwkExpirationInSeconds)
            .addEntryListenerConfig(listener));

    LOG.debug("hazelcast config={}", config);
    return config;

}
项目:oneops    文件:CacheInitializer.java   
private Config getConfig() {
  Config config = new Config();
  JoinConfig join = config.getNetworkConfig().getJoin();
  join.getTcpIpConfig().setEnabled(true);
  join.getTcpIpConfig().setMembers(cacheHosts);
  join.getMulticastConfig().setEnabled(false);
  join.getAwsConfig().setEnabled(false);
  CacheConfig cacheConfig = configProvider.getCacheConfig(cacheHosts);
  List<QuorumConfig> quorumConfigs = cacheConfig.getQuorumConfigs();
  quorumConfigs.stream().forEach(q -> config.addQuorumConfig(q));
  List<MapConfig> mapConfigs = cacheConfig.getMapConfigs();
  mapConfigs.stream().forEach(c -> config.addMapConfig(c));
  return config;
}
项目:hazelcast-aws    文件:AwsDiscoveryStrategyFactoryTest.java   
@Test
public void parseDiscoveryStrategyConfigPasses() {
    final AwsDiscoveryStrategyFactory factory = new AwsDiscoveryStrategyFactory();
    final Config config = createConfig("test-aws-config.xml");
    final JoinConfig joinConfig = config.getNetworkConfig().getJoin();

    assertFalse(joinConfig.getAwsConfig().isEnabled());
    assertFalse(joinConfig.getTcpIpConfig().isEnabled());
    assertFalse(joinConfig.getMulticastConfig().isEnabled());

    final DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();

    assertTrue(discoveryConfig.isEnabled());
    assertEquals(1, discoveryConfig.getDiscoveryStrategyConfigs().size());

    final DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();
    final Map<String, Comparable> providerProperties = providerConfig.getProperties();
    final Collection<PropertyDefinition> factoryConfigProperties = factory.getConfigurationProperties();

    assertEquals(factory.getDiscoveryStrategyType(), AwsDiscoveryStrategy.class);
    assertEquals(AwsDiscoveryStrategy.class.getName(), providerConfig.getClassName());
    assertEquals(factoryConfigProperties.size(), providerProperties.size());
    for (AwsProperties prop : AwsProperties.values()) {
        assertTrue(factoryConfigProperties.contains(prop.getDefinition()));
    }

    assertEquals("test-access-key", providerProperties.get("access-key"));
    assertEquals("test-secret-key", providerProperties.get("secret-key"));
    assertEquals("test-region", providerProperties.get("region"));
    assertEquals("test-iam-role", providerProperties.get("iam-role"));
    assertEquals("ec2.test-host-header", providerProperties.get("host-header"));
    assertEquals("test-security-group-name", providerProperties.get("security-group-name"));
    assertEquals("test-tag-key", providerProperties.get("tag-key"));
    assertEquals("test-tag-value", providerProperties.get("tag-value"));
    assertEquals("10", providerProperties.get("connection-timeout-seconds"));
    assertEquals("5702", providerProperties.get("hz-port"));
}
项目:dpCms    文件:HazelcastSessionDao.java   
public HazelcastSessionDao() {
    log.info("Initializing Hazelcast Shiro session persistence..");

    // configure Hazelcast instance
    final Config cfg = new Config();
    cfg.setInstanceName(hcInstanceName);
    // group configuration
    cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    mcCfg.setMulticastGroup(HC_MULTICAST_GROUP);
    mcCfg.setMulticastPort(HC_MULTICAST_PORT);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(false);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // get map
    map = Hazelcast.newHazelcastInstance(cfg).getMap(HC_MAP);
    log.info("Hazelcast Shiro session persistence initialized.");
}
项目:eet.osslite.cz    文件:HazelcastConfiguration.java   
private void setNetworkJoin(JoinConfig join) {
    join.getMulticastConfig().setEnabled(false);

    AwsConfig aws = join.getAwsConfig();
    aws.setEnabled(false);
    aws.setAccessKey("AKIAIA2GXRFAH4OTZN4A");
    aws.setSecretKey("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");

    setTcpIpConfig(join.getTcpIpConfig());
}
项目:hazelcast-jclouds    文件:JCloudsDiscoveryFactoryTest.java   
@Test
public void testParsing() {
    String xmlFileName = "test-jclouds-config.xml";
    InputStream xmlResource = JCloudsDiscoveryFactoryTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();

    JoinConfig joinConfig = config.getNetworkConfig().getJoin();

    AwsConfig awsConfig = joinConfig.getAwsConfig();
    assertFalse(awsConfig.isEnabled());

    TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
    assertFalse(tcpIpConfig.isEnabled());

    MulticastConfig multicastConfig = joinConfig.getMulticastConfig();
    assertFalse(multicastConfig.isEnabled());

    DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();
    assertTrue(discoveryConfig.isEnabled());

    assertEquals(1, discoveryConfig.getDiscoveryStrategyConfigs().size());

    DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();

    assertEquals(12, providerConfig.getProperties().size());
    assertEquals("aws-ec2", providerConfig.getProperties().get("provider"));
    assertEquals("test", providerConfig.getProperties().get("identity"));
    assertEquals("test", providerConfig.getProperties().get("credential"));
    assertEquals("zone1,zone2", providerConfig.getProperties().get("zones"));
    assertEquals("region1,region2", providerConfig.getProperties().get("regions"));
    assertEquals("zone1,zone2", providerConfig.getProperties().get("zones"));
    assertEquals("tag1,tag2", providerConfig.getProperties().get("tag-keys"));
    assertEquals("tagvalue1,tagvalue2", providerConfig.getProperties().get("tag-values"));
    assertEquals("group", providerConfig.getProperties().get("group"));
    assertEquals("5702", providerConfig.getProperties().get("hz-port"));
    assertEquals("myfile.json", providerConfig.getProperties().get("credentialPath"));
    assertEquals("myRole", providerConfig.getProperties().get("role-name"));
    assertEquals("http://foo/bar", providerConfig.getProperties().get("endpoint"));
}
项目:hazelcast-jet    文件:WordCountTest.java   
@Before
public void before() throws Exception {
    JetConfig config = new JetConfig();
    config.getInstanceConfig().setCooperativeThreadCount(PARALLELISM);
    Config hazelcastConfig = config.getHazelcastConfig();
    final JoinConfig join = hazelcastConfig.getNetworkConfig().getJoin();
    join.getMulticastConfig().setEnabled(false);
    join.getTcpIpConfig().setEnabled(true).addMember("127.0.0.1");

    for (int i = 1; i < NODE_COUNT; i++) {
        instance = Jet.newJetInstance(config);
    }
    logger = instance.getHazelcastInstance().getLoggingService().getLogger(WordCountTest.class);
    generateMockInput();
}
项目:runrightfast-vertx    文件:TypesafeHazelcastConfig.java   
/**
 * Only multicast and tcpip are currently supported.
 *
 * @return JoinConfig
 */
private JoinConfig joinConfig(final com.typesafe.config.Config config) {
    final JoinConfig join = new JoinConfig();
    join.setTcpIpConfig(tcpIpConfig(config));
    join.setMulticastConfig(multicastConfig(config));
    return join;
}
项目:spring-boot-shiro-orientdb    文件:HazelcastSessionDao.java   
public HazelcastSessionDao() {
    log.info("Initializing Hazelcast Shiro session persistence..");

    // configure Hazelcast instance
    final Config cfg = new Config();
    cfg.setInstanceName(hcInstanceName);
    // group configuration
    cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    mcCfg.setMulticastGroup(HC_MULTICAST_GROUP);
    mcCfg.setMulticastPort(HC_MULTICAST_PORT);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(false);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // get map
    map = Hazelcast.newHazelcastInstance(cfg).getMap(HC_MAP);
    log.info("Hazelcast Shiro session persistence initialized.");
}
项目:bagri    文件:MigrationTest.java   
@Test
@Ignore
public void testDataMigration() throws Exception {

    Config shConfig = new Config();
    shConfig.getNetworkConfig().setPortAutoIncrement(true);
    shConfig.getGroupConfig().setName("schema");
    shConfig.getGroupConfig().setPassword("schemapass");
    JoinConfig shJoin = shConfig.getNetworkConfig().getJoin();
    shJoin.getMulticastConfig().setEnabled(false);
    shJoin.getTcpIpConfig().addMember("localhost").setEnabled(true);
    shConfig.setProperty("hazelcast.logging.type", "slf4j");

    MapConfig mConfig = new MapConfig("test");
    mConfig.getMapStoreConfig().setEnabled(true);
    mConfig.getMapStoreConfig().setWriteDelaySeconds(10);
    mConfig.getMapStoreConfig().setImplementation(new TestCacheStore());
    shConfig.addMapConfig(mConfig);

    HazelcastInstance node1 = Hazelcast.newHazelcastInstance(shConfig);
    populateCache(node1, "test", 1000);

    System.out.println("population finished, time to start second node!");
    Thread.sleep(50000);

    //HazelcastInstance node2 = Hazelcast.newHazelcastInstance(shConfig);
    //populateCache(node, "test", 1000);

    //System.out.println("Second node started");
    //Thread.sleep(5000);
}
项目:fabric8-cxf-shiro    文件:HazelcastSessionDao.java   
public HazelcastSessionDao() {
  log.info("Initializating Hazelcast Shiro session persistence..");

  // configure Hazelcast instance
  hcInstanceName = UUID.randomUUID().toString();
  Config cfg = new Config();
  cfg.setInstanceName(hcInstanceName);
  // group configuration
  cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));

  // network configuration initialization
  NetworkConfig netCfg = new NetworkConfig();
  netCfg.setPortAutoIncrement(true);
  netCfg.setPort(HC_PORT);
  // multicast
  MulticastConfig mcCfg = new MulticastConfig();
  mcCfg.setEnabled(true);
  mcCfg.setMulticastGroup(HC_MULTICAST_GROUP);
  mcCfg.setMulticastPort(HC_MULTICAST_PORT);
  // tcp
  TcpIpConfig tcpCfg = new TcpIpConfig();
  tcpCfg.setEnabled(false);
  // network join configuration
  JoinConfig joinCfg = new JoinConfig();
  joinCfg.setMulticastConfig(mcCfg);
  joinCfg.setTcpIpConfig(tcpCfg);
  netCfg.setJoin(joinCfg);
  // ssl
  netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

  // get map
  map = Hazelcast.newHazelcastInstance(cfg).getMap(HC_MAP);

  log.info("Hazelcast Shiro session persistence initialized.");
}
项目:apgas    文件:Transport.java   
/**
 * Initializes the {@link HazelcastInstance} for this global runtime instance.
 *
 * @param runtime
 *          the global runtime instance
 * @param master
 *          member to connect to or null
 * @param localhost
 *          the preferred ip address of this host or null
 * @param compact
 *          reduce thread creation if set
 * @param kryo
 *          use kryo serialization if set
 */
protected Transport(GlobalRuntimeImpl runtime, String master,
    String localhost, boolean compact, boolean kryo) {
  this.runtime = runtime;
  // config
  final Config config = new Config();
  config.setProperty("hazelcast.logging.type", "none");
  config.setProperty("hazelcast.wait.seconds.before.join", "0");
  config.setProperty("hazelcast.socket.connect.timeout.seconds", "1");
  config.setProperty("hazelcast.connection.monitor.max.faults", "0");
  if (compact) {
    config.setProperty("hazelcast.operation.thread.count", "2");
    config.setProperty("hazelcast.operation.generic.thread.count", "2");
    config.setProperty("hazelcast.io.thread.count", "2");
    config.setProperty("hazelcast.event.thread.count", "2");
    config.addExecutorConfig(
        new ExecutorConfig(ExecutionService.ASYNC_EXECUTOR, 2));
    config.addExecutorConfig(
        new ExecutorConfig(ExecutionService.SYSTEM_EXECUTOR, 2));
    config.addExecutorConfig(
        new ExecutorConfig(ExecutionService.SCHEDULED_EXECUTOR, 2));
  }

  // kryo
  if (kryo) {
    config.getSerializationConfig().addSerializerConfig(
        new SerializerConfig().setTypeClass(SerializableRunnable.class)
            .setImplementation(new KryoSerializer()));
  }

  config.addMapConfig(
      new MapConfig(APGAS_FINISH).setInMemoryFormat(InMemoryFormat.OBJECT));

  // join config
  final JoinConfig join = config.getNetworkConfig().getJoin();
  join.getMulticastConfig().setEnabled(false);
  join.getTcpIpConfig().setEnabled(true);
  if (localhost != null) {
    System.setProperty("hazelcast.local.localAddress", localhost);
  }
  if (master != null) {
    join.getTcpIpConfig().addMember(master);
  }
  config.setInstanceName(APGAS);

  hazelcast = Hazelcast.newHazelcastInstance(config);
  me = hazelcast.getCluster().getLocalMember();

  allMembers = hazelcast.getList(APGAS_PLACES);
  allMembers.add(me);
  int id = 0;
  for (final Member member : allMembers) {
    if (member.getUuid().equals(me.getUuid())) {
      break;
    }
    ++id;
  }
  here = id;

  executor = hazelcast.getExecutorService(APGAS_EXECUTOR);
}
项目:docker-hazelcast-mapstore-cassandra    文件:InstanceStart.java   
public static void main(String[] args) throws InterruptedException {
  final Config cfg = new Config();
  cfg.setInstanceName(UUID.randomUUID().toString());

  final Properties props = new Properties();
  props.put("hazelcast.rest.enabled", false);
  props.put("hazelcast.logging.type", "slf4j");
  props.put("hazelcast.connect.all.wait.seconds", 45);
  props.put("hazelcast.operation.call.timeout.millis", 30000);

  // group configuration
  cfg.setGroupConfig(new GroupConfig(args[0],
      args[1]));
  // network configuration initialization
  final NetworkConfig netCfg = new NetworkConfig();
  netCfg.setPortAutoIncrement(true);
  netCfg.setPort(5701);
  // multicast
  final MulticastConfig mcCfg = new MulticastConfig();
  mcCfg.setEnabled(false);
  // tcp
  final TcpIpConfig tcpCfg = new TcpIpConfig();
  tcpCfg.addMember("127.0.0.1");
  tcpCfg.setEnabled(true);
  // network join configuration
  final JoinConfig joinCfg = new JoinConfig();
  joinCfg.setMulticastConfig(mcCfg);
  joinCfg.setTcpIpConfig(tcpCfg);
  netCfg.setJoin(joinCfg);
  // ssl
  netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

  // creating cassandra client
  final CassandraClient dao = new CassandraClient();
  dao.initialize(args[2]);

  final HazelcastMapStore mapStore = new HazelcastMapStore(User.class);
  mapStore.setDao(dao);


  // Adding mapstore
  final MapConfig mapCfg = cfg.getMapConfig("cassandra-map-store");

  final MapStoreConfig mapStoreCfg = new MapStoreConfig();
  mapStoreCfg.setImplementation(mapStore);
  mapStoreCfg.setWriteDelaySeconds(1);
  // to load all map at same time
  mapStoreCfg.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
  mapCfg.setMapStoreConfig(mapStoreCfg);
  cfg.addMapConfig(mapCfg);


  HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);

  // TERM signal processing
  Runtime.getRuntime().addShutdownHook(new Thread(() -> {
    Hazelcast.shutdownAll();
  }));
}
项目:hazelcast-mapstore-postgres-cassandra    文件:MyHazelcastInstance.java   
public Config getConfig() {

    final Config cfg = new Config();
    cfg.setInstanceName(instanceName);

    final Properties props = new Properties();
    props.put("hazelcast.rest.enabled", false);
    props.put("hazelcast.logging.type", "slf4j");
    props.put("hazelcast.connect.all.wait.seconds", 45);
    props.put("hazelcast.operation.call.timeout.millis", 30000);

    // group configuration
    cfg.setGroupConfig(new GroupConfig(Constants.HC_GROUP_NAME,
        Constants.HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(true);
    netCfg.setPort(Constants.HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    tcpCfg.addMember("127.0.0.1");
    tcpCfg.setEnabled(true);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));

    // Adding mapstore
    final MapConfig mapCfg = cfg.getMapConfig(storeType);

    final MapStoreConfig mapStoreCfg = new MapStoreConfig();
    mapStoreCfg.setImplementation(store);
    mapStoreCfg.setWriteDelaySeconds(1);
    // to load all map at same time
    mapStoreCfg.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    mapCfg.setMapStoreConfig(mapStoreCfg);
    cfg.addMapConfig(mapCfg);
    return cfg;
  }
项目:cattle    文件:HazelcastFactory.java   
public HazelcastInstance newInstance() {
    String name = NAME.get();
    String password = PASS.get();

    if (StringUtils.isBlank(name)) {
        name = hazelcastDao.getGroupName();
    }

    if (StringUtils.isBlank(password)) {
        password = hazelcastDao.getGroupPassword();
    }

    Config config = new Config();
    if (JMX.get()) {
        config.setProperty("hazelcast.jmx", "true");
    }

    config.setProperty("hazelcast.logging.type", LOGGING.get());
    config.setProperty("hazelcast.discovery.enabled", "true");


    GroupConfig groupConfig = new GroupConfig();
    groupConfig.setName(name);
    groupConfig.setPassword(password);
    config.setGroupConfig(groupConfig);

    DiscoveryStrategyConfig dsc = new DiscoveryStrategyConfig(dbDiscoveryFactory);

    DiscoveryConfig dc = new DiscoveryConfig();
    dc.setDiscoveryStrategyConfigs(Arrays.asList(dsc));

    JoinConfig joinConfig = new JoinConfig();
    joinConfig.setDiscoveryConfig(dc);
    joinConfig.getTcpIpConfig().setEnabled(false);
    joinConfig.getMulticastConfig().setEnabled(false);
    joinConfig.getAwsConfig().setEnabled(false);

    NetworkConfig nc = new NetworkConfig();
    nc.setPort(DBDiscovery.DEFAULT_PORT.get());
    nc.setJoin(joinConfig);
    nc.setPublicAddress(dbDiscovery.getLocalConfig().getAdvertiseAddress());

    config.setNetworkConfig(nc);

    HazelcastInstance hi = Hazelcast.newHazelcastInstance(config);
    while (!hi.getPartitionService().isClusterSafe()) {
        log.info("Waiting for cluster to be in a steady state");
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            throw new IllegalStateException("Waiting for cluster to be in a steady state", e);
        }
    }

    return hi;
}
项目:lumongo    文件:HazelcastManager.java   
public void init(Set<HazelcastNode> nodes, String hazelcastName) throws Exception {

        // force Hazelcast to use log4j

        int hazelcastPort = localNodeConfig.getHazelcastPort();

        Config cfg = new Config();
        cfg.setProperty(GroupProperty.LOGGING_TYPE.getName(), "log4j");
        // disable Hazelcast shutdown hook to allow LuMongo to handle
        cfg.setProperty(GroupProperty.SHUTDOWNHOOK_ENABLED.getName(), "false");
        cfg.setProperty(GroupProperty.REST_ENABLED.getName(), "false");

        cfg.getGroupConfig().setName(hazelcastName);
        cfg.getGroupConfig().setPassword(hazelcastName);
        cfg.getNetworkConfig().setPortAutoIncrement(false);
        cfg.getNetworkConfig().setPort(hazelcastPort);
        cfg.setInstanceName("" + hazelcastPort);

        cfg.getManagementCenterConfig().setEnabled(false);

        NetworkConfig network = cfg.getNetworkConfig();
        JoinConfig joinConfig = network.getJoin();

        joinConfig.getMulticastConfig().setEnabled(false);
        joinConfig.getTcpIpConfig().setEnabled(true);
        for (HazelcastNode node : nodes) {
            joinConfig.getTcpIpConfig().addMember(node.getAddress() + ":" + node.getHazelcastPort());
        }

        hazelcastInstance = Hazelcast.newHazelcastInstance(cfg);
        self = hazelcastInstance.getCluster().getLocalMember();

        hazelcastInstance.getCluster().addMembershipListener(this);
        hazelcastInstance.getLifecycleService().addLifecycleListener(this);

        log.info("Initialized hazelcast");
        Set<Member> members = hazelcastInstance.getCluster().getMembers();

        Member firstMember = members.iterator().next();

        if (firstMember.equals(self)) {
            log.info("Member is owner of cluster");
            indexManager.loadIndexes();
        }

        log.info("Current cluster members: <" + members + ">");
        indexManager.openConnections(members);

        initLock.writeLock().unlock();

    }
项目:gw2live    文件:HazelcastCache.java   
private HazelcastCache() {
    final AppConfig config = AppConfig.getInstance();
    final Map<String, MapConfig> mapconfigs = new HashMap<>();
    GroupConfig groupconfig = new GroupConfig();
    groupconfig.setName(config.getString("cluster.name", "gw2live"));
    groupconfig.setPassword(config.getString("cluster.password", "gw2live"));
    final MapConfig mapconfig = new MapConfig();
    mapconfig.getMaxSizeConfig().setMaxSizePolicy(MaxSizePolicy.PER_PARTITION);
    mapconfig.getMaxSizeConfig().setSize(0);
    mapconfig.setEvictionPolicy(MapConfig.DEFAULT_EVICTION_POLICY);
    mapconfig.setBackupCount(1);
    mapconfigs.put("*-cache", mapconfig);
    final NetworkConfig nwconfig = new NetworkConfig();
    if(config.containsKey("cluster.interface")) {
        final InterfacesConfig interfaces = new InterfacesConfig();
        interfaces.addInterface(config.getString("cluster.interface"));
        interfaces.setEnabled(true);
        nwconfig.setInterfaces(interfaces);
    }
    nwconfig.setPort(config.getInteger("cluster.port", 5801));
    nwconfig.setPortAutoIncrement(true);
    final MulticastConfig mcconfig = new MulticastConfig();
    mcconfig.setEnabled(true);
    mcconfig.setMulticastGroup(config.getString("cluster.multicast.group", "224.2.2.3"));
    mcconfig.setMulticastPort(config.getInteger("cluster.multicast.port", 58011));
    mcconfig.setMulticastTimeToLive(MulticastConfig.DEFAULT_MULTICAST_TTL);
    mcconfig.setMulticastTimeoutSeconds(MulticastConfig.DEFAULT_MULTICAST_TIMEOUT_SECONDS);
    final JoinConfig join = new JoinConfig();
    join.setMulticastConfig(mcconfig);
    nwconfig.setJoin(join);
    final ExecutorConfig execconfig = new ExecutorConfig();
    execconfig.setName("default");
    execconfig.setPoolSize(4);
    execconfig.setQueueCapacity(100);
    final Map<String, ExecutorConfig> execmap = new HashMap<>();
    execmap.put("default", execconfig);
    final Config hconfig = new Config();
    hconfig.setInstanceName("gw2live");
    hconfig.setGroupConfig(groupconfig);
    hconfig.setMapConfigs(mapconfigs);
    hconfig.setNetworkConfig(nwconfig);
    hconfig.setExecutorConfigs(execmap);
    hconfig.setProperty("hazelcast.shutdownhook.enabled", "false");
    hconfig.setProperty("hazelcast.wait.seconds.before.join", "0");
    hconfig.setProperty("hazelcast.rest.enabled", "false");
    hconfig.setProperty("hazelcast.memcache.enabled", "false");
    hconfig.setProperty("hazelcast.mancenter.enabled", "false");
    hconfig.setProperty("hazelcast.logging.type", "none");
    cache = Hazelcast.newHazelcastInstance(hconfig);

    LOG.debug("Hazelcast initialized");
}
项目:hazelcast-discovery-spi-demonstration    文件:DiscoveryTest.java   
@Test
public void test() {
    Config config = new XmlConfigBuilder().build();
    config.setProperty("hazelcast.discovery.enabled", "true");

    JoinConfig joinConfig = config.getNetworkConfig().getJoin();

    joinConfig.getMulticastConfig().setEnabled(false);
    joinConfig.getTcpIpConfig().setEnabled(false);

    DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();

    DiscoveryStrategyFactory discoveryStrategyFactory = new SomeRestServiceDiscoveryStrategyFactory();
    DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(discoveryStrategyFactory);

    discoveryConfig.addDiscoveryStrategyConfig(discoveryStrategyConfig);

    config.getNetworkConfig().setPort(55667);
    HazelcastInstance hazelcastInstance1 = Hazelcast.newHazelcastInstance(config);

    config.getNetworkConfig().setPort(1122);
    HazelcastInstance hazelcastInstance2 = Hazelcast.newHazelcastInstance(config);

    assertEquals(2, hazelcastInstance1.getCluster().getMembers().size());
    assertEquals(2, hazelcastInstance2.getCluster().getMembers().size());

    Hazelcast.shutdownAll();
}