qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kgiu...@apache.org
Subject [03/21] qpid-proton git commit: PROTON-857: use maps to track handle usage, avoid pre-allocating large arrays we typically wont utilise fully
Date Mon, 27 Apr 2015 21:26:28 GMT
PROTON-857: use maps to track handle usage, avoid pre-allocating large arrays we typically
wont utilise fully

Also reduces handle-max to 65535, giving 65536 usable handles like proton-c currently has.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/74e16dfe
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/74e16dfe
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/74e16dfe

Branch: refs/heads/kgiusti-python3
Commit: 74e16dfe00f21621e8dbc27cea41ae12ad9a66c7
Parents: f2d7d66
Author: Robert Gemmell <robbie@apache.org>
Authored: Wed Apr 22 11:22:13 2015 +0100
Committer: Robert Gemmell <robbie@apache.org>
Committed: Wed Apr 22 19:26:33 2015 +0100

----------------------------------------------------------------------
 .../proton/engine/impl/TransportSession.java    | 50 +++++++++-----------
 1 file changed, 22 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/74e16dfe/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportSession.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportSession.java
b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportSession.java
index fb537cc..1f4a9f8 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportSession.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportSession.java
@@ -34,20 +34,22 @@ import org.apache.qpid.proton.engine.Event;
 
 class TransportSession
 {
+    private static final int HANDLE_MAX = 65535;
+
     private final TransportImpl _transport;
     private final SessionImpl _session;
     private int _localChannel = -1;
     private int _remoteChannel = -1;
     private boolean _openSent;
-    private final UnsignedInteger _handleMax = UnsignedInteger.valueOf(65536);
+    private final UnsignedInteger _handleMax = UnsignedInteger.valueOf(HANDLE_MAX); //TODO:
should this be configurable?
     private UnsignedInteger _outgoingDeliveryId = UnsignedInteger.ZERO;
     private UnsignedInteger _incomingWindowSize = UnsignedInteger.ZERO;
     private UnsignedInteger _outgoingWindowSize = UnsignedInteger.ZERO;
     private UnsignedInteger _nextOutgoingId = UnsignedInteger.ONE;
     private UnsignedInteger _nextIncomingId = null;
 
-    private final TransportLink[] _remoteHandleMap = new TransportLink[_handleMax.intValue()
+ 1];
-    private final TransportLink[] _localHandleMap = new TransportLink[_handleMax.intValue()
+ 1];
+    private final Map<UnsignedInteger, TransportLink<?>> _remoteHandlesMap =
new HashMap<UnsignedInteger, TransportLink<?>>();
+    private final Map<UnsignedInteger, TransportLink<?>> _localHandlesMap = new
HashMap<UnsignedInteger, TransportLink<?>>();
     private final Map<String, TransportLink> _halfOpenLinks = new HashMap<String,
TransportLink>();
 
 
@@ -138,15 +140,11 @@ class TransportSession
 
     private void unsetLocalHandles()
     {
-        for(int i = 0; i < _localHandleMap.length; i++)
+        for (TransportLink<?> tl : _localHandlesMap.values())
         {
-            TransportLink<?> tl = _localHandleMap[i];
-            if(tl != null)
-            {
-                _localHandleMap[i] = null;
-                tl.clearLocalHandle();
-            }
+            tl.clearLocalHandle();
         }
+        _localHandlesMap.clear();
     }
 
     public void unsetRemoteChannel()
@@ -160,15 +158,11 @@ class TransportSession
 
     private void unsetRemoteHandles()
     {
-        for(int i = 0; i < _remoteHandleMap.length; i++)
+        for (TransportLink<?> tl : _remoteHandlesMap.values())
         {
-            TransportLink<?> tl = _remoteHandleMap[i];
-            if(tl != null)
-            {
-                _remoteHandleMap[i] = null;
-                tl.clearRemoteHandle();
-            }
+            tl.clearRemoteHandle();
         }
+        _remoteHandlesMap.clear();
     }
 
     public UnsignedInteger getHandleMax()
@@ -231,19 +225,19 @@ class TransportSession
 
     public TransportLink getLinkFromRemoteHandle(UnsignedInteger handle)
     {
-        return _remoteHandleMap[handle.intValue()];
+        return _remoteHandlesMap.get(handle);
     }
 
     public UnsignedInteger allocateLocalHandle(TransportLink transportLink)
     {
-        for(int i = 0; i < _localHandleMap.length; i++)
+        for(int i = 0; i <= HANDLE_MAX; i++)
         {
-            if(_localHandleMap[i] == null)
+            UnsignedInteger handle = UnsignedInteger.valueOf(i);
+            if(!_localHandlesMap.containsKey(handle))
             {
-                UnsignedInteger rc = UnsignedInteger.valueOf(i);
-                _localHandleMap[i] = transportLink;
-                transportLink.setLocalHandle(rc);
-                return rc;
+                _localHandlesMap.put(handle, transportLink);
+                transportLink.setLocalHandle(handle);
+                return handle;
             }
         }
         throw new IllegalStateException("no local handle available for allocation");
@@ -251,22 +245,22 @@ class TransportSession
 
     public void addLinkRemoteHandle(TransportLink link, UnsignedInteger remoteHandle)
     {
-        _remoteHandleMap[remoteHandle.intValue()] = link;
+        _remoteHandlesMap.put(remoteHandle, link);
     }
 
     public void addLinkLocalHandle(TransportLink link, UnsignedInteger localhandle)
     {
-        _localHandleMap[localhandle.intValue()] = link;
+        _localHandlesMap.put(localhandle, link);
     }
 
     public void freeLocalHandle(UnsignedInteger handle)
     {
-        _localHandleMap[handle.intValue()] = null;
+        _localHandlesMap.remove(handle);
     }
 
     public void freeRemoteHandle(UnsignedInteger handle)
     {
-        _remoteHandleMap[handle.intValue()] = null;
+        _remoteHandlesMap.remove(handle);
     }
 
     public TransportLink resolveHalfOpenLink(String name)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message