You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2014/11/14 12:03:17 UTC
[08/50] [abbrv] qpid-proton git commit: added dispatch code to event
class
added dispatch code to event class
git-svn-id: https://svn.apache.org/repos/asf/qpid/proton/trunk@1631543 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/2c89949f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/2c89949f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/2c89949f
Branch: refs/heads/examples
Commit: 2c89949fe8b226900c1630f73b64d61bbd2100b9
Parents: 4e7e432
Author: Rafael H. Schloming <rh...@apache.org>
Authored: Mon Oct 13 20:50:58 2014 +0000
Committer: Rafael H. Schloming <rh...@apache.org>
Committed: Mon Oct 13 20:50:58 2014 +0000
----------------------------------------------------------------------
proton-c/bindings/python/proton.py | 263 ++++++++++++-------
.../apache/qpid/proton/engine/BaseHandler.java | 67 +++++
.../org/apache/qpid/proton/engine/Event.java | 2 +
.../org/apache/qpid/proton/engine/Handler.java | 67 +++++
.../qpid/proton/engine/impl/EventImpl.java | 97 +++++++
5 files changed, 406 insertions(+), 90 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2c89949f/proton-c/bindings/python/proton.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton.py b/proton-c/bindings/python/proton.py
index 4d2f3e4..5bca26c 100644
--- a/proton-c/bindings/python/proton.py
+++ b/proton-c/bindings/python/proton.py
@@ -2911,6 +2911,10 @@ class Delivery(object):
self._dlv = None
@property
+ def released(self):
+ return self._dlv is None
+
+ @property
def tag(self):
return pn_delivery_tag(self._dlv)
@@ -3364,7 +3368,7 @@ class Collector:
clazz = pn_class_name(pn_event_class(event))
context = wrappers[clazz](pn_event_context(event))
- return Event(clazz, context, pn_event_type(event))
+ return Event(clazz, context, EventType.TYPES[pn_event_type(event)])
def pop(self):
ev = self.peek()
@@ -3375,41 +3379,54 @@ class Collector:
def __del__(self):
pn_collector_free(self._impl)
+class EventType:
+
+ TYPES = {}
+
+ def __init__(self, number, method):
+ self.number = number
+ self.name = pn_event_type_name(self.number)
+ self.method = method
+ self.TYPES[number] = self
+
+ def __repr__(self):
+ return self.name
+
class Event:
- CONNECTION_INIT = PN_CONNECTION_INIT
- CONNECTION_BOUND = PN_CONNECTION_BOUND
- CONNECTION_UNBOUND = PN_CONNECTION_UNBOUND
- CONNECTION_LOCAL_OPEN = PN_CONNECTION_LOCAL_OPEN
- CONNECTION_LOCAL_CLOSE = PN_CONNECTION_LOCAL_CLOSE
- CONNECTION_REMOTE_OPEN = PN_CONNECTION_REMOTE_OPEN
- CONNECTION_REMOTE_CLOSE = PN_CONNECTION_REMOTE_CLOSE
- CONNECTION_FINAL = PN_CONNECTION_FINAL
-
- SESSION_INIT = PN_SESSION_INIT
- SESSION_LOCAL_OPEN = PN_SESSION_LOCAL_OPEN
- SESSION_LOCAL_CLOSE = PN_SESSION_LOCAL_CLOSE
- SESSION_REMOTE_OPEN = PN_SESSION_REMOTE_OPEN
- SESSION_REMOTE_CLOSE = PN_SESSION_REMOTE_CLOSE
- SESSION_FINAL = PN_SESSION_FINAL
-
- LINK_INIT = PN_LINK_INIT
- LINK_LOCAL_OPEN = PN_LINK_LOCAL_OPEN
- LINK_LOCAL_CLOSE = PN_LINK_LOCAL_CLOSE
- LINK_LOCAL_DETACH = PN_LINK_LOCAL_DETACH
- LINK_REMOTE_OPEN = PN_LINK_REMOTE_OPEN
- LINK_REMOTE_CLOSE = PN_LINK_REMOTE_CLOSE
- LINK_REMOTE_DETACH = PN_LINK_REMOTE_DETACH
- LINK_FLOW = PN_LINK_FLOW
- LINK_FINAL = PN_LINK_FINAL
-
- DELIVERY = PN_DELIVERY
-
- TRANSPORT = PN_TRANSPORT
- TRANSPORT_ERROR = PN_TRANSPORT_ERROR
- TRANSPORT_HEAD_CLOSED = PN_TRANSPORT_HEAD_CLOSED
- TRANSPORT_TAIL_CLOSED = PN_TRANSPORT_TAIL_CLOSED
- TRANSPORT_CLOSED = PN_TRANSPORT_CLOSED
+ CONNECTION_INIT = EventType(PN_CONNECTION_INIT, "on_connection_init")
+ CONNECTION_BOUND = EventType(PN_CONNECTION_BOUND, "on_connection_bound")
+ CONNECTION_UNBOUND = EventType(PN_CONNECTION_UNBOUND, "on_connection_unbound")
+ CONNECTION_LOCAL_OPEN = EventType(PN_CONNECTION_LOCAL_OPEN, "on_connection_local_open")
+ CONNECTION_LOCAL_CLOSE = EventType(PN_CONNECTION_LOCAL_CLOSE, "on_connection_local_close")
+ CONNECTION_REMOTE_OPEN = EventType(PN_CONNECTION_REMOTE_OPEN, "on_connection_remote_open")
+ CONNECTION_REMOTE_CLOSE = EventType(PN_CONNECTION_REMOTE_CLOSE, "on_connection_remote_close")
+ CONNECTION_FINAL = EventType(PN_CONNECTION_FINAL, "on_connection_final")
+
+ SESSION_INIT = EventType(PN_SESSION_INIT, "on_session_init")
+ SESSION_LOCAL_OPEN = EventType(PN_SESSION_LOCAL_OPEN, "on_session_local_open")
+ SESSION_LOCAL_CLOSE = EventType(PN_SESSION_LOCAL_CLOSE, "on_session_local_close")
+ SESSION_REMOTE_OPEN = EventType(PN_SESSION_REMOTE_OPEN, "on_session_remote_open")
+ SESSION_REMOTE_CLOSE = EventType(PN_SESSION_REMOTE_CLOSE, "on_session_remote_close")
+ SESSION_FINAL = EventType(PN_SESSION_FINAL, "on_session_final")
+
+ LINK_INIT = EventType(PN_LINK_INIT, "on_link_init")
+ LINK_LOCAL_OPEN = EventType(PN_LINK_LOCAL_OPEN, "on_link_local_open")
+ LINK_LOCAL_CLOSE = EventType(PN_LINK_LOCAL_CLOSE, "on_link_local_close")
+ LINK_LOCAL_DETACH = EventType(PN_LINK_LOCAL_DETACH, "on_link_local_detach")
+ LINK_REMOTE_OPEN = EventType(PN_LINK_REMOTE_OPEN, "on_link_remote_open")
+ LINK_REMOTE_CLOSE = EventType(PN_LINK_REMOTE_CLOSE, "on_link_remote_close")
+ LINK_REMOTE_DETACH = EventType(PN_LINK_REMOTE_DETACH, "on_link_remote_detach")
+ LINK_FLOW = EventType(PN_LINK_FLOW, "on_link_flow")
+ LINK_FINAL = EventType(PN_LINK_FINAL, "on_link_final")
+
+ DELIVERY = EventType(PN_DELIVERY, "on_delivery")
+
+ TRANSPORT = EventType(PN_TRANSPORT, "on_transport")
+ TRANSPORT_ERROR = EventType(PN_TRANSPORT_ERROR, "on_transport_error")
+ TRANSPORT_HEAD_CLOSED = EventType(PN_TRANSPORT_HEAD_CLOSED, "on_transport_head_closed")
+ TRANSPORT_TAIL_CLOSED = EventType(PN_TRANSPORT_TAIL_CLOSED, "on_transport_tail_closed")
+ TRANSPORT_CLOSED = EventType(PN_TRANSPORT_CLOSED, "on_transport_closed")
def __init__(self, clazz, context, type):
self.clazz = clazz
@@ -3422,8 +3439,73 @@ class Event:
collector._contexts.remove(self.context)
self.context._released()
+ def dispatch(self, handler):
+ getattr(handler, self.type.method, handler.on_unhandled)(self)
+
+ @property
+ def connection(self):
+ if self.clazz == "pn_connection":
+ return self.context
+ elif self.clazz == "pn_session":
+ return self.context.connection
+ elif self.clazz == "pn_link":
+ return self.context.connection
+ elif self.clazz == "pn_delivery" and not self.context.released:
+ return self.context.link.connection
+ else:
+ return None
+
+ @property
+ def session(self):
+ if self.clazz == "pn_session":
+ return self.context
+ elif self.clazz == "pn_link":
+ return self.context.session
+ elif self.clazz == "pn_delivery" and not self.context.released:
+ return self.context.link.session
+ else:
+ return None
+
+ @property
+ def link(self):
+ if self.clazz == "pn_link":
+ return self.context
+ elif self.clazz == "pn_delivery" and not self.context.released:
+ return self.context.link
+ else:
+ return None
+
+ @property
+ def sender(self):
+ l = self.link
+ if l and l.is_sender:
+ return l
+ else:
+ return None
+
+ @property
+ def receiver(self):
+ l = self.link
+ if l and l.is_receiver:
+ return l
+ else:
+ return None
+
+ @property
+ def delivery(self):
+ if self.clazz == "pn_delivery":
+ return self.context
+ else:
+ return None
+
def __repr__(self):
- return "%s(%s)" % (pn_event_type_name(self.type), self.context)
+ return "%s(%s)" % (self.type, self.context)
+
+class Handler:
+
+ def on_unhandled(self, event):
+ pass
+
###
# Driver
@@ -3617,61 +3699,6 @@ class Driver(object):
def pending_connector(self):
return Connector._wrap_connector(pn_driver_connector(self._driver))
-__all__ = [
- "API_LANGUAGE",
- "IMPLEMENTATION_LANGUAGE",
- "ABORTED",
- "ACCEPTED",
- "AUTOMATIC",
- "PENDING",
- "MANUAL",
- "REJECTED",
- "RELEASED",
- "SETTLED",
- "UNDESCRIBED",
- "Array",
- "Collector",
- "Condition",
- "Connection",
- "Connector",
- "Data",
- "Delivery",
- "Disposition",
- "Described",
- "Driver",
- "DriverException",
- "Endpoint",
- "Event",
- "Link",
- "Listener",
- "Message",
- "MessageException",
- "Messenger",
- "MessengerException",
- "ProtonException",
- "VERSION_MAJOR",
- "VERSION_MINOR",
- "Receiver",
- "SASL",
- "Sender",
- "Session",
- "SSL",
- "SSLDomain",
- "SSLSessionDetails",
- "SSLUnavailable",
- "SSLException",
- "Terminus",
- "Timeout",
- "Interrupt",
- "Transport",
- "TransportException",
- "char",
- "symbol",
- "timestamp",
- "ulong"
- ]
-
-
class Url(object):
"""
Simple URL parser/constructor, handles URLs of the form:
@@ -3777,3 +3804,59 @@ class Url(object):
self.host = self.host or '0.0.0.0'
self.port = self.port or self.Port(self.scheme)
return self
+
+__all__ = [
+ "API_LANGUAGE",
+ "IMPLEMENTATION_LANGUAGE",
+ "ABORTED",
+ "ACCEPTED",
+ "AUTOMATIC",
+ "PENDING",
+ "MANUAL",
+ "REJECTED",
+ "RELEASED",
+ "SETTLED",
+ "UNDESCRIBED",
+ "Array",
+ "Collector",
+ "Condition",
+ "Connection",
+ "Connector",
+ "Data",
+ "Delivery",
+ "Disposition",
+ "Described",
+ "Driver",
+ "DriverException",
+ "Endpoint",
+ "Event",
+ "Handler",
+ "Link",
+ "Listener",
+ "Message",
+ "MessageException",
+ "Messenger",
+ "MessengerException",
+ "ProtonException",
+ "VERSION_MAJOR",
+ "VERSION_MINOR",
+ "Receiver",
+ "SASL",
+ "Sender",
+ "Session",
+ "SSL",
+ "SSLDomain",
+ "SSLSessionDetails",
+ "SSLUnavailable",
+ "SSLException",
+ "Terminus",
+ "Timeout",
+ "Interrupt",
+ "Transport",
+ "TransportException",
+ "Url",
+ "char",
+ "symbol",
+ "timestamp",
+ "ulong"
+ ]
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2c89949f/proton-j/src/main/java/org/apache/qpid/proton/engine/BaseHandler.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/BaseHandler.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/BaseHandler.java
new file mode 100644
index 0000000..94f4d12
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/BaseHandler.java
@@ -0,0 +1,67 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.proton.engine;
+
+
+/**
+ * BaseHandler
+ *
+ */
+
+public class BaseHandler implements Handler
+{
+
+ @Override public void onConnectionInit(Event e) { onUnhandled(e); }
+ @Override public void onConnectionLocalOpen(Event e) { onUnhandled(e); }
+ @Override public void onConnectionRemoteOpen(Event e) { onUnhandled(e); }
+ @Override public void onConnectionLocalClose(Event e) { onUnhandled(e); }
+ @Override public void onConnectionRemoteClose(Event e) { onUnhandled(e); }
+ @Override public void onConnectionBound(Event e) { onUnhandled(e); }
+ @Override public void onConnectionUnbound(Event e) { onUnhandled(e); }
+ @Override public void onConnectionFinal(Event e) { onUnhandled(e); }
+
+ @Override public void onSessionInit(Event e) { onUnhandled(e); }
+ @Override public void onSessionLocalOpen(Event e) { onUnhandled(e); }
+ @Override public void onSessionRemoteOpen(Event e) { onUnhandled(e); }
+ @Override public void onSessionLocalClose(Event e) { onUnhandled(e); }
+ @Override public void onSessionRemoteClose(Event e) { onUnhandled(e); }
+ @Override public void onSessionFinal(Event e) { onUnhandled(e); }
+
+ @Override public void onLinkInit(Event e) { onUnhandled(e); }
+ @Override public void onLinkLocalOpen(Event e) { onUnhandled(e); }
+ @Override public void onLinkRemoteOpen(Event e) { onUnhandled(e); }
+ @Override public void onLinkLocalDetach(Event e) { onUnhandled(e); }
+ @Override public void onLinkRemoteDetach(Event e) { onUnhandled(e); }
+ @Override public void onLinkLocalClose(Event e) { onUnhandled(e); }
+ @Override public void onLinkRemoteClose(Event e) { onUnhandled(e); }
+ @Override public void onLinkFlow(Event e) { onUnhandled(e); }
+ @Override public void onLinkFinal(Event e) { onUnhandled(e); }
+
+ @Override public void onDelivery(Event e) { onUnhandled(e); }
+ @Override public void onTransport(Event e) { onUnhandled(e); }
+ @Override public void onTransportError(Event e) { onUnhandled(e); }
+ @Override public void onTransportHeadClosed(Event e) { onUnhandled(e); }
+ @Override public void onTransportTailClosed(Event e) { onUnhandled(e); }
+ @Override public void onTransportClosed(Event e) { onUnhandled(e); }
+
+ @Override public void onUnhandled(Event event) {}
+
+}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2c89949f/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 3ffd414..3b299a6 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
@@ -69,6 +69,8 @@ public interface Event
Object getContext();
+ void dispatch(Handler handler);
+
Connection getConnection();
Session getSession();
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2c89949f/proton-j/src/main/java/org/apache/qpid/proton/engine/Handler.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Handler.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/Handler.java
new file mode 100644
index 0000000..5ff77e0
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Handler.java
@@ -0,0 +1,67 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.proton.engine;
+
+
+/**
+ * Handler
+ *
+ */
+
+public interface Handler
+{
+
+ void onConnectionInit(Event e);
+ void onConnectionLocalOpen(Event e);
+ void onConnectionRemoteOpen(Event e);
+ void onConnectionLocalClose(Event e);
+ void onConnectionRemoteClose(Event e);
+ void onConnectionBound(Event e);
+ void onConnectionUnbound(Event e);
+ void onConnectionFinal(Event e);
+
+ void onSessionInit(Event e);
+ void onSessionLocalOpen(Event e);
+ void onSessionRemoteOpen(Event e);
+ void onSessionLocalClose(Event e);
+ void onSessionRemoteClose(Event e);
+ void onSessionFinal(Event e);
+
+ void onLinkInit(Event e);
+ void onLinkLocalOpen(Event e);
+ void onLinkRemoteOpen(Event e);
+ void onLinkLocalDetach(Event e);
+ void onLinkRemoteDetach(Event e);
+ void onLinkLocalClose(Event e);
+ void onLinkRemoteClose(Event e);
+ void onLinkFlow(Event e);
+ void onLinkFinal(Event e);
+
+ void onDelivery(Event e);
+ void onTransport(Event e);
+ void onTransportError(Event e);
+ void onTransportHeadClosed(Event e);
+ void onTransportTailClosed(Event e);
+ void onTransportClosed(Event e);
+
+ void onUnhandled(Event e);
+
+}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/2c89949f/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 60d6dfe..3317bf9 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
@@ -21,6 +21,7 @@
package org.apache.qpid.proton.engine.impl;
import org.apache.qpid.proton.engine.Event;
+import org.apache.qpid.proton.engine.Handler;
import org.apache.qpid.proton.engine.Connection;
import org.apache.qpid.proton.engine.Session;
import org.apache.qpid.proton.engine.Link;
@@ -66,6 +67,102 @@ class EventImpl implements Event
return context;
}
+ public void dispatch(Handler handler)
+ {
+ switch (type) {
+ case CONNECTION_INIT:
+ handler.onConnectionInit(this);
+ break;
+ case CONNECTION_LOCAL_OPEN:
+ handler.onConnectionLocalOpen(this);
+ break;
+ case CONNECTION_REMOTE_OPEN:
+ handler.onConnectionRemoteOpen(this);
+ break;
+ case CONNECTION_LOCAL_CLOSE:
+ handler.onConnectionLocalClose(this);
+ break;
+ case CONNECTION_REMOTE_CLOSE:
+ handler.onConnectionRemoteClose(this);
+ break;
+ case CONNECTION_BOUND:
+ handler.onConnectionBound(this);
+ break;
+ case CONNECTION_UNBOUND:
+ handler.onConnectionUnbound(this);
+ break;
+ case CONNECTION_FINAL:
+ handler.onConnectionFinal(this);
+ break;
+ case SESSION_INIT:
+ handler.onSessionInit(this);
+ break;
+ case SESSION_LOCAL_OPEN:
+ handler.onSessionLocalOpen(this);
+ break;
+ case SESSION_REMOTE_OPEN:
+ handler.onSessionRemoteOpen(this);
+ break;
+ case SESSION_LOCAL_CLOSE:
+ handler.onSessionLocalClose(this);
+ break;
+ case SESSION_REMOTE_CLOSE:
+ handler.onSessionRemoteClose(this);
+ break;
+ case SESSION_FINAL:
+ handler.onSessionFinal(this);
+ break;
+ case LINK_INIT:
+ handler.onLinkInit(this);
+ break;
+ case LINK_LOCAL_OPEN:
+ handler.onLinkLocalOpen(this);
+ break;
+ case LINK_REMOTE_OPEN:
+ handler.onLinkRemoteOpen(this);
+ break;
+ case LINK_LOCAL_DETACH:
+ handler.onLinkLocalDetach(this);
+ break;
+ case LINK_REMOTE_DETACH:
+ handler.onLinkRemoteDetach(this);
+ break;
+ case LINK_LOCAL_CLOSE:
+ handler.onLinkLocalClose(this);
+ break;
+ case LINK_REMOTE_CLOSE:
+ handler.onLinkRemoteClose(this);
+ break;
+ case LINK_FLOW:
+ handler.onLinkFlow(this);
+ break;
+ case LINK_FINAL:
+ handler.onLinkFinal(this);
+ break;
+ case DELIVERY:
+ handler.onDelivery(this);
+ break;
+ case TRANSPORT:
+ handler.onTransport(this);
+ break;
+ case TRANSPORT_ERROR:
+ handler.onTransportError(this);
+ break;
+ case TRANSPORT_HEAD_CLOSED:
+ handler.onTransportHeadClosed(this);
+ break;
+ case TRANSPORT_TAIL_CLOSED:
+ handler.onTransportTailClosed(this);
+ break;
+ case TRANSPORT_CLOSED:
+ handler.onTransportClosed(this);
+ break;
+ default:
+ handler.onUnhandled(this);
+ break;
+ }
+ }
+
public Connection getConnection()
{
if (context instanceof Connection) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org