Exemplo n.º 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.");
   }
 }
Exemplo n.º 2
0
 private void initializeListeners(Config config) {
   for (final ListenerConfig listenerCfg : config.getListenerConfigs()) {
     Object listener = listenerCfg.getImplementation();
     if (listener == null) {
       try {
         listener = ClassLoaderUtil.newInstance(configClassLoader, listenerCfg.getClassName());
       } catch (Exception e) {
         logger.severe(e);
       }
     }
     if (listener instanceof HazelcastInstanceAware) {
       ((HazelcastInstanceAware) listener).setHazelcastInstance(hazelcastInstance);
     }
     if (listener instanceof DistributedObjectListener) {
       final ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
       proxyService.addProxyListener((DistributedObjectListener) listener);
     } else if (listener instanceof MembershipListener) {
       clusterService.addMembershipListener((MembershipListener) listener);
     } else if (listener instanceof MigrationListener) {
       partitionService.addMigrationListener((MigrationListener) listener);
     } else if (listener instanceof LifecycleListener) {
       hazelcastInstance.lifecycleService.addLifecycleListener((LifecycleListener) listener);
     } else if (listener != null) {
       final String error = "Unknown listener type: " + listener.getClass();
       Throwable t = new IllegalArgumentException(error);
       logger.warning(error, t);
     }
   }
 }
Exemplo n.º 3
0
  @Override
  public void run() throws Exception {
    if (!valid) {
      return;
    }
    final NodeEngine nodeEngine = getNodeEngine();
    final PartitionServiceImpl partitionService =
        (PartitionServiceImpl) nodeEngine.getPartitionService();
    partitionService.updatePartitionReplicaVersions(
        getPartitionId(), replicaVersions, getReplicaIndex());

    if (backupOp != null) {
      backupOp.setNodeEngine(nodeEngine);
      backupOp.setResponseHandler(ResponseHandlerFactory.createEmptyResponseHandler());
      backupOp.setCallerUuid(getCallerUuid());
      OperationAccessor.setCallerAddress(backupOp, getCallerAddress());
      OperationAccessor.setInvocationTime(backupOp, Clock.currentTimeMillis());

      final OperationService operationService = nodeEngine.getOperationService();
      operationService.runOperation(backupOp);
    }
  }