summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java')
-rw-r--r--src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java b/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
index 779f0b00..4783c053 100644
--- a/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
+++ b/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
@@ -48,11 +48,28 @@ public abstract class DispatchCommand extends BaseCommand {
private List<String> args = new ArrayList<String>();
private final Set<Class<? extends BaseCommand>> commands;
+ private final Map<String, DispatchCommand> dispatchers;
+ private final List<BaseCommand> instantiated;
private Map<String, Class<? extends BaseCommand>> map;
- private Map<String, BaseCommand> dispatchers;
protected DispatchCommand() {
commands = new HashSet<Class<? extends BaseCommand>>();
+ dispatchers = Maps.newHashMap();
+ instantiated = new ArrayList<BaseCommand>();
+ }
+
+ @Override
+ public void destroy() {
+ super.destroy();
+ commands.clear();
+ map = null;
+
+ for (BaseCommand command : instantiated) {
+ command.destroy();
+ }
+ for (DispatchCommand dispatcher : dispatchers.values()) {
+ dispatcher.destroy();
+ }
}
protected void registerDispatcher(UserModel user, Class<? extends DispatchCommand> cmd) {
@@ -60,9 +77,6 @@ public abstract class DispatchCommand extends BaseCommand {
throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", cmd.getName(),
CommandMetaData.class.getName()));
}
- if (dispatchers == null) {
- dispatchers = Maps.newHashMap();
- }
CommandMetaData meta = cmd.getAnnotation(CommandMetaData.class);
if (meta.admin() && !user.canAdmin()) {
@@ -108,10 +122,9 @@ public abstract class DispatchCommand extends BaseCommand {
CommandMetaData meta = cmd.getAnnotation(CommandMetaData.class);
map.put(meta.name(), cmd);
}
- if (dispatchers != null) {
- for (Map.Entry<String, BaseCommand> entry : dispatchers.entrySet()) {
- map.put(entry.getKey(), entry.getValue().getClass());
- }
+
+ for (Map.Entry<String, DispatchCommand> entry : dispatchers.entrySet()) {
+ map.put(entry.getKey(), entry.getValue().getClass());
}
}
return map;
@@ -163,6 +176,7 @@ public abstract class DispatchCommand extends BaseCommand {
BaseCommand cmd = null;
try {
cmd = c.newInstance();
+ instantiated.add(cmd);
} catch (Exception e) {
throw new UnloggedFailure(1, MessageFormat.format("Failed to instantiate {0} command", commandName));
}