public static void assertClusterSize(int expectedSize, HazelcastInstance instance) {
   int clusterSize = instance.getCluster().getMembers().size();
   if (expectedSize != clusterSize) {
     ConnectionManager connectionManager = getNode(instance).getConnectionManager();
     int activeConnectionCount = connectionManager.getActiveConnectionCount();
     throw new AssertionError(
         String.format(
             "Cluster size is not correct. Expected: %d Actual: %d %s",
             expectedSize, clusterSize, "ActiveConnectionCount: " + activeConnectionCount));
   }
 }
예제 #2
0
 private void doShutdown(boolean force) {
   long start = Clock.currentTimeMillis();
   logger.finest("** we are being asked to shutdown when active = " + String.valueOf(active));
   if (!force && isActive()) {
     final int maxWaitSeconds = groupProperties.GRACEFUL_SHUTDOWN_MAX_WAIT.getInteger();
     if (!partitionService.prepareToSafeShutdown(maxWaitSeconds, TimeUnit.SECONDS)) {
       logger.warning(
           "Graceful shutdown could not be completed in " + maxWaitSeconds + " seconds!");
     }
   }
   if (isActive()) {
     if (!force) {
       clusterService.sendShutdownMessage();
     }
     // set the joined=false first so that
     // threads do not process unnecessary
     // events, such as remove address
     joined.set(false);
     setActive(false);
     setMasterAddress(null);
     try {
       Runtime.getRuntime().removeShutdownHook(shutdownHookThread);
     } catch (Throwable ignored) {
     }
     if (managementCenterService != null) {
       managementCenterService.shutdown();
     }
     logger.finest("Shutting down client command service");
     clientEngine.shutdown();
     logger.finest("Shutting down node engine");
     nodeEngine.shutdown();
     if (multicastService != null) {
       logger.finest("Shutting down multicast service");
       multicastService.stop();
     }
     logger.finest("Shutting down connection manager");
     connectionManager.shutdown();
     textCommandService.stop();
     masterAddress = null;
     if (securityContext != null) {
       securityContext.destroy();
     }
     initializer.destroy();
     serializationService.destroy();
     int numThreads = threadGroup.activeCount();
     Thread[] threads = new Thread[numThreads * 2];
     numThreads = threadGroup.enumerate(threads, false);
     for (int i = 0; i < numThreads; i++) {
       Thread thread = threads[i];
       if (thread.isAlive()) {
         logger.finest("Shutting down thread " + thread.getName());
         thread.interrupt();
       }
     }
     failedConnections.clear();
     systemLogService.shutdown();
     logger.info(
         "Hazelcast Shutdown is completed in " + (Clock.currentTimeMillis() - start) + " ms.");
   }
 }
  public boolean send(Response response, Address target) {
    checkNotNull(target, "Target is required!");

    if (thisAddress.equals(target)) {
      throw new IllegalArgumentException(
          "Target is this node! -> " + target + ", response: " + response);
    }

    byte[] bytes = serializationService.toBytes(response);
    Packet packet = new Packet(bytes, -1).setAllFlags(FLAG_OP | FLAG_RESPONSE);

    if (response.isUrgent()) {
      packet.setFlag(FLAG_URGENT);
    }

    ConnectionManager connectionManager = node.getConnectionManager();
    Connection connection = connectionManager.getOrConnect(target);
    return connectionManager.transmit(packet, connection);
  }
  @Override
  public boolean send(Operation op, Address target) {
    checkNotNull(target, "Target is required!");

    if (thisAddress.equals(target)) {
      throw new IllegalArgumentException("Target is this node! -> " + target + ", op: " + op);
    }

    byte[] bytes = serializationService.toBytes(op);
    int partitionId = op.getPartitionId();
    Packet packet = new Packet(bytes, partitionId).setFlag(FLAG_OP);

    if (op.isUrgent()) {
      packet.setFlag(FLAG_URGENT);
    }

    ConnectionManager connectionManager = node.getConnectionManager();
    Connection connection = connectionManager.getOrConnect(target);
    return connectionManager.transmit(packet, connection);
  }
예제 #5
0
  @Override
  public void run() {
    StringBuffer sb = new StringBuffer();

    while (node.isActive()) {
      sb.append("\n");
      sb.append("ConnectionManager metrics\n");
      connectionManager.dumpPerformanceMetrics(sb);
      sb.append("OperationService metrics\n");
      operationService.dumpPerformanceMetrics(sb);

      logger.info(sb.toString());

      sb.setLength(0);
      try {
        Thread.sleep(TimeUnit.SECONDS.toMillis(delaySeconds));
      } catch (InterruptedException e) {
        return;
      }
    }
  }
예제 #6
0
  void start() {
    nodeEngine.start();
    connectionManager.start();
    if (config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()) {
      final Thread multicastServiceThread =
          new Thread(
              hazelcastThreadGroup.getInternalThreadGroup(),
              multicastService,
              hazelcastThreadGroup.getThreadNamePrefix("MulticastThread"));
      multicastServiceThread.start();
    }
    if (groupProperties.getBoolean(GroupProperty.DISCOVERY_SPI_ENABLED)) {
      discoveryService.start();
    }

    if (groupProperties.getBoolean(GroupProperty.SHUTDOWNHOOK_ENABLED)) {
      logger.finest("Adding ShutdownHook");
      Runtime.getRuntime().addShutdownHook(shutdownHookThread);
    }
    state = NodeState.ACTIVE;

    join();
    int clusterSize = clusterService.getSize();
    if (config.getNetworkConfig().isPortAutoIncrement()
        && address.getPort() >= config.getNetworkConfig().getPort() + clusterSize) {
      StringBuilder sb = new StringBuilder("Config seed port is ");
      sb.append(config.getNetworkConfig().getPort());
      sb.append(" and cluster size is ");
      sb.append(clusterSize);
      sb.append(". Some of the ports seem occupied!");
      logger.warning(sb.toString());
    }
    try {
      managementCenterService = new ManagementCenterService(hazelcastInstance);
    } catch (Exception e) {
      logger.warning("ManagementCenterService could not be constructed!", e);
    }
    nodeExtension.afterStart(this);
    versionCheck.check(this, getBuildInfo().getVersion(), buildInfo.isEnterprise());
  }
예제 #7
0
 public void start() {
   logger.finest(
       "We are asked to start and completelyShutdown is " + String.valueOf(completelyShutdown));
   if (completelyShutdown) return;
   nodeEngine.start();
   connectionManager.start();
   if (config.getNetworkConfig().getJoin().getMulticastConfig().isEnabled()) {
     final Thread multicastServiceThread =
         new Thread(
             hazelcastInstance.threadGroup,
             multicastService,
             getThreadNamePrefix("MulticastThread"));
     multicastServiceThread.start();
   }
   setActive(true);
   if (!completelyShutdown) {
     logger.finest("Adding ShutdownHook");
     Runtime.getRuntime().addShutdownHook(shutdownHookThread);
   }
   logger.finest("finished starting threads, calling join");
   join();
   int clusterSize = clusterService.getSize();
   if (config.getNetworkConfig().isPortAutoIncrement()
       && address.getPort() >= config.getNetworkConfig().getPort() + clusterSize) {
     StringBuilder sb = new StringBuilder("Config seed port is ");
     sb.append(config.getNetworkConfig().getPort());
     sb.append(" and cluster size is ");
     sb.append(clusterSize);
     sb.append(". Some of the ports seem occupied!");
     logger.warning(sb.toString());
   }
   try {
     managementCenterService = new ManagementCenterService(hazelcastInstance);
   } catch (Exception e) {
     logger.warning("ManagementCenterService could not be constructed!", e);
   }
   initializer.afterInitialize(this);
 }
예제 #8
0
  public void shutdown(final boolean terminate) {
    long start = Clock.currentTimeMillis();
    if (logger.isFinestEnabled()) {
      logger.finest("We are being asked to shutdown when state = " + state);
    }

    if (!STATE.compareAndSet(this, NodeState.ACTIVE, NodeState.SHUTTING_DOWN)) {
      waitIfAlreadyShuttingDown();
      return;
    }

    if (!terminate) {
      final int maxWaitSeconds =
          groupProperties.getSeconds(GroupProperty.GRACEFUL_SHUTDOWN_MAX_WAIT);
      if (!partitionService.prepareToSafeShutdown(maxWaitSeconds, TimeUnit.SECONDS)) {
        logger.warning(
            "Graceful shutdown could not be completed in " + maxWaitSeconds + " seconds!");
      }
      clusterService.sendShutdownMessage();
    } else {
      logger.warning("Terminating forcefully...");
    }

    // set the joined=false first so that
    // threads do not process unnecessary
    // events, such as remove address
    joined.set(false);
    setMasterAddress(null);
    try {
      if (groupProperties.getBoolean(GroupProperty.SHUTDOWNHOOK_ENABLED)) {
        Runtime.getRuntime().removeShutdownHook(shutdownHookThread);
      }
      discoveryService.destroy();
      logger.info("Shutting down connection manager...");
      connectionManager.shutdown();
    } catch (Throwable ignored) {
    }
    versionCheck.shutdown();
    if (managementCenterService != null) {
      managementCenterService.shutdown();
    }

    textCommandService.stop();
    if (multicastService != null) {
      logger.info("Shutting down multicast service...");
      multicastService.stop();
    }
    logger.info("Shutting down connection manager...");
    connectionManager.shutdown();

    logger.info("Shutting down node engine...");
    nodeEngine.shutdown(terminate);

    if (securityContext != null) {
      securityContext.destroy();
    }
    nodeExtension.destroy();
    logger.finest("Destroying serialization service...");
    serializationService.destroy();

    hazelcastThreadGroup.destroy();
    logger.info(
        "Hazelcast Shutdown is completed in " + (Clock.currentTimeMillis() - start) + " ms.");
    state = NodeState.SHUT_DOWN;
  }