Exemple #1
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.");
   }
 }
Exemple #2
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);
 }