Ejemplo n.º 1
0
 Set<ClientEndpoint> getEndpoints(String uuid) {
   Set<ClientEndpoint> endpointSet = new HashSet<ClientEndpoint>();
   for (ClientEndpoint endpoint : endpoints.values()) {
     if (uuid.equals(endpoint.getUuid())) {
       endpointSet.add(endpoint);
     }
   }
   return endpointSet;
 }
Ejemplo n.º 2
0
 public void invalidateScheduledActionsFor(Address endpoint, Set<Integer> threadIds) {
   if (!node.joined() || !node.isActive()) return;
   if (setScheduledActions.size() > 0) {
     Iterator<ScheduledAction> it = setScheduledActions.iterator();
     while (it.hasNext()) {
       ScheduledAction sa = it.next();
       Request request = sa.getRequest();
       if (endpoint.equals(request.caller) && threadIds.contains(request.lockThreadId)) {
         sa.setValid(false);
         it.remove();
       }
     }
   }
 }
Ejemplo n.º 3
0
 public void checkScheduledActions() {
   if (!node.joined() || !node.isActive()) return;
   if (setScheduledActions.size() > 0) {
     Iterator<ScheduledAction> it = setScheduledActions.iterator();
     while (it.hasNext()) {
       ScheduledAction sa = it.next();
       if (sa.expired() && sa.isValid()) {
         sa.onExpire();
         it.remove();
       } else if (!sa.isValid()) {
         it.remove();
       }
     }
   }
 }
Ejemplo n.º 4
0
 void startJoin() {
   logger.log(Level.FINEST, "Starting Join.");
   joinInProgress = true;
   final MembersUpdateCall membersUpdate =
       new MembersUpdateCall(lsMembers, node.getClusterImpl().getClusterTime());
   if (setJoins != null && setJoins.size() > 0) {
     for (MemberInfo memberJoined : setJoins) {
       membersUpdate.addMemberInfo(memberJoined);
     }
   }
   membersUpdate.setNode(node);
   membersUpdate.call();
   node.executorManager.executeNow(new JoinRunnable(membersUpdate));
 }
Ejemplo n.º 5
0
 void doRemoveAddress(Address deadAddress, boolean destroyConnection) {
   checkServiceThread();
   logger.log(Level.INFO, "Removing Address " + deadAddress);
   if (!node.joined()) {
     node.failedConnection(deadAddress);
     return;
   }
   if (deadAddress.equals(thisAddress)) return;
   if (deadAddress.equals(getMasterAddress())) {
     if (node.joined()) {
       MemberImpl newMaster = getNextMemberAfter(deadAddress, false, 1);
       if (newMaster != null) node.setMasterAddress(newMaster.getAddress());
       else node.setMasterAddress(null);
     } else {
       node.setMasterAddress(null);
     }
     logger.log(Level.FINEST, "Now Master " + node.getMasterAddress());
   }
   if (isMaster()) {
     setJoins.remove(new MemberInfo(deadAddress));
     resetMemberMasterConfirmations();
   }
   final Connection conn = node.connectionManager.getConnection(deadAddress);
   if (destroyConnection && conn != null) {
     node.connectionManager.destroyConnection(conn);
   }
   MemberImpl deadMember = getMember(deadAddress);
   if (deadMember != null) {
     removeMember(deadMember);
     node.getClusterImpl().setMembers(lsMembers);
     node.concurrentMapManager.syncForDead(deadMember);
     node.blockingQueueManager.syncForDead(deadAddress);
     node.listenerManager.syncForDead(deadAddress);
     node.topicManager.syncForDead(deadAddress);
     // node.getClusterImpl().setMembers(lsMembers); // shifted up to get members in syncForDead
     // methods
     disconnectExistingCalls(deadAddress);
     if (isMaster()) {
       logger.log(Level.FINEST, deadAddress + " is dead. Sending remove to all other members.");
       sendRemoveMemberToOthers(deadAddress);
     }
     logger.log(Level.INFO, this.toString());
   }
 }
Ejemplo n.º 6
0
 public void stop() {
   if (setJoins != null) {
     setJoins.clear();
   }
   timeToStartJoin = 0;
   if (lsMembers != null) {
     lsMembers.clear();
   }
   dataMemberCount.reset();
   if (mapMembers != null) {
     mapMembers.clear();
   }
   if (mapCalls != null) {
     mapCalls.clear();
   }
   if (memberMasterConfirmationTimes != null) {
     memberMasterConfirmationTimes.clear();
   }
 }
Ejemplo n.º 7
0
 public void deregisterScheduledAction(ScheduledAction scheduledAction) {
   setScheduledActions.remove(scheduledAction);
 }
Ejemplo n.º 8
0
 public void registerScheduledAction(ScheduledAction scheduledAction) {
   setScheduledActions.add(scheduledAction);
 }
Ejemplo n.º 9
0
 void joinReset() {
   joinInProgress = false;
   setJoins.clear();
   timeToStartJoin = Clock.currentTimeMillis() + WAIT_MILLIS_BEFORE_JOIN;
   firstJoinRequest = 0;
 }
Ejemplo n.º 10
0
  void handleJoinRequest(JoinRequest joinRequest) {
    final long now = Clock.currentTimeMillis();
    String msg =
        "Handling join from "
            + joinRequest.address
            + ", inProgress: "
            + joinInProgress
            + (timeToStartJoin > 0 ? ", timeToStart: " + (timeToStartJoin - now) : "");
    logger.log(Level.FINEST, msg);
    boolean validJoinRequest;
    try {
      validJoinRequest = node.validateJoinRequest(joinRequest);
    } catch (Exception e) {
      validJoinRequest = false;
    }
    final Connection conn = joinRequest.getConnection();
    if (validJoinRequest) {
      final MemberImpl member = getMember(joinRequest.address);
      if (member != null) {
        if (joinRequest.getUuid().equals(member.getUuid())) {
          String message = "Ignoring join request, member already exists.. => " + joinRequest;
          logger.log(Level.FINEST, message);

          // send members update back to node trying to join again...
          final long clusterTime = node.getClusterImpl().getClusterTime();
          sendProcessableTo(new MembersUpdateCall(lsMembers, clusterTime), conn);
          sendProcessableTo(new SyncProcess(), conn);
          return;
        }
        // If this node is master then remove old member and process join request.
        // If requesting address is equal to master node's address, that means master node
        // somehow disconnected and wants to join back.
        // So drop old member and process join request if this node becomes master.
        if (isMaster() || member.getAddress().equals(getMasterAddress())) {
          logger.log(
              Level.WARNING,
              "New join request has been received from an existing endpoint! => "
                  + member
                  + " Removing old member and processing join request...");
          // If existing connection of endpoint is different from current connection
          // destroy it, otherwise keep it.
          //                    final Connection existingConnection =
          // node.connectionManager.getConnection(joinRequest.address);
          //                    final boolean destroyExistingConnection = existingConnection !=
          // conn;
          doRemoveAddress(member.getAddress(), false);
        }
      }
      if (!node.getConfig().getNetworkConfig().getJoin().getMulticastConfig().isEnabled()) {
        if (node.isActive() && node.joined() && node.getMasterAddress() != null && !isMaster()) {
          sendProcessableTo(new Master(node.getMasterAddress()), conn);
        }
      }
      if (isMaster() && node.joined() && node.isActive()) {
        final MemberInfo newMemberInfo =
            new MemberInfo(joinRequest.address, joinRequest.nodeType, joinRequest.getUuid());
        if (node.securityContext != null && !setJoins.contains(newMemberInfo)) {
          final ILogger securityLogger = node.loggingService.getLogger("com.hazelcast.security");
          final Credentials cr = joinRequest.getCredentials();
          if (cr == null) {
            securityLogger.log(
                Level.SEVERE,
                "Expecting security credentials "
                    + "but credentials could not be found in JoinRequest!");
            sendAuthFail(conn);
            return;
          } else {
            try {
              LoginContext lc = node.securityContext.createMemberLoginContext(cr);
              lc.login();
            } catch (LoginException e) {
              securityLogger.log(
                  Level.SEVERE,
                  "Authentication has failed for "
                      + cr.getPrincipal()
                      + '@'
                      + cr.getEndpoint()
                      + " => ("
                      + e.getMessage()
                      + ")");
              securityLogger.log(Level.FINEST, e.getMessage(), e);
              sendAuthFail(conn);
              return;
            }
          }
        }
        if (joinRequest.to != null && !joinRequest.to.equals(thisAddress)) {
          sendProcessableTo(new Master(node.getMasterAddress()), conn);
          return;
        }
        if (!joinInProgress) {
          if (firstJoinRequest != 0
              && now - firstJoinRequest >= MAX_WAIT_SECONDS_BEFORE_JOIN * 1000) {
            startJoin();
          } else {
            if (setJoins.add(newMemberInfo)) {
              sendProcessableTo(new Master(node.getMasterAddress()), conn);
              if (firstJoinRequest == 0) {
                firstJoinRequest = now;
              }
              if (now - firstJoinRequest < MAX_WAIT_SECONDS_BEFORE_JOIN * 1000) {
                timeToStartJoin = now + WAIT_MILLIS_BEFORE_JOIN;
              }
            }
            if (now > timeToStartJoin) {
              startJoin();
            }
          }
        }
      }
    } else {
      conn.close();
    }
  }
Ejemplo n.º 11
0
 public boolean shouldTryMerge() {
   return !joinInProgress && setJoins.size() == 0;
 }