mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Merged IncomingConnectionExecutor and PluginExecutor into IoExecutor.
We don't need two separate executors for long-running IO threads.
This commit is contained in:
@@ -1,18 +1,49 @@
|
||||
package org.briarproject.lifecycle;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.briarproject.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
public class LifecycleModule extends AbstractModule {
|
||||
|
||||
private final ExecutorService ioExecutor;
|
||||
|
||||
public LifecycleModule() {
|
||||
// The thread pool is unbounded, so use direct handoff
|
||||
BlockingQueue<Runnable> queue = new SynchronousQueue<Runnable>();
|
||||
// Discard tasks that are submitted during shutdown
|
||||
RejectedExecutionHandler policy =
|
||||
new ThreadPoolExecutor.DiscardPolicy();
|
||||
// Create threads as required and keep them in the pool for 60 seconds
|
||||
ioExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
|
||||
60, SECONDS, queue, policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(LifecycleManager.class).to(
|
||||
LifecycleManagerImpl.class).in(Singleton.class);
|
||||
bind(ShutdownManager.class).to(
|
||||
ShutdownManagerImpl.class).in(Singleton.class);
|
||||
}
|
||||
|
||||
@Provides @Singleton @IoExecutor
|
||||
Executor getIoExecutor(LifecycleManager lifecycleManager) {
|
||||
lifecycleManager.registerForShutdown(ioExecutor);
|
||||
return ioExecutor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user