예제 #1
0
  @Override
  public FutureClusterResponses execute(ClusterRequest clusterRequest) {
    if (!isEnabled()) {
      return null;
    }

    List<Address> addresses = prepareAddresses(clusterRequest);

    Set<String> clusterNodeIds = new HashSet<>();

    for (Address address : addresses) {
      ClusterNode clusterNode = _liveInstances.get(address);

      if (clusterNode != null) {
        clusterNodeIds.add(clusterNode.getClusterNodeId());
      }
    }

    FutureClusterResponses futureClusterResponses = new FutureClusterResponses(clusterNodeIds);

    if (!clusterRequest.isFireAndForget()) {
      String uuid = clusterRequest.getUuid();

      _futureClusterResponses.put(uuid, futureClusterResponses);
    }

    if (addresses.remove(_localAddress)) {
      ClusterNodeResponse clusterNodeResponse = executeClusterRequest(clusterRequest);

      if (!clusterRequest.isFireAndForget()) {
        futureClusterResponses.addClusterNodeResponse(clusterNodeResponse);
      }
    }

    if (clusterRequest.isMulticast()) {
      try {
        _controlJChannel.send(null, clusterRequest);
      } catch (Exception e) {
        throw new SystemException("Unable to send multicast request", e);
      }
    } else {
      for (Address address : addresses) {
        org.jgroups.Address jGroupsAddress = (org.jgroups.Address) address.getRealAddress();

        try {
          _controlJChannel.send(jGroupsAddress, clusterRequest);
        } catch (Exception e) {
          throw new SystemException("Unable to send unicast request", e);
        }
      }
    }

    return futureClusterResponses;
  }
  @Override
  protected void doCoordinatorAddressUpdated(
      Address oldCoordinatorAddress, Address newCoordinatorAddress) {

    if (oldCoordinatorAddress.equals(newCoordinatorAddress)) {
      return;
    }

    _clusterExecutorImpl.fireClusterEvent(
        new ClusterEvent(ClusterEventType.COORDINATOR_ADDRESS_UPDATE));
  }
예제 #3
0
    @Override
    public FutureClusterResponses execute(ClusterRequest clusterRequest) {
      List<Address> addresses = new ArrayList<Address>();

      Collection<Address> clusterNodeAddresses = clusterRequest.getTargetClusterNodeAddresses();

      if (clusterNodeAddresses != null) {
        addresses.addAll(clusterNodeAddresses);
      }

      FutureClusterResponses futureClusterResponses = new FutureClusterResponses(addresses);

      for (Address address : addresses) {
        ClusterNodeResponse clusterNodeResponse = new ClusterNodeResponse();

        clusterNodeResponse.setAddress(address);
        clusterNodeResponse.setClusterMessageType(ClusterMessageType.EXECUTE);
        clusterNodeResponse.setMulticast(clusterRequest.isMulticast());
        clusterNodeResponse.setUuid(clusterRequest.getUuid());

        MockAddress mockAddress = (MockAddress) address.getRealAddress();

        try {
          clusterNodeResponse.setClusterNode(
              new ClusterNode(
                  String.valueOf(mockAddress.getTimestamp()), InetAddress.getLocalHost()));

          clusterNodeResponse.setResult(_invoke(clusterRequest.getMethodHandler()));
        } catch (Exception e) {
        }

        futureClusterResponses.addClusterNodeResponse(clusterNodeResponse);
      }

      return futureClusterResponses;
    }
  @Override
  protected void doReceive(Object messagePayload, Address srcAddress) {
    ClusterChannel clusterChannel = _clusterExecutorImpl.getClusterChannel();

    if (srcAddress.equals(clusterChannel.getLocalAddress())) {
      return;
    }

    try {
      if (messagePayload instanceof ClusterRequest) {
        ClusterRequest clusterRequest = (ClusterRequest) messagePayload;

        Serializable responsePayload =
            _clusterExecutorImpl.handleReceivedClusterRequest(clusterRequest);

        if (clusterRequest.isFireAndForget()) {
          return;
        }

        try {
          clusterChannel.sendUnicastMessage(responsePayload, srcAddress);
        } catch (Throwable t) {
          _log.error("Unable to send message " + responsePayload, t);
        }
      } else if (messagePayload instanceof ClusterNodeResponse) {
        _clusterExecutorImpl.handleReceivedClusterNodeResponse(
            (ClusterNodeResponse) messagePayload);
      } else if (_log.isWarnEnabled()) {
        _log.warn("Unable to process message content of type " + messagePayload.getClass());
      }
    } finally {
      ThreadLocalCacheManager.clearAll(Lifecycle.REQUEST);

      CentralizedThreadLocal.clearShortLivedThreadLocals();
    }
  }