Ejemplo n.º 1
0
  public void connectionRemoved(Connection connection) {
    if (connection.isClient() && connection instanceof TcpIpConnection && nodeEngine.isActive()) {
      final ClientEndpoint endpoint = endpoints.get(connection);
      if (endpoint != null
          && node.getLocalMember().getUuid().equals(endpoint.getPrincipal().getOwnerUuid())) {
        removeEndpoint(connection, true);
        if (!endpoint.isFirstConnection()) {
          return;
        }
        NodeEngine nodeEngine = node.nodeEngine;
        final Collection<MemberImpl> memberList = nodeEngine.getClusterService().getMemberList();
        for (MemberImpl member : memberList) {
          final ClientDisconnectionOperation op =
              new ClientDisconnectionOperation(endpoint.getUuid());
          op.setNodeEngine(nodeEngine)
              .setServiceName(SERVICE_NAME)
              .setService(this)
              .setResponseHandler(ResponseHandlerFactory.createEmptyResponseHandler());

          if (member.localMember()) {
            nodeEngine.getOperationService().runOperation(op);
          } else {
            nodeEngine.getOperationService().send(op, member.getAddress());
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
    @Override
    public void connectionRemoved(Connection connection) {
      if (connection.isClient() && nodeEngine.isRunning()) {
        ClientEndpointImpl endpoint = (ClientEndpointImpl) endpointManager.getEndpoint(connection);
        if (endpoint == null) {
          return;
        }

        if (!endpoint.isFirstConnection()) {
          return;
        }

        String localMemberUuid = node.getLocalMember().getUuid();
        String ownerUuid = endpoint.getPrincipal().getOwnerUuid();
        if (localMemberUuid.equals(ownerUuid)) {
          callDisconnectionOperation(endpoint);
        }
      }
    }
  @Override
  public boolean registerConnection(final Address remoteEndPoint, final Connection connection) {
    if (remoteEndPoint.equals(ioService.getThisAddress())) {
      return false;
    }

    if (connection instanceof TcpIpConnection) {
      TcpIpConnection tcpConnection = (TcpIpConnection) connection;
      Address currentEndPoint = tcpConnection.getEndPoint();
      if (currentEndPoint != null && !currentEndPoint.equals(remoteEndPoint)) {
        throw new IllegalArgumentException(
            connection + " has already a different endpoint than: " + remoteEndPoint);
      }
      tcpConnection.setEndPoint(remoteEndPoint);

      if (!connection.isClient()) {
        TcpIpConnectionMonitor connectionMonitor = getConnectionMonitor(remoteEndPoint, true);
        tcpConnection.setMonitor(connectionMonitor);
      }
    }
    connectionsMap.put(remoteEndPoint, connection);
    connectionsInProgress.remove(remoteEndPoint);
    ioService
        .getEventService()
        .executeEventCallback(
            new StripedRunnable() {
              @Override
              public void run() {
                for (ConnectionListener listener : connectionListeners) {
                  listener.connectionAdded(connection);
                }
              }

              @Override
              public int getKey() {
                return remoteEndPoint.hashCode();
              }
            });
    return true;
  }