diff options
author | Rafael H. Schloming <rhs@apache.org> | 2008-06-07 13:42:01 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2008-06-07 13:42:01 +0000 |
commit | 865436044bceebaae348747dedbc126e2b22eb5d (patch) | |
tree | ecadf31cb986ada58b907c5efbe6ea853784e88c /qpid/java/common | |
parent | dcdd849a1fc5678d8b8b9799ec357627cba8e5ed (diff) | |
download | qpid-python-865436044bceebaae348747dedbc126e2b22eb5d.tar.gz |
QPID-1126: reuse channel numbers for sessions that have closed, and honor the negotiated channel-max; also removed unnecessary catches that were swallowing stack traces from several tests
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@664339 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/common')
5 files changed, 36 insertions, 12 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpidity/transport/Channel.java b/qpid/java/common/src/main/java/org/apache/qpidity/transport/Channel.java index ad727676c4..2e11329c5b 100644 --- a/qpid/java/common/src/main/java/org/apache/qpidity/transport/Channel.java +++ b/qpid/java/common/src/main/java/org/apache/qpidity/transport/Channel.java @@ -131,10 +131,6 @@ public class Channel extends Invoker { session.closed(); } - } - - public void close() - { connection.removeChannel(channel); } diff --git a/qpid/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java b/qpid/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java index 9470520937..96578ffeb8 100644 --- a/qpid/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java +++ b/qpid/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java @@ -41,12 +41,14 @@ class ChannelDelegate extends MethodDelegate<Channel> public @Override void sessionDetached(Channel channel, SessionDetached closed) { - channel.getSession().closed(); + channel.closed(); } public @Override void sessionDetach(Channel channel, SessionDetach dtc) { channel.getSession().closed(); + channel.sessionDetached(dtc.getName(), SessionDetachCode.NORMAL); + channel.closed(); } } diff --git a/qpid/java/common/src/main/java/org/apache/qpidity/transport/Connection.java b/qpid/java/common/src/main/java/org/apache/qpidity/transport/Connection.java index 7d707ce17b..9829343491 100644 --- a/qpid/java/common/src/main/java/org/apache/qpidity/transport/Connection.java +++ b/qpid/java/common/src/main/java/org/apache/qpidity/transport/Connection.java @@ -22,8 +22,9 @@ package org.apache.qpidity.transport; import org.apache.qpidity.transport.util.Logger; +import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; +import java.util.List; import java.util.Map; import java.nio.ByteBuffer; @@ -48,6 +49,7 @@ public class Connection final private Sender<ConnectionEvent> sender; final private ConnectionDelegate delegate; + private int channelMax = 1; // want to make this final private int _connectionId; @@ -88,6 +90,32 @@ public class Connection sender.send(event); } + public int getChannelMax() + { + return channelMax; + } + + void setChannelMax(int max) + { + channelMax = max; + } + + public Channel getChannel() + { + synchronized (channels) + { + for (int i = 0; i < getChannelMax(); i++) + { + if (!channels.containsKey(i)) + { + return getChannel(i); + } + } + + throw new RuntimeException("no more channels available"); + } + } + public Channel getChannel(int number) { synchronized (channels) @@ -120,11 +148,10 @@ public class Connection log.debug("connection closed: %s", this); synchronized (channels) { - for (Iterator<Channel> it = channels.values().iterator(); - it.hasNext(); ) + List<Channel> values = new ArrayList<Channel>(channels.values()); + for (Channel ch : values) { - it.next().closed(); - it.remove(); + ch.closed(); } } delegate.closed(); diff --git a/qpid/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java b/qpid/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java index cb5f05a185..14344991c6 100644 --- a/qpid/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java +++ b/qpid/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java @@ -152,7 +152,7 @@ public abstract class ConnectionDelegate extends MethodDelegate<Channel> @Override public void connectionTune(Channel context, ConnectionTune struct) { - // should update the channel max given by the broker. + context.getConnection().setChannelMax(struct.getChannelMax()); context.connectionTuneOk(struct.getChannelMax(), struct.getMaxFrameSize(), struct.getHeartbeatMax()); context.connectionOpen(_virtualHost, null, Option.INSIST); } diff --git a/qpid/java/common/src/main/java/org/apache/qpidity/transport/Session.java b/qpid/java/common/src/main/java/org/apache/qpidity/transport/Session.java index d1ea23035a..a0229adf1e 100644 --- a/qpid/java/common/src/main/java/org/apache/qpidity/transport/Session.java +++ b/qpid/java/common/src/main/java/org/apache/qpidity/transport/Session.java @@ -526,7 +526,6 @@ public class Session extends Invoker } } } - channel.close(); channel.setSession(null); channel = null; } |