You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2009/08/10 01:26:39 UTC

svn commit: r802626 - /qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java

Author: ritchiem
Date: Sun Aug  9 23:26:38 2009
New Revision: 802626

URL: http://svn.apache.org/viewvc?rev=802626&view=rev
Log:
Removed Java 6 dependency on Deque. Used Stack instead.

Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java?rev=802626&r1=802625&r2=802626&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java Sun Aug  9 23:26:38 2009
@@ -22,8 +22,8 @@
 
 import org.apache.qpid.server.logging.LogActor;
 
-import java.util.LinkedList;
-import java.util.Deque;
+import java.util.EmptyStackException;
+import java.util.Stack;
 
 /**
  * The CurrentActor is a ThreadLocal wrapper that allows threads in the broker
@@ -31,78 +31,81 @@
  * reasons:
  * 1) We do not have to pass a logging actor around the system
  * 2) We can set new actors at the point we have enough information. i.e.
- *  - Set a low level ConnectionActor when processing bytes from the wire.
- *  - Set a ChannelActor when we are processing the frame
- *  - Set a SubscriptionActor when we are handling the subscription.
- *
+ * - Set a low level ConnectionActor when processing bytes from the wire.
+ * - Set a ChannelActor when we are processing the frame
+ * - Set a SubscriptionActor when we are handling the subscription.
+ * <p/>
  * The code performing the logging need not worry about what type of actor is
  * currently set so can perform its logging. The resulting log entry though will
  * contain customised details from the the currently set Actor.
- *
+ * <p/>
  * The Actor model also allows the pre-creation of fixed messages so the
  * performance impact of the additional logging data is minimised.
- *
+ * <p/>
  * This class does not perform any checks to ensure that there is an Actor set
  * when calling remove or get. As a result the application developer must ensure
  * that they have called set before they attempt to use the actor via get or
  * remove the set actor.
- *
+ * <p/>
  * The checking of the return via get should not be done as the logging is
  * desired. It is preferable to cause the NullPointerException to highlight the
  * programming error rather than miss a log message.
- *
+ * <p/>
  * The same is true for the remove. A NPE will occur if no set has been called
  * highlighting the programming error.
- * 
  */
 public class CurrentActor
 {
-    /**
-     * The ThreadLocal variable with initialiser
-     */
-    private static final ThreadLocal<Deque<LogActor>> _currentActor = new ThreadLocal<Deque<LogActor>>()
+    /** The ThreadLocal variable with initialiser */
+    private static final ThreadLocal<Stack<LogActor>> _currentActor = new ThreadLocal<Stack<LogActor>>()
     {
         // Initialise the CurrentActor to be an empty List
-        protected Deque<LogActor> initialValue()
+        protected Stack<LogActor> initialValue()
         {
-            return new LinkedList<LogActor>();
+            return new Stack<LogActor>();
         }
     };
 
     /**
      * Set a new LogActor to be the Current Actor
-     *
+     * <p/>
      * This pushes the Actor in to the LIFO Queue
      *
      * @param actor The new LogActor
      */
     public static void set(LogActor actor)
     {
-        Deque<LogActor> stack = _currentActor.get();
-        stack.addFirst(actor);
+        Stack<LogActor> stack = _currentActor.get();
+        stack.push(actor);
     }
 
     /**
      * Remove the current LogActor.
-     *
-     * Calling remove without calling set will result in a NoSuchElementException.
-     *
+     * <p/>
+     * Calling remove without calling set will result in an EmptyStackException.
      */
     public static void remove()
     {
-        Deque<LogActor> stack = _currentActor.get();
-        stack.removeFirst();
+        Stack<LogActor> stack = _currentActor.get();
+        stack.pop();
     }
 
     /**
      * Return the current head of the list of LogActors.
-     *
+     * <p/>
      * If there has been no set call then this will return Null.
      *
      * @return Current LogActor
      */
     public static LogActor get()
     {
-        return _currentActor.get().peek();
+        try
+        {
+            return _currentActor.get().peek();
+        }
+        catch (EmptyStackException ese)
+        {
+            return null;
+        }
     }
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org