@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); } } }
// Add partition id of sender private void decorateRequest(Request r) { Request.RInfo rinfo = r.getRInfo(); if (rinfo != null && listener != null) rinfo.setPartition(listener.getId()); }