NO-JIRA: Add Event.getRootHandler()

Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/3cb935f1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/3cb935f1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/3cb935f1

Branch: refs/heads/proton-go
Commit: 3cb935f1c8523a9065665eb386a1c04d47b5397e
Parents: 7de6a18
Author: Bozo Dragojevic <[email protected]>
Authored: Wed Sep 23 19:55:12 2015 +0200
Committer: Bozo Dragojevic <[email protected]>
Committed: Wed Sep 23 20:04:03 2015 +0200

----------------------------------------------------------------------
 .../java/org/apache/qpid/proton/engine/Event.java    | 15 +++++++++++++--
 .../apache/qpid/proton/engine/impl/EventImpl.java    |  6 ++++++
 .../apache/qpid/proton/reactor/impl/ReactorImpl.java | 11 +++++++++--
 .../qpid/proton/engine/EventExtensibilityTest.java   |  4 ++++
 4 files changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3cb935f1/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java 
b/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java
index 3929ba5..1fd2f4c 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Event.java
@@ -116,15 +116,26 @@ public interface Event extends Extendable
 
     Object getContext();
 
+    /**
+     * The {@link Handler} at the root of the handler tree.
+     * <p>
+     * Set by the {@link Reactor} before dispatching the event.
+     * <p>
+     * @see #redispatch(EventType, Handler)
+     * @return The root handler
+     */
+    Handler getRootHandler();
+
     void dispatch(Handler handler) throws HandlerException;
 
     /**
      * Synchronously redispatch the current event as a new {@link EventType} 
on the provided handler and it's children.
      * <p>
-     * Note: the redispatch will happen before children of the current handler 
have had the current event dispatched.
+     * Note: the <code>redispatch()</code> will complete before children of 
the current handler have had the current event dispatched, see {@link 
#delegate()}.
+     *
      *
      * @param as_type Type of event to dispatch
-     * @param handler The handler where to start the dispatch
+     * @param handler The handler where to start the dispatch. Use {@link 
#getRootHandler()} to redispatch the new event to all handlers in the tree.
      * @throws HandlerException A wrapper exception of any unhandled exception 
thrown by <code>handler</code>
      */
     void redispatch(EventType as_type, Handler handler) throws 
HandlerException;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3cb935f1/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EventImpl.java
----------------------------------------------------------------------
diff --git 
a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EventImpl.java 
b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EventImpl.java
index 98d9265..40f2669 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EventImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EventImpl.java
@@ -37,6 +37,7 @@ import org.apache.qpid.proton.engine.Transport;
 import org.apache.qpid.proton.reactor.Reactor;
 import org.apache.qpid.proton.reactor.Selectable;
 import org.apache.qpid.proton.reactor.Task;
+import org.apache.qpid.proton.reactor.impl.ReactorImpl;
 
 /**
  * EventImpl
@@ -90,6 +91,11 @@ class EventImpl implements Event
         return context;
     }
 
+    @Override
+    public Handler getRootHandler() {
+        return ReactorImpl.ROOT.get(this);
+    }
+
     private Handler delegated = null;
 
     @Override

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3cb935f1/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java
----------------------------------------------------------------------
diff --git 
a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java 
b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java
index 8335ea7..0d5c429 100644
--- 
a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java
+++ 
b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java
@@ -36,6 +36,7 @@ import org.apache.qpid.proton.engine.Event;
 import org.apache.qpid.proton.engine.Event.Type;
 import org.apache.qpid.proton.engine.EventType;
 import org.apache.qpid.proton.engine.Extendable;
+import org.apache.qpid.proton.engine.ExtendableAccessor;
 import org.apache.qpid.proton.engine.Handler;
 import org.apache.qpid.proton.engine.HandlerException;
 import org.apache.qpid.proton.engine.Record;
@@ -51,6 +52,7 @@ import org.apache.qpid.proton.reactor.Selector;
 import org.apache.qpid.proton.reactor.Task;
 
 public class ReactorImpl implements Reactor, Extendable {
+    public static final ExtendableAccessor<Event, Handler> ROOT = new 
ExtendableAccessor<>(Handler.class);
 
     private CollectorImpl collector;
     private long now;
@@ -267,8 +269,8 @@ public class ReactorImpl implements Reactor, Extendable {
                     return true;
                 }
                 Handler handler = eventHandler(event);
-                event.dispatch(handler);
-                event.dispatch(global);
+                dispatch(event, handler);
+                dispatch(event, global);
 
                 if (event.getEventType() == Type.CONNECTION_FINAL) {
                     children.remove(event.getConnection());
@@ -297,6 +299,11 @@ public class ReactorImpl implements Reactor, Extendable {
         }
     }
 
+    private void dispatch(Event event, Handler handler) {
+        ROOT.set(event, handler);
+        event.dispatch(handler);
+    }
+
     @Override
     public void wakeup() {
         try {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3cb935f1/proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java
----------------------------------------------------------------------
diff --git 
a/proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java
 
b/proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java
index 53a247b..230788f 100644
--- 
a/proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java
+++ 
b/proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java
@@ -195,6 +195,10 @@ public class EventExtensibilityTest extends TestCase {
             return impl.getContext();
         }
 
+        public Handler getRootHandler() {
+            return impl.getRootHandler();
+        }
+
         public void dispatch(Handler handler) throws HandlerException {
             impl.dispatch(handler);
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to