private Config hazelcast() {
    Config conf = new Config();
    conf.getNetworkConfig().setPort(hazelCastPort);
    conf.getNetworkConfig().setPortAutoIncrement(false);

    conf.setProperty("hazelcast.initial.min.cluster.size", "1");
    conf.setProperty("hazelcast.shutdownhook.enabled", "false");

    JoinConfig join = conf.getNetworkConfig().getJoin();

    boolean isAws = System.getProperty("hazelcast.aws", "false").equals("true");
    log.info("Setting up Joiner with this being " + (isAws ? "AWS" : "Multicast"));

    join.getAwsConfig().setEnabled(isAws);
    if (isAws) {
      join.getAwsConfig().setAccessKey(System.getProperty("hazelcast.access-key"));
      join.getAwsConfig().setSecretKey(System.getProperty("hazelcast.access-secret"));
    }
    join.getMulticastConfig().setEnabled(!isAws);

    ListConfig jobConfig = new ListConfig();
    jobConfig.setName(JOBS);

    conf.addListConfig(jobConfig);

    ListConfig replicateConfig = new ListConfig();
    replicateConfig.setName(REPLICATE_WEIGHTS);

    conf.addListConfig(replicateConfig);

    ListConfig topicsConfig = new ListConfig();
    topicsConfig.setName(TOPICS);

    conf.addListConfig(topicsConfig);

    ListConfig updatesConfig = new ListConfig();
    updatesConfig.setName(UPDATES);

    conf.addListConfig(updatesConfig);

    ListConfig availableWorkersConfig = new ListConfig();
    availableWorkersConfig.setName(AVAILABLE_WORKERS);
    conf.addListConfig(availableWorkersConfig);

    MapConfig heartbeatConfig = new MapConfig();
    heartbeatConfig.setName(HEART_BEAT);
    conf.addMapConfig(heartbeatConfig);

    MapConfig workerEnabledConifg = new MapConfig();
    workerEnabledConifg.setName(WORKER_ENABLED);
    conf.addMapConfig(workerEnabledConifg);

    return conf;
  }
예제 #2
0
 public Node(HazelcastInstanceImpl hazelcastInstance, Config config, NodeContext nodeContext) {
   this.hazelcastInstance = hazelcastInstance;
   this.threadGroup = hazelcastInstance.threadGroup;
   this.config = config;
   configClassLoader = config.getClassLoader();
   this.groupProperties = new GroupProperties(config);
   SerializationService ss;
   try {
     ss =
         new SerializationServiceBuilder()
             .setClassLoader(configClassLoader)
             .setConfig(config.getSerializationConfig())
             .setManagedContext(hazelcastInstance.managedContext)
             .setHazelcastInstance(hazelcastInstance)
             .build();
   } catch (Exception e) {
     throw ExceptionUtil.rethrow(e);
   }
   serializationService = (SerializationServiceImpl) ss;
   systemLogService = new SystemLogService(groupProperties.SYSTEM_LOG_ENABLED.getBoolean());
   final AddressPicker addressPicker = nodeContext.createAddressPicker(this);
   try {
     addressPicker.pickAddress();
   } catch (Throwable e) {
     throw ExceptionUtil.rethrow(e);
   }
   final ServerSocketChannel serverSocketChannel = addressPicker.getServerSocketChannel();
   address = addressPicker.getPublicAddress();
   localMember = new MemberImpl(address, true, UuidUtil.createMemberUuid(address));
   String loggingType = groupProperties.LOGGING_TYPE.getString();
   loggingService =
       new LoggingServiceImpl(
           systemLogService, config.getGroupConfig().getName(), loggingType, localMember);
   logger = loggingService.getLogger(Node.class.getName());
   initializer = NodeInitializerFactory.create(configClassLoader);
   try {
     initializer.beforeInitialize(this);
   } catch (Throwable e) {
     try {
       serverSocketChannel.close();
     } catch (Throwable ignored) {
     }
     throw ExceptionUtil.rethrow(e);
   }
   securityContext =
       config.getSecurityConfig().isEnabled() ? initializer.getSecurityContext() : null;
   nodeEngine = new NodeEngineImpl(this);
   clientEngine = new ClientEngineImpl(this);
   connectionManager = nodeContext.createConnectionManager(this, serverSocketChannel);
   partitionService = new PartitionServiceImpl(this);
   clusterService = new ClusterServiceImpl(this);
   textCommandService = new TextCommandServiceImpl(this);
   initializer.printNodeInfo(this);
   buildNumber = initializer.getBuildNumber();
   VersionCheck.check(this, initializer.getBuild(), initializer.getVersion());
   JoinConfig join = config.getNetworkConfig().getJoin();
   MulticastService mcService = null;
   try {
     if (join.getMulticastConfig().isEnabled()) {
       MulticastConfig multicastConfig = join.getMulticastConfig();
       MulticastSocket multicastSocket = new MulticastSocket(null);
       multicastSocket.setReuseAddress(true);
       // bind to receive interface
       multicastSocket.bind(new InetSocketAddress(multicastConfig.getMulticastPort()));
       multicastSocket.setTimeToLive(multicastConfig.getMulticastTimeToLive());
       try {
         // set the send interface
         final Address bindAddress = addressPicker.getBindAddress();
         // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4417033
         // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6402758
         if (!bindAddress.getInetAddress().isLoopbackAddress()) {
           multicastSocket.setInterface(bindAddress.getInetAddress());
         }
       } catch (Exception e) {
         logger.warning(e);
       }
       multicastSocket.setReceiveBufferSize(64 * 1024);
       multicastSocket.setSendBufferSize(64 * 1024);
       String multicastGroup = System.getProperty("hazelcast.multicast.group");
       if (multicastGroup == null) {
         multicastGroup = multicastConfig.getMulticastGroup();
       }
       multicastConfig.setMulticastGroup(multicastGroup);
       multicastSocket.joinGroup(InetAddress.getByName(multicastGroup));
       multicastSocket.setSoTimeout(1000);
       mcService = new MulticastService(this, multicastSocket);
       mcService.addMulticastListener(new NodeMulticastListener(this));
     }
   } catch (Exception e) {
     logger.severe(e);
   }
   this.multicastService = mcService;
   initializeListeners(config);
   joiner = nodeContext.createJoiner(this);
 }