felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r790181 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: Felix.java util/ThreadGate.java
Date Wed, 01 Jul 2009 14:22:41 GMT
Author: rickhall
Date: Wed Jul  1 14:22:41 2009
New Revision: 790181

URL: http://svn.apache.org/viewvc?rev=790181&view=rev
Log:
Implement proper return type for Framework.waitForStop(). (FELIX-1291)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=790181&r1=790180&r2=790181&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Wed Jul  1 14:22:41
2009
@@ -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

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java?rev=790181&r1=790180&r2=790181&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ThreadGate.java Wed
Jul  1 14:22:41 2009
@@ -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



Mime
View raw message