示例#1
0
 Consumer<U> check(long maxTime) {
   for (PooledFatPipe child : producer.children) {
     Consumer<U> consumer = child.check(maxTime, parent);
     if (consumer != null) return consumer;
   }
   return null;
 }
示例#2
0
 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();
   }
 }
示例#3
0
 @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;
 }
示例#4
0
 public void shutdown(long time, TimeUnit unit) {
   parent.shutdown(time, unit);
   producer.shutdown();
 }
示例#5
0
 public void start() {
   parent.start();
   Receptor<Object> parentRecptor = parent.takeReceptor();
   parentRecptor.set(new Object());
 }
示例#6
0
 void setSleep(long sleep) {
   parent.setSleep(sleep);
 }
示例#7
0
 private void shutdown() {
   for (PooledFatPipe child : children) {
     child.shutdown(0, TimeUnit.MILLISECONDS);
   }
   executor.shutdown();
 }