Search in sources :

Example 1 with ManagedThreadFactory

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

the class ProduceExceptionHandlerImp method restart.

protected void restart(final StateManagedComponent s) {
    // spin off exception handler Thread
    Thread t = new ManagedThreadFactory(getClass().getSimpleName()).newThread(new Runnable() {

        @Override
        public void run() {
            try {
                LifecycleHelper.stop(s);
                LifecycleHelper.close(s);
                LifecycleHelper.init(s);
                LifecycleHelper.start(s);
            } catch (Exception e) {
                log.error("Failed to restart " + LoggingHelper.friendlyName(s));
            }
        }
    });
    t.setName("Restart " + Thread.currentThread().getName());
    log.trace("Handling Produce Exception");
    t.start();
}
Also used : ManagedThreadFactory(com.adaptris.core.util.ManagedThreadFactory)

Example 2 with ManagedThreadFactory

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

the class ServiceWorkerPool method warmup.

public void warmup(final GenericObjectPool<Worker> objectPool) throws CoreException {
    ExecutorService populator = Executors.newCachedThreadPool(new ManagedThreadFactory(this.getClass().getSimpleName()));
    try {
        log.trace("Warming up {} service-workers", maxThreads);
        final List<Future<Worker>> futures = new ArrayList<>(maxThreads);
        for (int i = 0; i < maxThreads; i++) {
            futures.add(populator.submit(new Callable<Worker>() {

                @Override
                public Worker call() throws Exception {
                    return objectPool.borrowObject();
                }
            }));
        }
        for (Worker w : waitFor(futures)) {
            objectPool.returnObject(w);
        }
        log.trace("ObjectPool contains {} (active) of {} objects", objectPool.getNumActive(), objectPool.getNumIdle());
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    } finally {
        populator.shutdownNow();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) CoreException(com.adaptris.core.CoreException) ManagedThreadFactory(com.adaptris.core.util.ManagedThreadFactory)

Example 3 with ManagedThreadFactory

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

the class BlockingChannelLifecycleStrategy method handleOperation.

private void handleOperation(List<Channel> channels, ChannelAction op, CyclicBarrier gate) throws CoreException {
    ManagedThreadFactory factory = new ManagedThreadFactory(getClass().getSimpleName());
    Set<Thread> myThreads = Collections.newSetFromMap(new WeakHashMap<Thread, Boolean>());
    final CoreExceptionHandler exceptions = new CoreExceptionHandler();
    for (int i = 0; i < channels.size(); i++) {
        final Channel c = channels.get(i);
        final String name = c.hasUniqueId() ? c.getUniqueId() : "Channel(" + i + ")";
        Thread t = factory.newThread(new ChannelInvocationThread(name + "." + op.name(), exceptions, gate, op, c));
        t.setUncaughtExceptionHandler(exceptions);
        myThreads.add(t);
        t.start();
    }
    try {
        gate.await(timeoutMs(), TimeUnit.MILLISECONDS);
    } catch (Exception gateException) {
        CoreException e = new CoreException("Exception waiting for all channel." + op.name() + " operations to complete", gateException);
        exceptions.uncaughtException(Thread.currentThread(), e);
        // I've been interrupted; so interrupt children!
        interrupt(myThreads);
    }
    CoreException e = exceptions.getFirstThrowableException();
    if (e != null) {
        throw e;
    }
}
Also used : CoreException(com.adaptris.core.CoreException) Channel(com.adaptris.core.Channel) CoreException(com.adaptris.core.CoreException) ManagedThreadFactory(com.adaptris.core.util.ManagedThreadFactory)

Example 4 with ManagedThreadFactory

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

the class FilteredSharedComponentStart method getExecutor.

private ExecutorService getExecutor(String name) {
    ExecutorService es = connectionStarters.get(name);
    if (es == null || es.isShutdown()) {
        es = Executors.newSingleThreadExecutor(new ManagedThreadFactory(getClass().getSimpleName()));
        connectionStarters.put(name, es);
    }
    return es;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ManagedThreadFactory(com.adaptris.core.util.ManagedThreadFactory)

Example 5 with ManagedThreadFactory

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

the class NonBlockingChannelStartStrategy method getExecutor.

private ExecutorService getExecutor(String name) {
    ExecutorService es = channelStarters.get(name);
    if (es == null || es.isShutdown()) {
        es = Executors.newSingleThreadExecutor(new ManagedThreadFactory(getClass().getSimpleName()));
        channelStarters.put(name, es);
    }
    return es;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) 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