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();
}
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();
}
}
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;
}
}
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;
}
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;
}
Aggregations