From 865436044bceebaae348747dedbc126e2b22eb5d Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Sat, 7 Jun 2008 13:42:01 +0000 Subject: 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 --- .../java/org/apache/qpidity/transport/Channel.java | 4 --- .../apache/qpidity/transport/ChannelDelegate.java | 4 ++- .../org/apache/qpidity/transport/Connection.java | 37 +++++++++++++++++++--- .../qpidity/transport/ConnectionDelegate.java | 2 +- .../java/org/apache/qpidity/transport/Session.java | 1 - 5 files changed, 36 insertions(+), 12 deletions(-) (limited to 'qpid/java/common/src') 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 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 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 it = channels.values().iterator(); - it.hasNext(); ) + List values = new ArrayList(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 @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; } -- cgit v1.2.1