Search in sources :

Example 11 with ManagedThreadFactory

use of com.adaptris.core.util.ManagedThreadFactory in project interlok by adaptris.

the class AdaptrisMessageWorkerImp method handleConnectionException.

/**
 * @see com.adaptris.core.AdaptrisMessageWorker #handleConnectionException()
 */
@Override
public void handleConnectionException() throws CoreException {
    if (hasActiveErrorHandler()) {
        // spin off exception handler Thread
        Thread thread = new ManagedThreadFactory(getClass().getSimpleName()).newThread(new Runnable() {

            @Override
            public void run() {
                retrieveConnection(AdaptrisConnection.class).connectionErrorHandler().handleConnectionException();
            }
        });
        thread.setName("Connection Exc: " + Thread.currentThread().getName());
        log.trace("Handling Connection Exception");
        thread.start();
    }
}
Also used : ManagedThreadFactory(com.adaptris.core.util.ManagedThreadFactory)

Example 12 with ManagedThreadFactory

use of com.adaptris.core.util.ManagedThreadFactory in project interlok by adaptris.

the class ActiveJmsConnectionErrorHandler method init.

@Override
public void init() throws CoreException {
    super.init();
    try {
        MyExceptionHandler handler = new MyExceptionHandler();
        CountDownLatch verifierThreadGate = new CountDownLatch(1);
        verifier = new JmsConnectionVerifier(idForLogging, verifierThreadGate);
        Thread verifierThread = new ManagedThreadFactory(getClass().getSimpleName()).newThread(verifier);
        verifierThread.setName("JmsConnectionErrorHandler for " + idForLogging);
        verifierThread.setUncaughtExceptionHandler(handler);
        verifierThread.start();
        boolean actuallyStarted = verifierThreadGate.await(DEFAULT_MAX_WAIT_FOR_START.toMilliseconds(), TimeUnit.MILLISECONDS);
        if (!actuallyStarted) {
            if (handler.hasError()) {
                ExceptionHelper.rethrowCoreException(handler.lastException());
            } else {
                throw new CoreException("Failed to start connection error handler");
            }
        }
        if (additionalLogging()) {
            log.debug("ActiveJmsConnectionErrorHandler for {} started", idForLogging);
        }
    } catch (Exception e) {
        ExceptionHelper.rethrowCoreException(e);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) CountDownLatch(java.util.concurrent.CountDownLatch) JMSException(javax.jms.JMSException) CoreException(com.adaptris.core.CoreException) ManagedThreadFactory(com.adaptris.core.util.ManagedThreadFactory)

Aggregations

ManagedThreadFactory (com.adaptris.core.util.ManagedThreadFactory)12 CoreException (com.adaptris.core.CoreException)7 TimeInterval (com.adaptris.util.TimeInterval)4 Test (org.junit.Test)4 Adapter (com.adaptris.core.Adapter)3 MockFailingConnection (com.adaptris.core.stubs.MockFailingConnection)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 ExecutorService (java.util.concurrent.ExecutorService)3 TimeoutException (java.util.concurrent.TimeoutException)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 ObjectName (javax.management.ObjectName)3 Channel (com.adaptris.core.Channel)1 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)1 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 JMSException (javax.jms.JMSException)1