Esempio n. 1
0
  private void removeMember(MemberImpl deadMember) {
    logger.info("Removing " + deadMember);
    lock.lock();
    try {
      Map<Address, MemberImpl> members = membersMapRef.get();
      final Address deadAddress = deadMember.getAddress();

      if (members.containsKey(deadAddress)) {
        // !!! ORDERED !!!
        Map<Address, MemberImpl> newMembers = new LinkedHashMap<Address, MemberImpl>(members);
        newMembers.remove(deadAddress);
        clusterHeartbeatManager.removeMember(deadMember);
        setMembersRef(newMembers);

        if (node.isMaster()) {
          if (logger.isFinestEnabled()) {
            logger.finest(deadMember + " is dead, sending remove to all other members...");
          }
          invokeMemberRemoveOperation(deadAddress);
        }

        final ClusterState clusterState = clusterStateManager.getState();
        if (clusterState == ClusterState.FROZEN || clusterState == ClusterState.PASSIVE) {
          if (logger.isFinestEnabled()) {
            logger.finest(
                deadMember
                    + " is dead, added to members left while cluster is "
                    + clusterState
                    + " state");
          }
          Map<Address, MemberImpl> membersRemovedInNotActiveState =
              new LinkedHashMap<Address, MemberImpl>(membersRemovedInNotActiveStateRef.get());
          membersRemovedInNotActiveState.put(deadAddress, deadMember);
          membersRemovedInNotActiveStateRef.set(
              Collections.unmodifiableMap(membersRemovedInNotActiveState));
          final InternalPartitionServiceImpl partitionService = node.partitionService;
          partitionService.cancelReplicaSyncRequestsTo(deadAddress);
        } else {
          onMemberRemove(deadMember, newMembers);
        }

        // async events
        sendMembershipEventNotifications(
            deadMember, unmodifiableSet(new LinkedHashSet<Member>(newMembers.values())), false);
      }
    } finally {
      lock.unlock();
    }
  }
Esempio 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);
     }
     boolean known = false;
     if (listener instanceof DistributedObjectListener) {
       final ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
       proxyService.addProxyListener((DistributedObjectListener) listener);
       known = true;
     }
     if (listener instanceof MembershipListener) {
       clusterService.addMembershipListener((MembershipListener) listener);
       known = true;
     }
     if (listener instanceof MigrationListener) {
       partitionService.addMigrationListener((MigrationListener) listener);
       known = true;
     }
     if (listener instanceof PartitionLostListener) {
       partitionService.addPartitionLostListener((PartitionLostListener) listener);
       known = true;
     }
     if (listener instanceof LifecycleListener) {
       hazelcastInstance.lifecycleService.addLifecycleListener((LifecycleListener) listener);
       known = true;
     }
     if (listener instanceof ClientListener) {
       String serviceName = ClientEngineImpl.SERVICE_NAME;
       nodeEngine.getEventService().registerLocalListener(serviceName, serviceName, listener);
       known = true;
     }
     if (listener != null && !known) {
       final String error = "Unknown listener type: " + listener.getClass();
       Throwable t = new IllegalArgumentException(error);
       logger.warning(error, t);
     }
   }
 }
Esempio n. 3
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;
  }