Github user gemmellr commented on a diff in the pull request:
https://github.com/apache/qpid-proton/pull/48#discussion_r36179361
--- Diff:
proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java
---
@@ -0,0 +1,381 @@
+package org.apache.qpid.proton.engine;
+
+import java.io.IOException;
+
+import org.apache.qpid.proton.engine.Event.Type;
+import org.apache.qpid.proton.reactor.Reactor;
+import org.apache.qpid.proton.reactor.Selectable;
+import org.apache.qpid.proton.reactor.Task;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class EventExtensibilityTest extends TestCase {
+
+ // //////////////
+ // / Extra package public API classes
+ // //////////////
+
+ /**
+ * Sample additional information that gets generated and passed around
with
+ * the extension events. The information is stored inside
+ * {@link Event#attachments()} see {@link
ExtraEventImpl#getExtraInfo()}
+ */
+ public static class ExtraInfo {
+ public int foo;
+ }
+
+ /**
+ * Additional events generated by this extension.
+ *
+ * @author bozzo
+ *
+ */
+ public interface ExtraEvent extends Event {
+ /**
+ * Enum is a convenient mechanism for defining new event types
+ */
+ public enum ExtraTypes implements EventType {
+ FOO, BAR, NOT_A_EXTRA_EVENT;
+ ;
+
+ /**
+ * The actual implementation of the dispatch can be moved out
of
+ * line
+ */
+ @Override
+ public void dispatch(Event e, Handler h) {
+ ExtraEventTypeImpl.dispatch(this, e, h);
+ }
+
+ @Override
+ public boolean isValid() {
+ return this != NOT_A_EXTRA_EVENT;
+ }
+ }
+
+ /**
+ * typesafe access to event type generated by this extension
useful for
+ * handling in switch statements
+ *
+ * @return one of enum values. When invoked on an Event that is
not an
+ * ExtraEvent the return value shall be
+ */
+ ExtraTypes getExtraEventType();
+
+ /**
+ * typesafe access to extra information attached to additional
events
+ */
+ ExtraInfo getExtraInfo();
+ }
+
+ /**
+ * New handler methods for handling the extended event types. These
methods
+ * can take {@link ExtraEvent} as a parameter to get typesafe access to
+ * {@link ExtraInfo}
+ *
+ * The interface needs to extend the {@link Handler} interface.
+ */
+ public interface ExtraHandler extends Handler {
+ void onFoo(ExtraEvent e);
+
+ void onBar(ExtraEvent e);
+ }
+
+ /**
+ * Implementation of the default base class for ExtraHandler. All
events
+ * should be forwarded to the {@link Handler#onUnhandled(Event)} method
+ */
+ public static class ExtraBaseHandler extends BaseHandler implements
ExtraHandler {
+
+ @Override
+ public void onFoo(ExtraEvent e) {
+ this.onUnhandled(e);
+ }
+
+ @Override
+ public void onBar(ExtraEvent e) {
+ this.onUnhandled(e);
+ }
+
+ }
+
+ // //////////////
+ // / Extra package implementation classes
+ // //////////////
+
+ public static class ExtraEventTypeImpl {
+ /**
+ * Implementation of dispatch method for this extension
+ *
+ * @param type
+ * The implementation should accept only it's own
+ * {@link EventType} instances
+ * @param handler
--- End diff --
Forgot to comment earlier. The javadoc params dont match the method
signature.
(I know, only a test, but we have more than enough javadoc warnings/errors
already :P)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---