예제 #1
0
 @Override
 public void run() {
   try (CDC ignored = CDC.reset(CellNucleus.this)) {
     innerRun();
   } catch (Throwable e) {
     Thread t = Thread.currentThread();
     t.getUncaughtExceptionHandler().uncaughtException(t, e);
   }
 }
예제 #2
0
 @Override
 public final void run() {
   try {
     _r.run();
   } catch (final Throwable e) {
     final Thread t = Thread.currentThread();
     final UncaughtExceptionHandler h = t.getUncaughtExceptionHandler();
     if (h != null) h.uncaughtException(t, e);
   }
 }
예제 #3
0
  public void run() {
    HawtDispatchQueue original = HawtDispatcher.CURRENT_QUEUE.get();
    HawtDispatcher.CURRENT_QUEUE.set(this);
    executing.set(Boolean.TRUE);
    try {
      Runnable runnable;
      while ((runnable = externalQueue.poll()) != null) {
        localQueue.add(runnable);
      }
      while (true) {
        if (isSuspended()) {
          return;
        }
        runnable = localQueue.poll();
        if (runnable == null) {
          return;
        }
        try {
          runnable.run();
        } catch (Throwable e) {
          Thread thread = Thread.currentThread();
          thread.getUncaughtExceptionHandler().uncaughtException(thread, e);
        }
      }
    } finally {

      // Posts any deferred events.  This ensures
      // the next events generated by this dispatch
      // queue are received in order.
      for (Runnable runnable : sourceQueue) {
        runnable.run();
      }
      sourceQueue.clear();

      executing.remove();
      HawtDispatcher.CURRENT_QUEUE.set(original);
      triggered.set(false);
      boolean empty = externalQueue.isEmpty() && localQueue.isEmpty();
      if (!isSuspended() && !empty) {
        triggerExecution();
      }
    }
  }
예제 #4
0
 public void exceptionCaught(ChannelHandlerContext ctx, Throwable t) {
   if (t instanceof ClosedChannelException) {
     _logger.info("Connection {} unexpectedly closed.", ctx.channel());
   } else if (t instanceof Exception) {
     for (NettyTransferService<HttpProtocolInfo>.NettyMoverChannel file : _files) {
       CacheException cause;
       if (file == _writeChannel) {
         cause = new FileCorruptedCacheException("Connection lost before end of file: " + t, t);
       } else {
         cause = new CacheException(t.toString(), t);
       }
       file.release(cause);
     }
     _files.clear();
     ctx.close();
   } else {
     Thread me = Thread.currentThread();
     me.getUncaughtExceptionHandler().uncaughtException(me, t);
     ctx.close();
   }
 }
예제 #5
0
  public int updateWaitQueue() {
    Collection<CellLock> expired = new ArrayList<>();
    long now = System.currentTimeMillis();
    int size;

    synchronized (_waitHash) {
      Iterator<CellLock> i = _waitHash.values().iterator();
      while (i.hasNext()) {
        CellLock lock = i.next();
        if (lock != null && !lock.isSync() && lock.getTimeout() < now) {
          expired.add(lock);
          i.remove();
        }
      }
      size = _waitHash.size();
    }

    //
    // _waitHash can't be used here. Otherwise
    // we will end up in a deadlock (NO LOCKS WHILE CALLING CALLBACKS)
    //
    for (CellLock lock : expired) {
      try {
        CellMessage envelope = lock.getMessage();
        EventLogger.sendEnd(envelope);
        lock.getCallback().answerTimedOut(envelope);
      } catch (RuntimeException e) {
        /* Don't let a problem in the callback prevent us from
         * expiring all messages.
         */
        Thread t = Thread.currentThread();
        t.getUncaughtExceptionHandler().uncaughtException(t, e);
      }
    }

    return size;
  }
예제 #6
0
  void shutdown(KillEvent event) {
    LOGGER.trace("Received {}", event);

    try (CDC ignored = CDC.reset(CellNucleus.this)) {
      _state = REMOVING;
      addToEventQueue(LAST_MESSAGE_EVENT);
      try {
        _cell.prepareRemoval(event);
      } catch (Throwable e) {
        Thread t = Thread.currentThread();
        t.getUncaughtExceptionHandler().uncaughtException(t, e);
      }

      shutdownPrivateExecutors();

      LOGGER.debug("Waiting for all threads in {} to finish", _threads);

      try {
        Collection<Thread> threads = getNonDaemonThreads(_threads);

        /* Some threads shut down asynchronously. Give them
         * one second before we start to kill them.
         */
        while (!joinThreads(threads, 1000)) {
          killThreads(threads);
        }
        _threads.destroy();
      } catch (IllegalThreadStateException e) {
        _threads.setDaemon(true);
      } catch (InterruptedException e) {
        LOGGER.warn("Interrupted while waiting for threads");
      }
      __cellGlue.destroy(CellNucleus.this);
      _state = DEAD;
    }
  }