Exemplo n.º 1
0
 @Override
 @SuppressWarnings({"unchecked"})
 public void shutdown(long time, TimeUnit unit) {
   started = false;
   try {
     lock.tryAcquire(time, unit);
   } catch (InterruptedException e) {
     logger.warn("shutdown", e);
   }
   if (group != null) group.interrupt();
   consumers = new Consumer[0];
   consumerSeqs = new long[0];
   outUse = new AtomicLongArray(0);
   executor.shutdown();
 }
Exemplo n.º 2
0
 @Override
 public synchronized Receptor<T> takeReceptor() {
   if (!freeReceptors.isEmpty()) {
     ReceptorImpl impl = (ReceptorImpl) freeReceptors.remove(0);
     impl.skips = 0;
     return impl;
   }
   int length = inputs.length() + 1;
   final AtomicReferenceArray<T> inputs = new AtomicReferenceArray<>(length);
   this.inputs = inputs;
   final List<ReceptorImpl> newReuseReceptors = new ArrayList<>(length);
   for (int i = 0; i < length; i++) {
     newReuseReceptors.add(new ReceptorImpl(i));
   }
   executor.execute(
       () -> {
         long lastTime = System.currentTimeMillis();
         try {
           boolean empty = false;
           while (!empty && started) {
             empty = true;
             for (int i = 0; i < outputs.length(); i++) {
               T result = outputs.get(i);
               if (result == null) continue;
               Thread.sleep(1);
               empty = false;
               if (lastTime + 30_000 < System.currentTimeMillis()) {
                 lastTime = System.currentTimeMillis();
                 logger.error(
                     "unable to set receptors for " + producer + " i=" + i + " result=" + result);
                 if (pool != null) logger.warn("pool=" + pool.producer);
               }
               break;
             }
           }
         } catch (InterruptedException e) {
           logger.warn("takeReceptor", e);
         } finally {
           reuseReceptors = newReuseReceptors;
           outputs = inputs;
         }
       });
   return new ReceptorImpl(length - 1);
 }