You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2015/07/06 01:45:22 UTC
[21/38] qpid-proton git commit: PROTON-881: added Record attachments
in favor of modifying endpoints to know about handlers
PROTON-881: added Record attachments in favor of modifying endpoints to know about handlers
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/f8703333
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/f8703333
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/f8703333
Branch: refs/heads/master
Commit: f870333338b5ad62aef6867855f98fee08cca974
Parents: 06c451f
Author: Rafael Schloming <rh...@alum.mit.edu>
Authored: Thu May 7 11:23:15 2015 -0400
Committer: Rafael Schloming <rh...@alum.mit.edu>
Committed: Thu May 7 11:23:15 2015 -0400
----------------------------------------------------------------------
.../apache/qpid/proton/engine/Connection.java | 2 +-
.../org/apache/qpid/proton/engine/Endpoint.java | 3 ++
.../qpid/proton/engine/HandlerEndpoint.java | 28 ------------
.../org/apache/qpid/proton/engine/Link.java | 2 +-
.../org/apache/qpid/proton/engine/Record.java | 35 +++++++++++++++
.../org/apache/qpid/proton/engine/Session.java | 2 +-
.../qpid/proton/engine/impl/ConnectionImpl.java | 2 +-
.../qpid/proton/engine/impl/EndpointImpl.java | 7 +++
.../proton/engine/impl/HandlerEndpointImpl.java | 44 -------------------
.../qpid/proton/engine/impl/LinkImpl.java | 2 +-
.../qpid/proton/engine/impl/RecordImpl.java | 46 ++++++++++++++++++++
.../qpid/proton/engine/impl/SessionImpl.java | 2 +-
.../org/apache/qpid/proton/reactor/Reactor.java | 4 +-
.../qpid/proton/reactor/impl/ReactorImpl.java | 32 ++++++++------
14 files changed, 117 insertions(+), 94 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/Connection.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Connection.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/Connection.java
index 3dccbb1..feff80b 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/Connection.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Connection.java
@@ -37,7 +37,7 @@ import org.apache.qpid.proton.reactor.ReactorChild;
* {@link #sessionHead(EnumSet, EnumSet)}, {@link #linkHead(EnumSet, EnumSet)}
* {@link #getWorkHead()} respectively.
*/
-public interface Connection extends HandlerEndpoint, ReactorChild
+public interface Connection extends Endpoint, ReactorChild
{
public static final class Factory
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/Endpoint.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Endpoint.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/Endpoint.java
index a4a810c..021a001 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/Endpoint.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Endpoint.java
@@ -76,4 +76,7 @@ public interface Endpoint
* @see #setContext(Object)
*/
public Object getContext();
+
+ Record attachments();
+
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/HandlerEndpoint.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/HandlerEndpoint.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/HandlerEndpoint.java
deleted file mode 100644
index ecadc0a..0000000
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/HandlerEndpoint.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *
- * 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;
-
-public interface HandlerEndpoint extends Endpoint {
-
- void add(Handler handler);
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/Link.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Link.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/Link.java
index caafc14..9d05d03 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/Link.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Link.java
@@ -37,7 +37,7 @@ import org.apache.qpid.proton.amqp.transport.Target;
*
* TODO describe the application's responsibility to honour settlement.
*/
-public interface Link extends HandlerEndpoint
+public interface Link extends Endpoint
{
/**
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/Record.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Record.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/Record.java
new file mode 100644
index 0000000..1496449
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Record.java
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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;
+
+
+/**
+ * Record
+ *
+ */
+
+public interface Record
+{
+
+ <T> T get(Object key, Class<T> klass);
+ <T> void set(Object key, Class<T> klass, T value);
+
+}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/Session.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Session.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/Session.java
index eaddac0..f2f048a 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/Session.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Session.java
@@ -28,7 +28,7 @@ import java.util.EnumSet;
*
* Note that session level flow control is handled internally by Proton.
*/
-public interface Session extends HandlerEndpoint
+public interface Session extends Endpoint
{
/**
* Returns a newly created sender endpoint
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ConnectionImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ConnectionImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ConnectionImpl.java
index b018a95..e018d14 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ConnectionImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ConnectionImpl.java
@@ -36,7 +36,7 @@ import org.apache.qpid.proton.engine.ProtonJConnection;
import org.apache.qpid.proton.engine.Session;
import org.apache.qpid.proton.reactor.Reactor;
-public class ConnectionImpl extends HandlerEndpointImpl implements ProtonJConnection
+public class ConnectionImpl extends EndpointImpl implements ProtonJConnection
{
public static final int MAX_CHANNELS = 65535;
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EndpointImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EndpointImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EndpointImpl.java
index b97793a..8b143d6 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EndpointImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/EndpointImpl.java
@@ -25,6 +25,7 @@ import org.apache.qpid.proton.amqp.transport.ErrorCondition;
import org.apache.qpid.proton.engine.EndpointState;
import org.apache.qpid.proton.engine.Event;
import org.apache.qpid.proton.engine.ProtonJEndpoint;
+import org.apache.qpid.proton.engine.Record;
public abstract class EndpointImpl implements ProtonJEndpoint
{
@@ -36,6 +37,7 @@ public abstract class EndpointImpl implements ProtonJEndpoint
private EndpointImpl _transportNext;
private EndpointImpl _transportPrev;
private Object _context;
+ private Record _attachments = new RecordImpl();
private int refcount = 1;
boolean freed = false;
@@ -213,4 +215,9 @@ public abstract class EndpointImpl implements ProtonJEndpoint
_context = context;
}
+ public Record attachments()
+ {
+ return _attachments;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/HandlerEndpointImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/HandlerEndpointImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/HandlerEndpointImpl.java
deleted file mode 100644
index a108412..0000000
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/HandlerEndpointImpl.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *
- * 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.impl;
-
-import org.apache.qpid.proton.engine.BaseHandler;
-import org.apache.qpid.proton.engine.Handler;
-import org.apache.qpid.proton.engine.HandlerEndpoint;
-
-
-public abstract class HandlerEndpointImpl extends EndpointImpl implements HandlerEndpoint {
-
- private Handler handler = null;
-
- @Override
- public void add(Handler handler) {
- if (this.handler == null) {
- this.handler = new BaseHandler();
- }
- this.handler.add(handler);
- }
-
- public Handler getHandler() {
- return handler;
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/LinkImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/LinkImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/LinkImpl.java
index af92fb8..5dd6264 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/LinkImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/LinkImpl.java
@@ -30,7 +30,7 @@ import org.apache.qpid.proton.engine.EndpointState;
import org.apache.qpid.proton.engine.Event;
import org.apache.qpid.proton.engine.Link;
-public abstract class LinkImpl extends HandlerEndpointImpl implements Link
+public abstract class LinkImpl extends EndpointImpl implements Link
{
private final SessionImpl _session;
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/RecordImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/RecordImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/RecordImpl.java
new file mode 100644
index 0000000..849e694
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/RecordImpl.java
@@ -0,0 +1,46 @@
+/*
+ *
+ * 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.impl;
+
+import org.apache.qpid.proton.engine.Record;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * RecordImpl
+ *
+ */
+
+public class RecordImpl implements Record
+{
+
+ private Map<Object,Object> values = new HashMap<Object,Object>();
+
+ public <T> void set(Object key, Class<T> klass, T value) {
+ values.put(key, value);
+ }
+
+ public <T> T get(Object key, Class<T> klass) {
+ return klass.cast(values.get(key));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SessionImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SessionImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SessionImpl.java
index 9969b93..3af1820 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SessionImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SessionImpl.java
@@ -31,7 +31,7 @@ import org.apache.qpid.proton.engine.Event;
import org.apache.qpid.proton.engine.ProtonJSession;
import org.apache.qpid.proton.engine.Session;
-public class SessionImpl extends HandlerEndpointImpl implements ProtonJSession
+public class SessionImpl extends EndpointImpl implements ProtonJSession
{
private final ConnectionImpl _connection;
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java b/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java
index f91f376..5756b34 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java
@@ -27,6 +27,7 @@ import java.util.Set;
import org.apache.qpid.proton.engine.Collector;
import org.apache.qpid.proton.engine.Connection;
import org.apache.qpid.proton.engine.Handler;
+import org.apache.qpid.proton.engine.Record;
import org.apache.qpid.proton.reactor.impl.ReactorImpl;
@@ -42,8 +43,7 @@ public interface Reactor {
public long mark();
public long now();
- public void attach(Object attachment);
- public Object attachment();
+ public Record attachments();
public long getTimeout();
public void setTimeout(long timeout);
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f8703333/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 c2c30ef..a5a39d6 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
@@ -34,9 +34,10 @@ import org.apache.qpid.proton.engine.Connection;
import org.apache.qpid.proton.engine.Event;
import org.apache.qpid.proton.engine.Event.Type;
import org.apache.qpid.proton.engine.Handler;
+import org.apache.qpid.proton.engine.Record;
import org.apache.qpid.proton.engine.impl.CollectorImpl;
import org.apache.qpid.proton.engine.impl.ConnectionImpl;
-import org.apache.qpid.proton.engine.impl.HandlerEndpointImpl;
+import org.apache.qpid.proton.engine.impl.RecordImpl;
import org.apache.qpid.proton.reactor.Acceptor;
import org.apache.qpid.proton.reactor.Reactor;
import org.apache.qpid.proton.reactor.ReactorChild;
@@ -47,7 +48,6 @@ import org.apache.qpid.proton.reactor.Task;
public class ReactorImpl implements Reactor {
- private Object attachment;
private CollectorImpl collector;
private long now;
private long timeout;
@@ -61,6 +61,7 @@ public class ReactorImpl implements Reactor {
private Timer timer;
private final Pipe wakeup;
private Selector selector;
+ private Record attachments;
@Override
public long mark() {
@@ -82,6 +83,7 @@ public class ReactorImpl implements Reactor {
timer = new Timer(collector);
wakeup = Pipe.open();
mark();
+ attachments = new RecordImpl();
}
@Override
@@ -110,14 +112,8 @@ public class ReactorImpl implements Reactor {
}
}
- @Override
- public void attach(Object attachment) {
- this.attachment = attachment;
- }
-
- @Override
- public Object attachment() {
- return attachment;
+ public Record attachments() {
+ return attachments;
}
@Override
@@ -205,19 +201,27 @@ public class ReactorImpl implements Reactor {
}
}
+ static Handler getHandler(Record record) {
+ return record.get(ReactorImpl.class, Handler.class);
+ }
+
+ static void setHandler(Record record, Handler handler) {
+ record.set(ReactorImpl.class, Handler.class, handler);
+ }
+
// pn_event_handler
private Handler eventHandler(Event event) {
Handler result;
if (event.getLink() != null) {
- result = ((HandlerEndpointImpl)event.getLink()).getHandler();
+ result = getHandler(event.getLink().attachments());
if (result != null) return result;
}
if (event.getSession() != null) {
- result = ((HandlerEndpointImpl)event.getSession()).getHandler();
+ result = getHandler(event.getSession().attachments());
if (result != null) return result;
}
if (event.getConnection() != null) {
- result = ((HandlerEndpointImpl)event.getConnection()).getHandler();
+ result = getHandler(event.getConnection().attachments());
if (result != null) return result;
}
@@ -394,7 +398,7 @@ public class ReactorImpl implements Reactor {
@Override
public Connection connection(Handler handler) {
Connection connection = Proton.connection();
- connection.add(handler);
+ setHandler(connection.attachments(), handler);
connection.collect(collector);
children.add(connection);
((ConnectionImpl)connection).setReactor(this);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org