Пример #1
0
 private <TRequest, TResponse> ClientResponseCommandExecutor<TResponse> createResponseExecutor(
     Membership.Member member, ResponseCommand<TRequest, TResponse> command) {
   ResponseCommandExecutor commandHandler = null;
   for (ResponseCommandExecutor ch : responseCommandHandlers) {
     if (ch.canHandle(command.getType())) commandHandler = ch;
   }
   if (command instanceof Udp)
     return new UdpClientResponseCommandExecutor<>(member, command, commandHandler, logger);
   return new TcpClientResponseCommandExecutor<>(member, command, commandHandler, logger);
 }
Пример #2
0
 private <TRequest, TResponse> Response<TResponse> executeAllParallel(
     ResponseCommand<TRequest, TResponse> responseCommand, boolean includeLocal) {
   Collection<Callable<Response<TResponse>>> commandExecutors = new ArrayList<>();
   if (includeLocal) {
     for (Membership.Member machine : membershipService.getMembershipList().getMemberList()) {
       commandExecutors.add(createResponseExecutor(machine, responseCommand));
     }
   } else {
     for (Membership.Member machine :
         membershipService.getMembershipListNoLocal().getMemberList()) {
       commandExecutors.add(createResponseExecutor(machine, responseCommand));
     }
   }
   List<Future<Response<TResponse>>> results;
   try {
     results = pool.invokeAll(commandExecutors);
     Response<TResponse> response = null;
     for (Future<Response<TResponse>> future : results) {
       try {
         if (response == null) response = future.get();
         else {
           Response<TResponse> tResponse = future.get();
           if (tResponse != null) {
             response.setResponseData(response.getResponseData().add(tResponse.getResponseData()));
             response.setResponse(
                 responseCommand.add(response.getResponse(), tResponse.getResponse()));
           }
         }
       } catch (ExecutionException e) {
         logger.logLine(DefaultLogger.SEVERE, String.valueOf(e));
       }
     }
     return response;
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   return null;
 }