コード例 #1
0
ファイル: CommLayerEmitter.java プロジェクト: thaingo/s4
  @Override
  public void emit(int partitionId, EventWrapper eventWrapper) {

    // Special handling required for Requests
    if (eventWrapper.getEvent() instanceof Request) {
      decorateRequest((Request) eventWrapper.getEvent());
    }

    try {
      byte[] rawMessage = serDeser.serialize(eventWrapper);
      MessageHolder mh = new MessageHolder(partitionId, rawMessage);
      queueMessage(mh);
    } catch (RuntimeException rte) {
      if (monitor != null) {
        monitor.increment(
            low_level_emitter_out_err_ct.toString(),
            1,
            S4_EVENT_METRICS.toString(),
            "et",
            eventWrapper.getStreamName());
      }
      Logger.getLogger("s4")
          .error("Error serializing or emitting event " + eventWrapper.getEvent(), rte);
      throw rte;
    }
  }
コード例 #2
0
ファイル: CommLayerEmitter.java プロジェクト: thaingo/s4
 public void queueMessage(MessageHolder messageHolder) {
   messageQueue.add(messageHolder);
   try {
     if (monitor != null) {
       monitor.set(
           low_level_emitter_qsz.toString(), messageQueue.size(), S4_CORE_METRICS.toString());
     }
   } catch (Exception e) {
     logger.error("Exception in monitor metrics on thread " + Thread.currentThread().getId(), e);
   }
 }
コード例 #3
0
ファイル: CommLayerEmitter.java プロジェクト: thaingo/s4
  @Override
  public void run() {
    if (listener == null) {
      if (listenerAppName == null) {
        listenerAppName = appName;
      }
      sender = new SenderProcess(clusterManagerAddress, appName, listenerAppName);
      Map<String, String> map = new HashMap<String, String>();
      map.put("SenderId", "" + senderId);
      sender.setSerializer(new PassThroughSerializer());
      sender.acquireTaskAndCreateSender(map);
    } else {
      Object listenerConfig = null;
      try {
        listenerConfig = listener.getListenerConfig();
        if (listenerConfig == null) {
          logger.info("CommLayerEmitter going to wait for listener to acquire task");
          synchronized (listener) {
            listenerConfig = listener.getListenerConfig();
            if (listenerConfig == null) {
              listener.wait();
              listenerConfig = listener.getListenerConfig();
            }
          }
        }
      } catch (Exception e) {
        logger.info("Exception in CommLayerEmitter.run()", e);
      }
      logger.info("Creating sender process with " + listenerConfig);

      String destinationAppName =
          (listenerAppName != null ? listenerAppName : listener.getAppName());

      sender =
          new SenderProcess(
              listener.getClusterManagerAddress(), listener.getAppName(), destinationAppName);

      sender.setSerializer(new PassThroughSerializer());
      sender.createSenderFromConfig(listenerConfig);
      nodeCount = sender.getNumOfPartitions();
    }
    boolean isSent = false;
    while (!Thread.interrupted()) {
      isSent = false;
      try {
        MessageHolder mh = messageQueue.take();
        byte[] rawMessage = mh.getRawMessage();
        if (listener == null) {
          isSent = sender.send(rawMessage);
        } else {
          isSent = sender.sendToPartition(mh.getPartitionId(), rawMessage);
        }

        if (isSent) {
          if (monitor != null) {
            monitor.increment(
                low_level_emitter_msg_out_ct.toString(), 1, S4_CORE_METRICS.toString());
          }
        } else {
          if (monitor != null) {
            monitor.increment(
                low_level_emitter_out_err_ct.toString(), 1, S4_CORE_METRICS.toString());
          }
          logger.warn("commlayer emit failed ...");
        }
      } catch (InterruptedException ie) {
        if (monitor != null) {
          monitor.increment(low_level_emitter_out_err_ct.toString(), 1, S4_CORE_METRICS.toString());
        }
        Thread.currentThread().interrupt();
      } catch (Exception e) {
        Logger.getLogger("s4").error("Error emitting message", e);
      }
    }
  }