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

项目: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);
}
项目:runrightfast-vertx    文件:TypesafeHazelcastConfig.java   
private MulticastConfig multicastConfig(final com.typesafe.config.Config config) {
    return ConfigUtils.getConfig(config, "join-config", "multicast")
            .map(multicastConfig -> {
                final MulticastConfig multicast = new MulticastConfig();
                multicast.setEnabled(true);
                ConfigUtils.getString(multicastConfig, "multicast-group").ifPresent(multicast::setMulticastGroup);
                ConfigUtils.getInt(multicastConfig, "multicast-port").ifPresent(multicast::setMulticastPort);
                ConfigUtils.getInt(multicastConfig, "multicast-time-to-live").ifPresent(multicast::setMulticastTimeToLive);
                ConfigUtils.getInt(multicastConfig, "multicast-timeout-seconds").ifPresent(multicast::setMulticastTimeoutSeconds);
                ConfigUtils.getStringList(multicastConfig, "trusted-interfaces").ifPresent(trustedInterfaces -> {
                    trustedInterfaces.stream().forEach(multicast::addTrustedInterface);
                });
                return multicast;
            })
            .orElseGet(() -> new MulticastConfig().setEnabled(false));
}
项目:dropwizard-hazelcast-session    文件:HazelcastSessionsStoreFactory.java   
@Override
public SessionsStore provide() {
    LOGGER.info("Starting Hazelcast instance");
    HazelcastConfig hazelcastConfig = hazelcastSessionConfig.getHazelcastConfig();
    Config hcHazelcastConfig = new Config();
    for (Map.Entry<String, String> hazelcastConfigProperty : hazelcastConfig.getProperties().entrySet()) {
        hcHazelcastConfig.setProperty(hazelcastConfigProperty.getKey(), hazelcastConfigProperty.getValue());
    }
    MulticastConfig multicastConfig = hcHazelcastConfig.getNetworkConfig().getJoin().getMulticastConfig();
    String multicastGroup = hazelcastConfig.getMulticastGroup();
    if (isNotBlank(multicastGroup)) {
        multicastConfig.setMulticastGroup(multicastGroup);
    }
    Integer multicastPort = hazelcastConfig.getMulticastPort();
    if (multicastPort != null) {
        multicastConfig.setMulticastPort(multicastPort);
    }
    HazelcastInstance hazelcastInstance = newHazelcastInstance(hcHazelcastConfig);
    return new HazelcastSessionsStore(hazelcastInstance);
}
项目: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;

}
项目: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.");
}
项目: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"));
}
项目: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.");
}
项目: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.");
}
项目:lb-hazelcast    文件:JsonConfigTest.java   
@Test
public void testBuilder() {
    final Config config = new JsonConfigBuilder(getResource()).build();
    assertNotNull(config);

    // Group Config
    assertNotNull(config.getGroupConfig());
    assertEquals("group-name", config.getGroupConfig().getName());
    assertEquals("group-password", config.getGroupConfig().getPassword());

    // Network Config
    final NetworkConfig netCfg = config.getNetworkConfig();

    assertEquals(true, netCfg.isReuseAddress());
    assertEquals(5900, netCfg.getPort());
    assertEquals(false, netCfg.isPortAutoIncrement());
    assertEquals(100, netCfg.getPortCount());
    assertTrue(netCfg.getOutboundPortDefinitions().contains("10100"));
    assertTrue(netCfg.getOutboundPortDefinitions().contains("9000-10000"));
    assertFalse(netCfg.getOutboundPortDefinitions().contains("1"));
    assertEquals("127.0.0.1", netCfg.getPublicAddress());

    // Multicast Config
    final MulticastConfig mcastCfg = netCfg.getJoin().getMulticastConfig();
    assertEquals(false, mcastCfg.isEnabled());
    assertEquals(false, mcastCfg.isLoopbackModeEnabled());
    assertTrue(mcastCfg.getTrustedInterfaces().contains("eth0"));
    assertTrue(mcastCfg.getTrustedInterfaces().contains("eth1"));
    assertFalse(mcastCfg.getTrustedInterfaces().contains("lo0"));

    // TcpIp Config
    final TcpIpConfig tcpCfg = netCfg.getJoin().getTcpIpConfig();
    assertEquals(false, tcpCfg.isEnabled());
    assertEquals(10, tcpCfg.getConnectionTimeoutSeconds());
}
项目:lb-hazelcast    文件:YamlConfigTest.java   
@Test
public void testBuilder() {
    final Config config = new YamlConfigBuilder(getResource()).build();
    assertNotNull(config);

    // Group Config
    assertNotNull(config.getGroupConfig());
    assertEquals("group-name", config.getGroupConfig().getName());
    assertEquals("group-password", config.getGroupConfig().getPassword());

    // Network Config
    final NetworkConfig netCfg = config.getNetworkConfig();

    assertEquals(true, netCfg.isReuseAddress());
    assertEquals(5900, netCfg.getPort());
    assertEquals(false, netCfg.isPortAutoIncrement());
    assertEquals(100, netCfg.getPortCount());
    assertFalse(netCfg.getOutboundPortDefinitions().isEmpty());
    assertEquals(2, netCfg.getOutboundPortDefinitions().size());
    assertTrue(netCfg.getOutboundPortDefinitions().contains("10100"));
    assertTrue(netCfg.getOutboundPortDefinitions().contains("9000-10000"));
    assertEquals("127.0.0.1", netCfg.getPublicAddress());

    // Multicast Config
    final MulticastConfig mcastCfg = netCfg.getJoin().getMulticastConfig();
    assertEquals(false, mcastCfg.isEnabled());
    assertEquals(false, mcastCfg.isLoopbackModeEnabled());
    assertFalse(mcastCfg.getTrustedInterfaces().isEmpty());
    assertEquals(2, mcastCfg.getTrustedInterfaces().size());
    assertTrue(mcastCfg.getTrustedInterfaces().contains("eth0"));
    assertTrue(mcastCfg.getTrustedInterfaces().contains("eth1"));

    // TcpIp Config
    final TcpIpConfig tcpCfg = netCfg.getJoin().getTcpIpConfig();
    assertEquals(false, tcpCfg.isEnabled());
    assertEquals(10, tcpCfg.getConnectionTimeoutSeconds());
    assertFalse(tcpCfg.getMembers().isEmpty());
    assertEquals(3, tcpCfg.getMembers().size());
    assertTrue(tcpCfg.getMembers().contains("192.168.0.1"));
    assertTrue(tcpCfg.getMembers().contains("192.168.0.2"));
    assertTrue(tcpCfg.getMembers().contains("192.168.0.3"));
    assertEquals("127.0.0.1", tcpCfg.getRequiredMember());

    // Interfaces Config
    final InterfacesConfig ifacesCfg = netCfg.getInterfaces();
    assertEquals(false, ifacesCfg.isEnabled());
    assertEquals(3, ifacesCfg.getInterfaces().size());
    assertTrue(ifacesCfg.getInterfaces().contains("10.3.16.*"));
    assertTrue(ifacesCfg.getInterfaces().contains("10.3.10.4-18"));
    assertTrue(ifacesCfg.getInterfaces().contains("192.168.1.3"));
}
项目: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;
  }
项目: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");
}