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;
  }
Ejemplo n.º 2
0
  private void initNetworkConfig(
      NetworkConfig networkConfig, int basePort, int portSeed, boolean multicast, int nodeCount) {

    networkConfig.setPortAutoIncrement(false);
    networkConfig.setPort(basePort + portSeed);

    JoinConfig join = networkConfig.getJoin();

    MulticastConfig multicastConfig = join.getMulticastConfig();
    multicastConfig.setEnabled(multicast);
    multicastConfig.setMulticastTimeoutSeconds(5);

    TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
    tcpIpConfig.setEnabled(!multicast);
    tcpIpConfig.setConnectionTimeoutSeconds(5);

    List<String> members = new ArrayList<String>(nodeCount);
    for (int i = 0; i < nodeCount; i++) {
      members.add("127.0.0.1:" + (basePort + i));
    }
    Collections.sort(members);
    tcpIpConfig.setMembers(members);
  }