Implement proper return type for Framework.waitForStop(). (FELIX-1291)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@790181 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index cff6656..097e13b 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -788,15 +788,26 @@
// If there is a gate, wait on it; otherwise, return immediately.
// Grab a copy of the gate, since it is volatile.
ThreadGate gate = m_shutdownGate;
+ boolean open = false;
if (gate != null)
{
- gate.await(timeout);
+ open = gate.await(timeout);
}
- // TODO: RFC132 - We need to modify this to return the proper reason:
- // FrameEvent.STOPPED, FrameEvent.STOPPED_UPDATE,
- // FrameEvent.STOPPED_BOOTCLASSPATH_MODIFIED, FrameEvent.ERROR
- return new FrameworkEvent(FrameworkEvent.STOPPED, this, null);
+ FrameworkEvent event;
+ if (open && (gate.getMessage() != null))
+ {
+ event = (FrameworkEvent) gate.getMessage();
+ }
+ else if (!open && (gate != null))
+ {
+ event = new FrameworkEvent(FrameworkEvent.WAIT_TIMEDOUT, this, null);
+ }
+ else
+ {
+ event = new FrameworkEvent(FrameworkEvent.STOPPED, this, null);
+ }
+ return event;
}
public void uninstall() throws BundleException
@@ -837,6 +848,9 @@
{
// First acquire the system bundle lock to verify the state.
acquireBundleLock(Felix.this, Bundle.STARTING | Bundle.ACTIVE);
+ // Set the reason for the shutdown.
+ m_shutdownGate.setMessage(
+ new FrameworkEvent(FrameworkEvent.STOPPED_UPDATE, Felix.this, null));
// Record the state and stop the system bundle.
int oldState = Felix.this.getState();
try
diff --git a/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java b/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
index 158ee14..f9900a3 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
@@ -26,6 +26,8 @@
public class ThreadGate
{
private boolean m_open = false;
+ private Object m_msg = null;
+ private boolean m_initialized = false;
/**
* Open the gate and release any waiting threads.
@@ -37,11 +39,38 @@
}
/**
+ * Returns the message object associated with the gate; the
+ * message is just an arbitrary object used to pass information
+ * to the waiting threads.
+ * @return the message object associated with the gate.
+ **/
+ public synchronized Object getMessage()
+ {
+ return m_msg;
+ }
+
+ /**
+ * Sets the message object associated with the gate. The message
+ * object can only be set once, subsequent calls to this method
+ * are ignored.
+ * @param msg the message object to associate with this gate.
+ **/
+ public synchronized void setMessage(Object msg)
+ {
+ if (!m_initialized)
+ {
+ m_msg = msg;
+ m_initialized = true;
+ }
+ }
+
+ /**
* Wait for the gate to open.
+ * @return <tt>true</tt> if the gate was opened or <tt>false</tt> if the timeout expired.
* @throws java.lang.InterruptedException If the calling thread is interrupted;
* the gate still remains closed until opened.
**/
- public synchronized void await(long timeout) throws InterruptedException
+ public synchronized boolean await(long timeout) throws InterruptedException
{
long start = System.currentTimeMillis();
long remaining = timeout;
@@ -57,5 +86,6 @@
}
}
}
+ return m_open;
}
}
\ No newline at end of file