[
https://issues.apache.org/jira/browse/PROTON-964?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14653499#comment-14653499
]
ASF GitHub Bot commented on PROTON-964:
---------------------------------------
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)
> Proton-J extensible event types
> -------------------------------
>
> Key: PROTON-964
> URL: https://issues.apache.org/jira/browse/PROTON-964
> Project: Qpid Proton
> Issue Type: Improvement
> Components: proton-j
> Affects Versions: 0.10
> Reporter: Bozo Dragojevic
> Assignee: Bozo Dragojevic
> Fix For: 0.11
>
>
> Event.Type is an enum which makes it impossible to extend.
> Introduce a separate interface EventType and make Event.Type implement it.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)