示例#1
0
  void applyStateLocally(Map<InetAddress, EndpointState> epStateMap) {
    for (Entry<InetAddress, EndpointState> entry : epStateMap.entrySet()) {
      InetAddress ep = entry.getKey();
      if (ep.equals(localEndpoint_)) continue;

      EndpointState localEpStatePtr = endpointStateMap_.get(ep);
      EndpointState remoteState = entry.getValue();
      /*
          If state does not exist just add it. If it does then add it only if the version
          of the remote copy is greater than the local copy.
      */
      if (localEpStatePtr != null) {
        int localGeneration = localEpStatePtr.getHeartBeatState().getGeneration();
        int remoteGeneration = remoteState.getHeartBeatState().getGeneration();

        if (remoteGeneration > localGeneration) {
          handleGenerationChange(ep, remoteState);
        } else if (remoteGeneration == localGeneration) {
          /* manage the membership state */
          int localMaxVersion = getMaxEndpointStateVersion(localEpStatePtr);
          int remoteMaxVersion = getMaxEndpointStateVersion(remoteState);
          if (remoteMaxVersion > localMaxVersion) {
            markAlive(ep, localEpStatePtr);
            applyHeartBeatStateLocally(ep, localEpStatePtr, remoteState);
            /* apply ApplicationState */
            applyApplicationStateLocally(ep, localEpStatePtr, remoteState);
          }
        } else {
          if (logger_.isTraceEnabled())
            logger_.trace(
                "Ignoring remote generation " + remoteGeneration + " < " + localGeneration);
        }
      } else {
        handleNewJoin(ep, remoteState);
      }
    }
  }