You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gg...@apache.org on 2017/06/08 14:17:46 UTC
[2/2] karaf git commit: [KARAF-5184] Make sure terminal is closed
even if ConsoleSession didn't run yet (with DelayedStarted)
[KARAF-5184] Make sure terminal is closed even if ConsoleSession didn't run yet (with DelayedStarted)
(cherry picked from commit a99b55a5d792809237a2220e57275cc1cfe05ee3)
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/b6aff5d2
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/b6aff5d2
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/b6aff5d2
Branch: refs/heads/karaf-4.1.x
Commit: b6aff5d25580644290b77c9869b2e4c1a34cf1c5
Parents: 673fc4c
Author: Grzegorz Grzybek <gr...@gmail.com>
Authored: Thu Jun 8 15:49:06 2017 +0200
Committer: Grzegorz Grzybek <gr...@gmail.com>
Committed: Thu Jun 8 16:16:59 2017 +0200
----------------------------------------------------------------------
.../shell/impl/console/ConsoleSessionImpl.java | 18 +++++++++------
.../shell/impl/console/osgi/DelayedStarted.java | 24 +++++++++++++-------
.../impl/console/osgi/LocalConsoleManager.java | 9 ++++++--
3 files changed, 34 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/b6aff5d2/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
index f0a8569..b500e9f 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
@@ -84,6 +84,8 @@ public class ConsoleSessionImpl implements Session {
// Input stream
volatile boolean running;
+ private AtomicBoolean closed = new AtomicBoolean(false);
+
final SessionFactory factory;
final ThreadIO threadIO;
final InputStream in;
@@ -272,11 +274,13 @@ public class ConsoleSessionImpl implements Session {
}
public void close() {
- if (running) {
- try {
- reader.getHistory().save();
- } catch (IOException e) {
- // ignore
+ if (closed.compareAndSet(false, true)) {
+ if (running) {
+ try {
+ reader.getHistory().save();
+ } catch (IOException e) {
+ // ignore
+ }
}
running = false;
@@ -293,9 +297,9 @@ public class ConsoleSessionImpl implements Session {
// Ignore
}
}
+ if (session != null)
+ session.close();
}
- if (session != null)
- session.close();
}
public void run() {
http://git-wip-us.apache.org/repos/asf/karaf/blob/b6aff5d2/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/DelayedStarted.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/DelayedStarted.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/DelayedStarted.java
index 0277e4e..0419171 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/DelayedStarted.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/DelayedStarted.java
@@ -31,10 +31,11 @@ import org.osgi.framework.startlevel.FrameworkStartLevel;
class DelayedStarted extends Thread implements FrameworkListener {
private static final String SYSTEM_PROP_KARAF_CONSOLE_STARTED = "karaf.console.started";
- private final AtomicBoolean started = new AtomicBoolean(false);
+ private final AtomicBoolean started = new AtomicBoolean(false);
+ private final AtomicBoolean stopped = new AtomicBoolean(false);
private final InputStream in;
- private final Runnable console;
- private final BundleContext bundleContext;
+ private final Runnable console;
+ private final BundleContext bundleContext;
DelayedStarted(Runnable console, String name, BundleContext bundleContext, InputStream in) {
super(name);
@@ -53,7 +54,7 @@ class DelayedStarted extends Thread implements FrameworkListener {
public void run() {
try {
- while (!started.get()) {
+ while (!started.get() && !stopped.get()) {
if (in.available() == 0) {
Thread.sleep(10);
}
@@ -69,10 +70,17 @@ class DelayedStarted extends Thread implements FrameworkListener {
// Ignore
}
- // Signal to the main module that it can stop displaying the startup progress
- System.setProperty(SYSTEM_PROP_KARAF_CONSOLE_STARTED, "true");
- this.bundleContext.removeFrameworkListener(this);
- console.run();
+
+ if (!stopped.get()) {
+ // Signal to the main module that it can stop displaying the startup progress
+ System.setProperty(SYSTEM_PROP_KARAF_CONSOLE_STARTED, "true");
+ this.bundleContext.removeFrameworkListener(this);
+ console.run();
+ }
+ }
+
+ public void stopDelayed() {
+ stopped.set(true);
}
public void frameworkEvent(FrameworkEvent event) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/b6aff5d2/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/LocalConsoleManager.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/LocalConsoleManager.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/LocalConsoleManager.java
index 8a307d0..5524338 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/LocalConsoleManager.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/LocalConsoleManager.java
@@ -50,6 +50,8 @@ public class LocalConsoleManager {
private ServiceRegistration<?> registration;
private boolean closing;
+ private DelayedStarted watcher;
+
public LocalConsoleManager(BundleContext bundleContext,
SessionFactory sessionFactory) throws Exception {
this.bundleContext = bundleContext;
@@ -77,8 +79,8 @@ public class LocalConsoleManager {
String name = "Karaf local console user " + ShellUtil.getCurrentUserName();
boolean delayconsole = Boolean.parseBoolean(System.getProperty(KARAF_DELAY_CONSOLE));
if (delayconsole) {
- DelayedStarted watcher = new DelayedStarted(session, name, bundleContext, System.in);
- new Thread(watcher).start();
+ watcher = new DelayedStarted(session, name, bundleContext, System.in);
+ new Thread(watcher, name).start();
} else {
new Thread(session, name).start();
}
@@ -154,6 +156,9 @@ public class LocalConsoleManager {
if (session != null) {
session.close();
}
+ if (watcher != null) {
+ watcher.stopDelayed();
+ }
}
protected void close() {