mirror of https://github.com/apache/activemq.git
Re-included the means to prevent the main thread from exiting until the vm is exited elsewhere (either Ctrl+C, terminateJVM, etc.)
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@365865 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
050637cdf6
commit
b70c8d1cb2
|
@ -111,9 +111,10 @@ public class Main {
|
||||||
QUERY_TYPE_ID_MAP.setProperty("Topic", "Destination");
|
QUERY_TYPE_ID_MAP.setProperty("Topic", "Destination");
|
||||||
};
|
};
|
||||||
|
|
||||||
private final ArrayList extensions = new ArrayList();
|
private final List brokers = new ArrayList();
|
||||||
private final Map queryObjects = new HashMap();
|
private final List extensions = new ArrayList();
|
||||||
private final List queryViews = new ArrayList();
|
private final Map queryObjects = new HashMap();
|
||||||
|
private final List queryViews = new ArrayList();
|
||||||
|
|
||||||
private int taskType = TASK_NONE;
|
private int taskType = TASK_NONE;
|
||||||
private boolean stopAll = false;
|
private boolean stopAll = false;
|
||||||
|
@ -444,6 +445,8 @@ public class Main {
|
||||||
this.startBroker(this.getConfigUri());
|
this.startBroker(this.getConfigUri());
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
waitForShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void taskStopBrokers(List brokerNames) throws Throwable {
|
protected void taskStopBrokers(List brokerNames) throws Throwable {
|
||||||
|
@ -649,6 +652,37 @@ public class Main {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void waitForShutdown() throws Throwable {
|
||||||
|
// Prevent the main thread from exiting, in case this is the last user thread
|
||||||
|
final boolean[] shutdown = new boolean[]{false};
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
|
public void run() {
|
||||||
|
synchronized(shutdown) {
|
||||||
|
shutdown[0]=true;
|
||||||
|
shutdown.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
synchronized(shutdown) {
|
||||||
|
while( !shutdown[0] ) {
|
||||||
|
shutdown.wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use reflection to stop the broker in case, the vm was exited via unconventional means
|
||||||
|
try {
|
||||||
|
for (Iterator i=brokers.iterator(); i.hasNext();) {
|
||||||
|
Object broker = i.next();
|
||||||
|
Method stop = broker.getClass().getMethod("stop", new Class[] {});
|
||||||
|
stop.invoke(broker, new Object[] {});
|
||||||
|
}
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
throw e.getCause();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void stopBroker(MBeanServerConnection server, String brokerName) {
|
public void stopBroker(MBeanServerConnection server, String brokerName) {
|
||||||
ObjectName brokerObjName = null;
|
ObjectName brokerObjName = null;
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue