コード例 #1
0
ファイル: DRPCSpout.java プロジェクト: MBtech/incubator-storm
  @Override
  public void fail(Object msgId) {
    DRPCMessageId did = (DRPCMessageId) msgId;
    DistributedRPCInvocations.Iface client;

    if (_local_drpc_id == null) {
      client = _clients.get(did.index);
    } else {
      client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(_local_drpc_id);
    }
    try {
      client.failRequest(did.id);
    } catch (TException e) {
      LOG.error("Failed to fail request", e);
    } catch (AuthorizationException aze) {
      LOG.error("Not authorized to failREquest from DRPC server", aze);
    }
  }
コード例 #2
0
ファイル: DRPCSpout.java プロジェクト: MBtech/incubator-storm
 @Override
 public void nextTuple() {
   boolean gotRequest = false;
   if (_local_drpc_id == null) {
     int size = 0;
     synchronized (_clients) {
       size =
           _clients
               .size(); // This will only ever grow, so no need to worry about falling off the end
     }
     for (int i = 0; i < size; i++) {
       DRPCInvocationsClient client;
       synchronized (_clients) {
         client = _clients.get(i);
       }
       if (!client.isConnected()) {
         continue;
       }
       try {
         DRPCRequest req = client.fetchRequest(_function);
         if (req.get_request_id().length() > 0) {
           Map returnInfo = new HashMap();
           returnInfo.put("id", req.get_request_id());
           returnInfo.put("host", client.getHost());
           returnInfo.put("port", client.getPort());
           gotRequest = true;
           _collector.emit(
               new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)),
               new DRPCMessageId(req.get_request_id(), i));
           break;
         }
       } catch (TException e) {
         reconnect(client);
         LOG.error("Failed to fetch DRPC result from DRPC server", e);
       } catch (AuthorizationException aze) {
         reconnect(client);
         LOG.error("Not authorized to fetch DRPC result from DRPC server", aze);
       } catch (Exception e) {
         LOG.error("Failed to fetch DRPC result from DRPC server", e);
       }
     }
     checkFutures();
   } else {
     DistributedRPCInvocations.Iface drpc =
         (DistributedRPCInvocations.Iface) ServiceRegistry.getService(_local_drpc_id);
     if (drpc != null) { // can happen during shutdown of drpc while topology is still up
       try {
         DRPCRequest req = drpc.fetchRequest(_function);
         if (req.get_request_id().length() > 0) {
           Map returnInfo = new HashMap();
           returnInfo.put("id", req.get_request_id());
           returnInfo.put("host", _local_drpc_id);
           returnInfo.put("port", 0);
           gotRequest = true;
           _collector.emit(
               new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)),
               new DRPCMessageId(req.get_request_id(), 0));
         }
       } catch (TException e) {
         throw new RuntimeException(e);
       } catch (AuthorizationException aze) {
         throw new RuntimeException(aze);
       }
     }
   }
   if (!gotRequest) {
     Utils.sleep(1);
   }
 }