[Jboss-cvs] JBoss Messaging SVN: r1322 - branches/Branch_1_0/src/main/org/jboss/jms/client
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 19 15:29:42 EDT 2006
Author: timfox
Date: 2006-09-19 15:29:41 -0400 (Tue, 19 Sep 2006)
New Revision: 1322
Modified:
branches/Branch_1_0/src/main/org/jboss/jms/client/JBossConnection.java
Log:
Close connection in finalizer to prevent resource leak
Modified: branches/Branch_1_0/src/main/org/jboss/jms/client/JBossConnection.java
===================================================================
--- branches/Branch_1_0/src/main/org/jboss/jms/client/JBossConnection.java 2006-09-19 19:17:09 UTC (rev 1321)
+++ branches/Branch_1_0/src/main/org/jboss/jms/client/JBossConnection.java 2006-09-19 19:29:41 UTC (rev 1322)
@@ -61,27 +61,28 @@
Connection, QueueConnection, TopicConnection,
XAConnection, XAQueueConnection, XATopicConnection, Serializable
{
-
+
// Constants -----------------------------------------------------
private static final long serialVersionUID = -3715868654823177898L;
-
+
static final int TYPE_GENERIC_CONNECTION = 0;
static final int TYPE_QUEUE_CONNECTION = 1;
static final int TYPE_TOPIC_CONNECTION = 2;
-
+
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
protected ConnectionDelegate delegate;
- private int connectionType;
+ private int connectionType;
+ private boolean closed;
// Constructors --------------------------------------------------
public JBossConnection(ConnectionDelegate delegate, int connectionType)
{
this.delegate = delegate;
- this.connectionType = connectionType;
+ this.connectionType = connectionType;
}
// Connection implementation -------------------------------------
@@ -146,7 +147,7 @@
String messageSelector,
ServerSessionPool sessionPool,
int maxMessages) throws JMSException
- {
+ {
// As spec. section 4.11
if (connectionType == TYPE_QUEUE_CONNECTION)
{
@@ -156,23 +157,23 @@
return delegate.
createConnectionConsumer(topic, subscriptionName, messageSelector, sessionPool, maxMessages);
}
-
+
// QueueConnection implementation ---------------------------------
public QueueSession createQueueSession(boolean transacted,
int acknowledgeMode) throws JMSException
- {
+ {
return createSessionInternal(transacted, acknowledgeMode, false,
JBossSession.TYPE_QUEUE_SESSION);
}
-
+
public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector,
ServerSessionPool sessionPool,
int maxMessages) throws JMSException
{
return delegate.createConnectionConsumer(queue, null, messageSelector, sessionPool, maxMessages);
}
-
+
// TopicConnection implementation ---------------------------------
public TopicSession createTopicSession(boolean transacted,
@@ -181,35 +182,35 @@
return createSessionInternal(transacted, acknowledgeMode, false,
JBossSession.TYPE_TOPIC_SESSION);
}
-
+
public ConnectionConsumer createConnectionConsumer(Topic topic, String messageSelector,
ServerSessionPool sessionPool,
int maxMessages) throws JMSException
{
return delegate.createConnectionConsumer(topic, null, messageSelector, sessionPool, maxMessages);
}
-
+
// XAConnection implementation -------------------------------------
public XASession createXASession() throws JMSException
- {
+ {
return createSessionInternal(true, Session.SESSION_TRANSACTED, true,
JBossSession.TYPE_GENERIC_SESSION);
}
-
+
// XAQueueConnection implementation ---------------------------------
public XAQueueSession createXAQueueSession() throws JMSException
- {
+ {
return createSessionInternal(true, Session.SESSION_TRANSACTED, true,
JBossSession.TYPE_QUEUE_SESSION);
}
-
+
// XATopicConnection implementation ---------------------------------
public XATopicSession createXATopicSession() throws JMSException
- {
+ {
return createSessionInternal(true, Session.SESSION_TRANSACTED, true,
JBossSession.TYPE_TOPIC_SESSION);
@@ -221,14 +222,14 @@
{
return "JBossConnection->" + delegate;
}
-
+
public String getRemotingClientSessionId()
{
ConnectionState state = (ConnectionState)((ClientConnectionDelegate)delegate).getState();
-
+
return state.getRemotingConnection().getInvokingClient().getSessionId();
}
-
+
public ConnectionDelegate getDelegate()
{
return delegate;
@@ -237,7 +238,7 @@
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
-
+
protected JBossSession createSessionInternal(boolean transacted, int acknowledgeMode,
boolean isXA, int type) throws JMSException
{
@@ -261,7 +262,18 @@
tccc.restore();
}
}
-
+
+ protected void finalize() throws Throwable
+ {
+ super.finalize();
+ //If a user hasn't explicitly closed the connection due to sloppy programming
+ //then we close it here
+ if (!closed)
+ {
+ close();
+ }
+ }
+
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
More information about the jboss-cvs-commits
mailing list