コード例 #1
0
  protected ClusterNodeResponse executeClusterRequest(ClusterRequest clusterRequest) {

    Serializable payload = clusterRequest.getPayload();

    if (!(payload instanceof MethodHandler)) {
      return ClusterNodeResponse.createExceptionClusterNodeResponse(
          _localClusterNode,
          clusterRequest.getUuid(),
          new ClusterException("Payload is not of type " + MethodHandler.class.getName()));
    }

    MethodHandler methodHandler = (MethodHandler) payload;

    ClusterInvokeThreadLocal.setEnabled(false);

    try {
      return ClusterNodeResponse.createResultClusterNodeResponse(
          _localClusterNode, clusterRequest.getUuid(), methodHandler.invoke());
    } catch (Exception e) {
      return ClusterNodeResponse.createExceptionClusterNodeResponse(
          _localClusterNode, clusterRequest.getUuid(), e);
    } finally {
      ClusterInvokeThreadLocal.setEnabled(true);
    }
  }
コード例 #2
0
  @AdviseWith(adviceClasses = {EnableClusterLinkAdvice.class})
  @Test
  public void testInvoke3() throws Exception {
    ClusterExecutorImpl clusterExecutorImpl1 = null;
    ClusterExecutorImpl clusterExecutorImpl2 = null;

    try {
      clusterExecutorImpl1 = getClusterExecutorImpl(false, false);
      clusterExecutorImpl2 = getClusterExecutorImpl(false, false);

      MethodHandler methodHandler = new MethodHandler(testMethod2MethodKey);

      Address address = clusterExecutorImpl2.getLocalClusterNodeAddress();

      ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest(methodHandler, address);

      FutureClusterResponses futureClusterResponses = clusterExecutorImpl1.execute(clusterRequest);

      assertFutureClusterResponsesWithException(
          futureClusterResponses,
          clusterRequest.getUuid(),
          address,
          "Return value is not serializable");
    } finally {
      if (clusterExecutorImpl1 != null) {
        clusterExecutorImpl1.destroy();
      }

      if (clusterExecutorImpl2 != null) {
        clusterExecutorImpl2.destroy();
      }
    }
  }
コード例 #3
0
  @AdviseWith(adviceClasses = {EnableClusterLinkAdvice.class})
  @Test
  public void testInvoke2() throws Exception {
    ClusterExecutorImpl clusterExecutorImpl1 = null;
    ClusterExecutorImpl clusterExecutorImpl2 = null;

    try {
      clusterExecutorImpl1 = getClusterExecutorImpl(false, false);
      clusterExecutorImpl2 = getClusterExecutorImpl(false, false);

      String timestamp = String.valueOf(System.currentTimeMillis());

      MethodHandler methodHandler = new MethodHandler(testMethod1MethodKey, timestamp);

      Address address = clusterExecutorImpl2.getLocalClusterNodeAddress();

      ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest(methodHandler, address);

      FutureClusterResponses futureClusterResponses = clusterExecutorImpl1.execute(clusterRequest);

      assertFutureClusterResponsesWithoutException(
          futureClusterResponses.get(), clusterRequest.getUuid(), timestamp, address);
    } finally {
      if (clusterExecutorImpl1 != null) {
        clusterExecutorImpl1.destroy();
      }

      if (clusterExecutorImpl2 != null) {
        clusterExecutorImpl2.destroy();
      }
    }
  }
コード例 #4
0
  @AdviseWith(adviceClasses = {EnableClusterLinkAdvice.class})
  @Test
  public void testInvoke6() throws Exception {
    ClusterExecutorImpl clusterExecutorImpl1 = null;
    ClusterExecutorImpl clusterExecutorImpl2 = null;

    try {
      clusterExecutorImpl1 = getClusterExecutorImpl(false, true);
      clusterExecutorImpl2 = getClusterExecutorImpl(false, true);

      MethodHandler methodHandler = new MethodHandler(testMethod4MethodKey);

      Address address = clusterExecutorImpl2.getLocalClusterNodeAddress();

      ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest(methodHandler, address);

      clusterRequest.setBeanIdentifier(BEAN_IDENTIFIER);

      FutureClusterResponses futureClusterResponses = clusterExecutorImpl1.execute(clusterRequest);

      assertFutureClusterResponsesWithoutException(
          futureClusterResponses.get(),
          clusterRequest.getUuid(),
          SERIALIZABLE_RETRUN_VALUE,
          address);
    } finally {
      if (clusterExecutorImpl1 != null) {
        clusterExecutorImpl1.destroy();
      }

      if (clusterExecutorImpl2 != null) {
        clusterExecutorImpl2.destroy();
      }
    }
  }
コード例 #5
0
  @AdviseWith(adviceClasses = {EnableClusterLinkAdvice.class})
  @Test
  public void testInvoke5() throws Exception {
    ClusterExecutorImpl clusterExecutorImpl1 = null;
    ClusterExecutorImpl clusterExecutorImpl2 = null;

    try {
      clusterExecutorImpl1 = getClusterExecutorImpl(false, false);
      clusterExecutorImpl2 = getClusterExecutorImpl(false, false);

      Address address = clusterExecutorImpl2.getLocalClusterNodeAddress();

      ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest(null, address);

      FutureClusterResponses futureClusterResponses = clusterExecutorImpl1.execute(clusterRequest);

      assertFutureClusterResponsesWithException(
          futureClusterResponses,
          clusterRequest.getUuid(),
          address,
          "Payload is not of type " + MethodHandler.class.getName());
    } finally {
      if (clusterExecutorImpl1 != null) {
        clusterExecutorImpl1.destroy();
      }

      if (clusterExecutorImpl2 != null) {
        clusterExecutorImpl2.destroy();
      }
    }
  }
コード例 #6
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;
  }
コード例 #7
0
  @AdviseWith(adviceClasses = {EnableClusterLinkAdvice.class})
  @Test
  public void testInvoke9() throws Exception {
    ClusterExecutorImpl clusterExecutorImpl1 = null;
    ClusterExecutorImpl clusterExecutorImpl2 = null;

    try {
      clusterExecutorImpl1 = getClusterExecutorImpl(false, true);
      clusterExecutorImpl2 = getClusterExecutorImpl(false, true);

      MethodHandler methodHandler =
          new MethodHandler(new MethodKey(TestBean.class, "nonexistentMethod"));

      Address address = clusterExecutorImpl2.getLocalClusterNodeAddress();

      ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest(methodHandler, address);

      clusterRequest.setServletContextName(SERVLET_CONTEXT_NAME);

      List<LogRecord> logRecords =
          JDKLoggerTestUtil.configureJDKLogger(
              ClusterRequestReceiver.class.getName(), Level.SEVERE);

      FutureClusterResponses futureClusterResponses = clusterExecutorImpl1.execute(clusterRequest);

      assertFutureClusterResponsesWithException(
          futureClusterResponses, clusterRequest.getUuid(), address, null);

      assertLogger(
          logRecords, "Unable to invoke method " + methodHandler, NoSuchMethodException.class);
    } finally {
      if (clusterExecutorImpl1 != null) {
        clusterExecutorImpl1.destroy();
      }

      if (clusterExecutorImpl2 != null) {
        clusterExecutorImpl2.destroy();
      }
    }
  }
コード例 #8
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;
    }