Commit 108bf73c authored by Andre Freyssinet's avatar Andre Freyssinet

JORAM-335: No longer close session in cleanup. Be careful, this session

is registered in the XAResource handled by external component.
parent 95fa9ecc
......@@ -98,9 +98,16 @@ public class ManagedConnectionImpl
/**
* Unique session for the use of managed components, involved in local or
* distributed transactions.
* Joram-327: This attribute should be better encapsulated!!
*/
Session session = null;
private Session session = null;
final Session getSession() {
return session;
}
final void setSession(Session session) {
this.session = session;
}
/** only used for reconnection */
Subject subject;
......@@ -245,16 +252,11 @@ public class ManagedConnectionImpl
}
/**
* Provides a <code>XAResource</code> instance for managing distributed
* transactions.
* Provides a <code>XAResource</code> instance for managing distributed transactions.
*
* @exception CommException If the physical connection
* is lost.
* @exception IllegalStateException If the managed connection is
* involved in a local
* transaction.
* @exception ResourceAdapterInternalException If the XA resource can't be
* retrieved.
* @exception CommException If the physical connection is lost.
* @exception IllegalStateException If the managed connection is involved in a local transaction.
* @exception ResourceAdapterInternalException If the XA resource can't be retrieved.
*/
public XAResource getXAResource() throws ResourceException {
if (logger.isLoggable(BasicLevel.DEBUG))
......@@ -288,8 +290,8 @@ public class ManagedConnectionImpl
if (outboundCnx != null) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getXAResource outboundCnx = " + outboundCnx +
"\n outboundCnx.sess = " + outboundCnx.sessions);
logger.log(BasicLevel.DEBUG,
this + " getXAResource outboundCnx = " + outboundCnx + "\n outboundCnx.sess = " + outboundCnx.sessions);
OutboundSession outboundSession = null;
if (outboundCnx.sessions.size() > 0) {
......@@ -297,7 +299,8 @@ public class ManagedConnectionImpl
if (!(outboundSession.sess instanceof XASession)) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getXAResource outboundSession.sess = " + outboundSession.sess);
logger.log(BasicLevel.DEBUG,
this + " getXAResource outboundSession.sess = " + outboundSession.sess);
// getXARessourceManager (create by XAConnection)
org.objectweb.joram.client.jms.XAResourceMngr xaResourceMngr = null;
......@@ -310,8 +313,7 @@ public class ManagedConnectionImpl
}
if (xaResourceMngr == null)
xaResourceMngr = new org.objectweb.joram.client.jms.XAResourceMngr(
(org.objectweb.joram.client.jms.Connection) outboundCnx.xac);
xaResourceMngr = new org.objectweb.joram.client.jms.XAResourceMngr((org.objectweb.joram.client.jms.Connection) outboundCnx.xac);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getXAResource xaResourceMngr = " + xaResourceMngr);
......@@ -343,11 +345,13 @@ public class ManagedConnectionImpl
// No session available, create a new XASession.
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getXAResource createXASession");
session = cnx.createXASession();
session = cnx.createXASession();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getXAResource session = " + session + ", session.class = " + session.getClass().getName() +
", getAcknowledgeMode = " + session.getAcknowledgeMode() + ", getTransacted = " + session.getTransacted());
logger.log(BasicLevel.DEBUG,
this + " getXAResource session = " + session + ", session.class = " + session.getClass().getName() +
", getAcknowledgeMode = " + session.getAcknowledgeMode() + ", getTransacted = " + session.getTransacted());
}
if (logger.isLoggable(BasicLevel.DEBUG))
......@@ -361,23 +365,23 @@ public class ManagedConnectionImpl
} else if (session instanceof org.objectweb.joram.client.jms.XASession) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getXAResource session is XASession and not null");
// set Session transacted = true
((org.objectweb.joram.client.jms.XASession)session).getDelegateSession().setTransacted(true);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getXAResource session = " + session + ", session.class = " + session.getClass().getName() +
", getAcknowledgeMode = " + session.getAcknowledgeMode() + ", getTransacted = " + session.getTransacted());
logger.log(BasicLevel.DEBUG,
this + " getXAResource session = " + session + ", session.class = " + session.getClass().getName() +
", getAcknowledgeMode = " + session.getAcknowledgeMode() + ", getTransacted = " + session.getTransacted());
// TODO
// cnx.sessions.add((org.objectweb.joram.client.jms.Session) session);
} else if (! (session instanceof javax.jms.XASession)) {
if (out != null)
out.print("Managed connection not involved in a local transaction.");
throw new IllegalStateException("Managed connection not involved "
+ "in a local transaction.");
throw new IllegalStateException("Managed connection not involved in a local transaction.");
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getXAResource return = " + ((XASession) session).getXAResource());
......@@ -409,9 +413,11 @@ public class ManagedConnectionImpl
out.print("Physical connection to the underlying JORAM server has been lost.");
throw new CommException("Physical connection to the underlying JORAM server has been lost.");
}
try {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getLocalTransaction session = " + session);
if (session == null)
session = cnx.createSession(true, 0);
else if (session instanceof javax.jms.XASession) {
......@@ -466,8 +472,7 @@ public class ManagedConnectionImpl
*
* @exception ResourceException Never thrown.
*/
public synchronized void cleanup()
throws ResourceException {
public synchronized void cleanup() throws ResourceException {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " cleanup()");
......@@ -477,14 +482,15 @@ public class ManagedConnectionImpl
handle = (OutboundConnection) it.next();
handle.cleanup();
}
try {
if (session != null)
session.close();
} catch (JMSException e) {
if (logger.isLoggable(BasicLevel.WARN))
logger.log(BasicLevel.WARN, e);
}
session = null;
// JORAM-335: This session is registered in XAResource.
// try {
// if (session != null)
// session.close();
// } catch (JMSException e) {
// if (logger.isLoggable(BasicLevel.WARN))
// logger.log(BasicLevel.WARN, e);
// }
// session = null;
try {
// Clear the handles.
handles.clear();
......@@ -752,8 +758,7 @@ public class ManagedConnectionImpl
* Returns <code>false</code> if the wrapped physical connection has been
* lost or destroyed, <code>true</code> if it is still valid.
*/
boolean isValid()
{
boolean isValid() {
return valid;
}
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2004 Bull SA
* Copyright (C) 2004 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 2004 Bull SA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -122,16 +122,16 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
if (! valid)
throw new javax.jms.IllegalStateException("Invalid connection handle.");
Session sess = managedCx.getSession();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " createSession managedCx.session = " + managedCx.session);
logger.log(BasicLevel.DEBUG, this + " createSession managedCx.session = " + sess);
Session sess = managedCx.session;
if (sess == null) {
try {
sess = xac.createSession(false, acknowledgeMode);
// Joram-327: managedCx.session should be set with the created session. May be, we should deal
// JORAM-327: managedCx.session should be set with the created session. May be, we should deal
// with potential synchronization issues.
managedCx.session = sess;
managedCx.setSession(sess);
} catch (IllegalStateException e) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " createSession (IllegalStateException)" + e);
......@@ -150,7 +150,7 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
sess = xac.createSession(false, acknowledgeMode);
// Joram-327: managedCx.session should be set with the created session. May be, we should deal
// with potential synchronization issues.
managedCx.session = sess;
managedCx.setSession(sess);
} catch (ResourceException exc) {
if (logger.isLoggable(BasicLevel.WARN))
logger.log(BasicLevel.WARN, this + " createSession (ResourceException)", exc);
......@@ -288,6 +288,7 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
logger.log(BasicLevel.DEBUG, this + " close() session = " + session);
session.close();
// TODO (AF): Should remove session from vector or set sessions to null
}
managedCx.closeHandle(this);
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2012 - ScalAgent Distributed Technologies
* Copyright (C) 2012 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 2004 - Bull SA
*
* This library is free software; you can redistribute it and/or
......@@ -45,7 +45,6 @@ import fr.dyade.aaa.common.Debug;
* a transaction (local or global).
*/
public class OutboundQueueConnection extends OutboundConnection implements QueueConnection {
public static Logger logger = Debug.getLogger(OutboundQueueConnection.class.getName());
/**
......@@ -57,9 +56,9 @@ public class OutboundQueueConnection extends OutboundConnection implements Queue
OutboundQueueConnection(ManagedConnectionImpl managedCx, XAQueueConnection xac) {
super(managedCx, xac);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "OutboundQueueConnection(" + managedCx + ", " + xac + ")");
logger.log(BasicLevel.DEBUG,
"OutboundQueueConnection(" + managedCx + ", " + xac + ")");
}
/**
* Returns the unique authorized JMS session per connection wrapped in
......@@ -75,10 +74,12 @@ public class OutboundQueueConnection extends OutboundConnection implements Queue
if (! valid)
throw new javax.jms.IllegalStateException("Invalid connection handle.");
Session sess = managedCx.getSession();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG,
this + " createQueueSession sess = " + managedCx.session);
Session sess = managedCx.session;
this + " createQueueSession sess = " + sess);
// TODO (AF): Use code from OutboundConnection.
if (sess == null)
sess = xac.createSession(false, acknowledgeMode);
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2012 - ScalAgent Distributed Technologies
* Copyright (C) 2012 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 2004 - Bull SA
*
* This library is free software; you can redistribute it and/or
......@@ -45,7 +45,6 @@ import fr.dyade.aaa.common.Debug;
* a transaction (local or global).
*/
public class OutboundTopicConnection extends OutboundConnection implements TopicConnection {
public static Logger logger = Debug.getLogger(OutboundTopicConnection.class.getName());
/**
......@@ -54,15 +53,13 @@ public class OutboundTopicConnection extends OutboundConnection implements Topic
* @param managedCx The managed connection building the handle.
* @param xac The underlying physical PubSub connection to handle.
*/
OutboundTopicConnection(ManagedConnectionImpl managedCx,
XATopicConnection xac) {
OutboundTopicConnection(ManagedConnectionImpl managedCx, XATopicConnection xac) {
super(managedCx, xac);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "OutboundTopicConnection(" + managedCx +
", " + xac + ")");
logger.log(BasicLevel.DEBUG,
"OutboundTopicConnection(" + managedCx + ", " + xac + ")");
}
/**
* Returns the unique authorized JMS session per connection wrapped in
......@@ -72,8 +69,7 @@ public class OutboundTopicConnection extends OutboundConnection implements Topic
* @exception javax.jms.JMSException Generic exception.
*/
public TopicSession
createTopicSession(boolean transacted, int acknowledgeMode)
throws JMSException {
createTopicSession(boolean transacted, int acknowledgeMode) throws JMSException {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " createTopicSession(" + transacted +
", " + acknowledgeMode + ")");
......@@ -81,10 +77,11 @@ public class OutboundTopicConnection extends OutboundConnection implements Topic
if (! valid)
throw new javax.jms.IllegalStateException("Invalid connection handle.");
Session sess = managedCx.getSession();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " createTopicSession sess = " + managedCx.session);
logger.log(BasicLevel.DEBUG, this + " createTopicSession sess = " + sess);
Session sess = managedCx.session;
// TODO (AF): Use code from OutboundConnection.
if (sess == null)
sess = xac.createSession(false, acknowledgeMode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment