From a782480e732d6cd86f74b00cb766f8b9f970142e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=BCger?= Date: Thu, 15 Oct 2015 12:26:34 +0200 Subject: [PATCH] [KARAF-4068] Remove unused list of sessions The list of created sessions is not used. But even more of a problem is the fact that closed sessions are not removed from the list. During the runtime of the session factory all sessions are tracked. --- .../karaf/shell/impl/console/SessionFactoryImpl.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java index ba20338..c238aa0 100644 --- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java +++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/SessionFactoryImpl.java @@ -20,9 +20,7 @@ package org.apache.karaf.shell.impl.console; import java.io.InputStream; import java.io.PrintStream; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.apache.felix.gogo.runtime.CommandProcessorImpl; @@ -41,7 +39,6 @@ public class SessionFactoryImpl extends RegistryImpl implements SessionFactory, final CommandProcessorImpl commandProcessor; final ThreadIO threadIO; - final List sessions = new ArrayList(); final Map subshells = new HashMap(); boolean closed; @@ -108,12 +105,11 @@ public class SessionFactoryImpl extends RegistryImpl implements SessionFactory, @Override public Session create(InputStream in, PrintStream out, PrintStream err, Terminal term, String encoding, Runnable closeCallback) { - synchronized (sessions) { + synchronized (commandProcessor) { if (closed) { throw new IllegalStateException("SessionFactory has been closed"); } final Session session = new ConsoleSessionImpl(this, commandProcessor, threadIO, in, out, err, term, encoding, closeCallback); - sessions.add(session); return session; } } @@ -125,22 +121,18 @@ public class SessionFactoryImpl extends RegistryImpl implements SessionFactory, @Override public Session create(InputStream in, PrintStream out, PrintStream err, Session parent) { - synchronized (sessions) { + synchronized (commandProcessor) { if (closed) { throw new IllegalStateException("SessionFactory has been closed"); } final Session session = new HeadlessSessionImpl(this, commandProcessor, in, out, err, parent); - sessions.add(session); return session; } } public void stop() { - synchronized (sessions) { + synchronized (commandProcessor) { closed = true; - for (Session session : sessions) { - session.close(); - } commandProcessor.stop(); } } -- 2.6.1