コード例 #1
0
    @Override
    @SuppressWarnings("unchecked")
    public <T extends TransportResponse> void sendRequest(
        DiscoveryNode node,
        String action,
        TransportRequest request,
        TransportRequestOptions options,
        TransportResponseHandler<T> handler) {
      if (TransportLivenessAction.NAME.equals(action)) {
        assertHeaders(request);
        ((TransportResponseHandler<LivenessResponse>) handler)
            .handleResponse(new LivenessResponse(ClusterName.DEFAULT, node));
        return;
      }
      if (ClusterStateAction.NAME.equals(action)) {
        assertHeaders(request);
        ClusterName cluster1 = new ClusterName("cluster1");
        ((TransportResponseHandler<ClusterStateResponse>) handler)
            .handleResponse(new ClusterStateResponse(cluster1, state(cluster1)));
        clusterStateLatch.countDown();
        return;
      }

      handler.handleException(new TransportException("", new InternalException(action, request)));
    }
コード例 #2
0
    @Override
    @SuppressWarnings("unchecked")
    public <T extends TransportResponse> void sendRequest(
        DiscoveryNode node,
        String action,
        TransportRequest request,
        TransportRequestOptions options,
        TransportResponseHandler<T> handler) {
      if (TransportLivenessAction.NAME.equals(action)) {
        assertHeaders(threadPool);
        ((TransportResponseHandler<LivenessResponse>) handler)
            .handleResponse(new LivenessResponse(clusterName, node));
        return;
      }
      if (ClusterStateAction.NAME.equals(action)) {
        assertHeaders(threadPool);
        ClusterName cluster1 = new ClusterName("cluster1");
        ClusterState.Builder builder = ClusterState.builder(cluster1);
        // the sniffer detects only data nodes
        builder.nodes(
            DiscoveryNodes.builder()
                .put(
                    new DiscoveryNode(
                        "node_id",
                        address,
                        Collections.emptyMap(),
                        Collections.singleton(DiscoveryNode.Role.DATA),
                        Version.CURRENT)));
        ((TransportResponseHandler<ClusterStateResponse>) handler)
            .handleResponse(new ClusterStateResponse(cluster1, builder.build()));
        clusterStateLatch.countDown();
        return;
      }

      handler.handleException(new TransportException("", new InternalException(action)));
    }