protected void consumeBatch(EventHandler<Object> handler) { boolean isConsumeEvent = false; if (controlQueue.population() > 0) { controlQueue.consumeBatch(handler); isConsumeEvent = true; } if (exeQueue.population() > 0) { exeQueue.consumeBatch(handler); isConsumeEvent = true; } if (!isConsumeEvent) JStormUtils.sleepMs(1); } }
public void serializer(KryoTupleSerializer serializer) { LOG.debug("start serializer of task: {}", taskId); if (!AsyncLoopRunnable.getShutdown().get()) { //note: sleep 1ms to reduce cpu usage when serializeQueue is empty if (serializeQueue.population() == 0) { Utils.sleep(1); return; } try { List<Object> objects = serializeQueue.retreiveAvailableBatch(); for (Object object : objects) { if (object == null) { continue; } serialize(serializer, object); } } catch (InterruptedException e) { LOG.error("InterruptedException " + e.getCause()); } catch (TimeoutException ignored) { } catch (AlertException e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); } } }
public boolean deserializer(KryoTupleDeserializer deserializer, boolean forceConsume) { //LOG.debug("start Deserializer of task, {}", taskId); boolean isIdling = true; DisruptorQueue exeQueue = innerTaskTransfer.get(taskId); if (!taskStatus.isShutdown()) { if ((deserializeQueue.population() > 0 && exeQueue.pctFull() < 1.0) || forceConsume) { try { List<Object> objects = deserializeQueue.retreiveAvailableBatch(); for (Object object : objects) { deserialize(deserializer, (byte[]) object, exeQueue); } isIdling = false; } catch (InterruptedException e) { LOG.error("InterruptedException " + e.getCause()); return true; } catch (TimeoutException e) { return true; } catch (Throwable e) { if (Utils.exceptionCauseIsInstanceOf(KryoException.class, e)) { throw new RuntimeException(e); } else if (!taskStatus.isShutdown()) { LOG.error("Unknown exception ", e); } } } } else { task.unregisterDeserializeQueue(); } return isIdling; }
public float pctFull() { return (1.0F * population() / capacity()); }
public void serializer(KryoTupleSerializer serializer) { LOG.debug("start Serializer of task, {}", taskId); if (!AsyncLoopRunnable.getShutdown().get()) { //note: avoid to cpu idle when serializeQueue is empty if (serializeQueue.population() == 0){ Utils.sleep(1); return; } try { List<Object> objects = serializeQueue.retreiveAvailableBatch(); for (Object object : objects) { if (object == null) { continue; } serialize(serializer, object); } } catch (InterruptedException e) { LOG.error("InterruptedException " + e.getCause()); return; } catch (TimeoutException e) { return; }catch (AlertException e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); } } }
public boolean deserializer(KryoTupleDeserializer deserializer, boolean forceConsume) { //LOG.debug("start Deserializer of task, {}", taskId); boolean isIdling = true; DisruptorQueue exeQueue = innerTaskTransfer.get(taskId); if (!taskStatus.isShutdown()) { if ((deserializeQueue.population() > 0 && exeQueue.pctFull() < 1.0) || forceConsume) { try { List<Object> objects = deserializeQueue.retreiveAvailableBatch(); for (Object object : objects) { deserialize(deserializer, (byte[]) object, exeQueue); } isIdling = false; } catch (InterruptedException e) { LOG.error("InterruptedException " + e.getCause()); return isIdling; } catch (TimeoutException e) { return isIdling; } catch (Throwable e) { if (Utils.exceptionCauseIsInstanceOf(KryoException.class, e)) { throw new RuntimeException(e); } else if (!taskStatus.isShutdown()) { LOG.error("Unknow exception ", e); } } } } else { task.unregisterDeserializeQueue(); } return isIdling; }