Stop SshCommandDestroy thread pool on server shutdown

This avoids leaking the thread during acceptance tests.

Change-Id: I18a7f57bc6b381f28006a20b6cffda0be6b3fb46
This commit is contained in:
Shawn Pearce 2013-07-29 22:29:54 -07:00 committed by Dave Borowitz
parent d46c321e32
commit a206e11fad
2 changed files with 17 additions and 3 deletions

View File

@ -16,6 +16,7 @@ package com.google.gerrit.sshd;
import com.google.common.util.concurrent.Atomics;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.git.WorkQueue;
@ -23,6 +24,7 @@ import com.google.gerrit.sshd.SshScope.Context;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.CommandFactory;
@ -39,7 +41,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
@ -49,7 +51,9 @@ import java.util.concurrent.atomic.AtomicReference;
/**
* Creates a CommandFactory using commands registered by {@link CommandModule}.
*/
class CommandFactoryProvider implements Provider<CommandFactory> {
@Singleton
class CommandFactoryProvider implements Provider<CommandFactory>,
LifecycleListener {
private static final Logger logger = LoggerFactory
.getLogger(CommandFactoryProvider.class);
@ -57,7 +61,7 @@ class CommandFactoryProvider implements Provider<CommandFactory> {
private final SshLog log;
private final SshScope sshScope;
private final ScheduledExecutorService startExecutor;
private final Executor destroyExecutor;
private final ExecutorService destroyExecutor;
private final SchemaFactory<ReviewDb> schemaFactory;
@Inject
@ -79,6 +83,15 @@ class CommandFactoryProvider implements Provider<CommandFactory> {
.build());
}
@Override
public void start() {
}
@Override
public void stop() {
destroyExecutor.shutdownNow();
}
@Override
public CommandFactory get() {
return new CommandFactory() {

View File

@ -107,6 +107,7 @@ public class SshModule extends FactoryModule {
listener().toInstance(registerInParentInjectors());
listener().to(SshLog.class);
listener().to(SshDaemon.class);
listener().to(CommandFactoryProvider.class);
}
});
}