You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by bo...@apache.org on 2015/09/10 21:57:37 UTC
[5/5] qpid-proton git commit: PROTON-980: Enable handler processing
the event after child handlers have processed it
PROTON-980: Enable handler processing the event after child handlers have processed it
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/c8c2775b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/c8c2775b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/c8c2775b
Branch: refs/heads/master
Commit: c8c2775b58e9a9be51c091cc56980cf344ce8cd1
Parents: 8f3a8f0
Author: Bozo Dragojevic <bo...@digiverse.si>
Authored: Mon Sep 7 17:28:13 2015 +0200
Committer: Bozo Dragojevic <bo...@digiverse.si>
Committed: Thu Sep 10 21:57:12 2015 +0200
----------------------------------------------------------------------
.../org/apache/qpid/proton/engine/Event.java | 11 +++++++
.../qpid/proton/engine/impl/EventImpl.java | 29 +++++++++++++----
.../qpid/proton/engine/EventDelegationTest.java | 33 ++++++++++++++++++++
.../proton/engine/EventExtensibilityTest.java | 5 +++
4 files changed, 72 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c8c2775b/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 9a1c69d..9e35565 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
@@ -129,6 +129,17 @@ public interface Event extends Extendable
*/
void redispatch(EventType as_type, Handler handler) throws HandlerException;
+ /**
+ * dispatch the event to all children of the handler. A handler can call
+ * this method explicitly to be able to do more processing after all child
+ * handlers have already processed the event. If handler does not invoke
+ * this method it is invoked implicitly by {@link #dispatch(Handler)}
+ *
+ * @param handler
+ * @throws HandlerException
+ */
+ void delegate() throws HandlerException;
+
Connection getConnection();
Session getSession();
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c8c2775b/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 e4cee5f..0ba1a55 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
@@ -88,21 +88,38 @@ class EventImpl implements Event
return context;
}
+ private Handler delegated = null;
+
@Override
- public void dispatch(Handler handler)
+ public void dispatch(Handler handler) throws HandlerException
{
+ Handler old_delegated = delegated;
try {
- handler.handle(this);
- } catch(RuntimeException runtimeException) {
- throw new HandlerException(handler, runtimeException);
+ delegated = handler;
+ try {
+ handler.handle(this);
+ } catch(RuntimeException runtimeException) {
+ throw new HandlerException(handler, runtimeException);
+ }
+ delegate();
+ } finally {
+ delegated = old_delegated;
}
+ }
- Iterator<Handler> children = handler.children();
+ @Override
+ public void delegate() throws HandlerException
+ {
+ if (delegated == null) {
+ return; // short circuit
+ }
+ Iterator<Handler> children = delegated.children();
+ delegated = null;
while(children.hasNext()) {
dispatch(children.next());
}
}
-
+
@Override
public void redispatch(EventType as_type, Handler handler) throws HandlerException
{
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c8c2775b/proton-j/src/test/java/org/apache/qpid/proton/engine/EventDelegationTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/EventDelegationTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/EventDelegationTest.java
index d8cce0a..a36f9cb 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/EventDelegationTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/engine/EventDelegationTest.java
@@ -25,6 +25,19 @@ public class EventDelegationTest {
}
}
+ class DelegatingFlowTracer extends ExecutionFlowTracer {
+ public DelegatingFlowTracer(String name) {
+ super(name);
+ }
+
+ @Override
+ public void onReactorInit(Event e) {
+ trace.add("(" + name);
+ e.delegate();
+ trace.add(name + ")");
+ }
+ }
+
Handler assemble(Handler outer, Handler...inner) {
for(Handler h : inner) {
outer.add(h);
@@ -52,4 +65,24 @@ public class EventDelegationTest {
assertArrayEquals(new String[]{"A", "A.A", "A.A.A", "A.A.B", "A.B"}, trace.toArray());
}
+ @Test
+ public void testExplicitDelegate() throws IOException {
+ Handler h =
+ assemble(
+ new ExecutionFlowTracer("A"),
+ assemble(
+ new DelegatingFlowTracer("A.A"),
+ new ExecutionFlowTracer("A.A.A"),
+ new ExecutionFlowTracer("A.A.B")
+ ),
+ assemble(
+ new ExecutionFlowTracer("A.B")
+ )
+ );
+ Reactor r = Reactor.Factory.create();
+ r.getHandler().add(h);
+ r.run();
+ assertArrayEquals(new String[]{"A", "(A.A", "A.A.A", "A.A.B", "A.A)", "A.B"}, trace.toArray());
+ }
+
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c8c2775b/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 2706bab..c35ac31 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
@@ -248,6 +248,11 @@ public class EventExtensibilityTest extends TestCase {
public Event copy() {
return new ExtraEventImpl(impl.copy());
}
+
+ @Override
+ public void delegate() throws HandlerException {
+ impl.delegate();
+ }
}
public class ExtendedTestEventGenerator extends BaseHandler {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org