Consumer<U> check(long maxTime) { for (PooledFatPipe child : producer.children) { Consumer<U> consumer = child.check(maxTime, parent); if (consumer != null) return consumer; } return null; }
private void add(PooledFatPipe child) { parent.adding = true; try { parent.lock.acquire(); } catch (InterruptedException e) { logger.warn("add", e); return; } finally { parent.adding = false; } try { producer.add(child); } finally { parent.lock.release(); } }
@Override public Boolean execute(Object d, Receptor<Object> r, Signal parent) { r.lazySet(d); // put the data back in for polling boolean data = false; for (int i = 0; i < children.length; i++) { AtomicIntegerArray inUse = this.inUse; if (!inUse.compareAndSet(i, 0, 1)) { if (inUse.get(i) == 2) sleep(); continue; } PooledFatPipe child = children[i]; if (child == null) { inUse.set(i, 0); continue; } Signal signal; if (parent.getThreadIndex() < 0) { signal = new ChildSignalImpl(inUse, i); } else { ChildSignalImpl s = signals[i * poolSize + parent.getThreadIndex()]; if (s == null || s.inUse != inUse) { sleep(); inUse.set(i, 0); continue; } s.index = i; s.notified = false; signal = s; } try { data |= child.poll(signal, parent); } catch (Exception e) { if (listener == null) logger.error("poll", e); else listener.exceptionThrown(e); } finally { signal.signal(); } } return data ? Boolean.TRUE : null; }
public void shutdown(long time, TimeUnit unit) { parent.shutdown(time, unit); producer.shutdown(); }
public void start() { parent.start(); Receptor<Object> parentRecptor = parent.takeReceptor(); parentRecptor.set(new Object()); }
void setSleep(long sleep) { parent.setSleep(sleep); }
private void shutdown() { for (PooledFatPipe child : children) { child.shutdown(0, TimeUnit.MILLISECONDS); } executor.shutdown(); }