Commit cda63255 authored by Andre Freyssinet's avatar Andre Freyssinet

JORAM-327: no longer creates multiples unused sessions.

parent ed025eeb
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2004 - 2013 ScalAgent Distributed Technologies
* Copyright (C) 2004 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 2004 Bull SA
*
* This library is free software; you can redistribute it and/or
......@@ -98,6 +98,7 @@ 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;
......@@ -177,8 +178,7 @@ public class ManagedConnectionImpl
* @exception CommException If the wrapped physical connection is lost.
*/
public Object getConnection(javax.security.auth.Subject subject,
ConnectionRequestInfo cxRequestInfo)
throws ResourceException {
ConnectionRequestInfo cxRequestInfo) throws ResourceException {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getConnection(" + subject + ", " + cxRequestInfo + ")");
......@@ -400,8 +400,7 @@ public class ManagedConnectionImpl
* @exception LocalTransactionException If the LocalTransaction resource
* can't be created.
*/
public javax.resource.spi.LocalTransaction getLocalTransaction()
throws ResourceException {
public javax.resource.spi.LocalTransaction getLocalTransaction() throws ResourceException {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " getLocalTransaction()");
......@@ -663,23 +662,19 @@ public class ManagedConnectionImpl
* begun, or if the commit fails.
*/
public synchronized void commit() throws ResourceException {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " commit()");
if (! isValid())
throw new CommException("Physical connection to the underlying "
+ "JORAM server has been lost.");
throw new CommException("Physical connection to the underlying JORAM server has been lost.");
if (! startedLocalTx)
throw new LocalTransactionException("Local transaction has not begun.");
try {
session.commit();
}
catch (JMSException exc) {
throw new LocalTransactionException("Commit of the transacted JMS "
+ "session failed: " + exc);
} catch (JMSException exc) {
throw new LocalTransactionException("Commit of the transacted JMS session failed: " + exc);
}
ConnectionEvent event =
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2004 - Bull SA
* Copyright (C) 2004 - 2013 ScalAgent Distributed Technologies
* Copyright (C) 2004 Bull SA
* Copyright (C) 2004 - 2019 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -91,24 +91,21 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
if (! valid)
throw new javax.jms.IllegalStateException("Invalid connection handle.");
throw new IllegalStateException("Forbidden call on a component's "
+ "connection.");
throw new IllegalStateException("Forbidden call on a component's connection.");
}
/**
* Forbidden call on an application or component's outbound connection,
* throws a <code>IllegalStateException</code> instance.
*/
public void setExceptionListener(ExceptionListener listener)
throws JMSException {
public void setExceptionListener(ExceptionListener listener) throws JMSException {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " setExceptionListener(" + listener + ")");
if (! valid)
throw new javax.jms.IllegalStateException("Invalid connection handle.");
throw new IllegalStateException("Forbidden call on a component's "
+ "connection.");
throw new IllegalStateException("Forbidden call on a component's connection.");
}
/**
......@@ -118,11 +115,9 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
* @exception javax.jms.IllegalStateException If the handle is invalid.
* @exception javax.jms.JMSException Generic exception.
*/
public Session createSession(boolean transacted, int acknowledgeMode)
throws JMSException {
public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " createSession(" + transacted +
", " + acknowledgeMode + ")");
logger.log(BasicLevel.DEBUG, this + " createSession(" + transacted + ", " + acknowledgeMode + ")");
if (! valid)
throw new javax.jms.IllegalStateException("Invalid connection handle.");
......@@ -134,10 +129,14 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
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
// with potential synchronization issues.
managedCx.session = sess;
} catch (IllegalStateException e) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " createSession (IllegalStateException)" + e);
logger.log(BasicLevel.WARN, this + " createSession reconnection in progress...");
try {
if (managedCx.isReconnected()) {
ManagedConnection mc = managedCx.mcf.createManagedConnection(managedCx.subject, managedCx.cxRequest);
......@@ -149,15 +148,21 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
throw new JMSException(this + " createSession : managed connection is not reconnected.");
}
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;
} catch (ResourceException exc) {
if (logger.isLoggable(BasicLevel.WARN))
logger.log(BasicLevel.WARN, this + " createSession (ResourceException)", exc);
}
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " createSession sess = " + sess);
logger.log(BasicLevel.DEBUG, this + " createSession new session = " + sess);
} else {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " createSession retrieve session = " + sess);
}
return new OutboundSession(sess, this, transacted);
}
......@@ -225,7 +230,6 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
* throws a <code>IllegalStateException</code> instance.
*/
public void stop() throws JMSException {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " stop()");
......@@ -243,8 +247,7 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
createConnectionConsumer(Destination destination,
String messageSelector,
ServerSessionPool sessionPool,
int maxMessages)
throws JMSException {
int maxMessages) throws JMSException {
if (! valid)
throw new javax.jms.IllegalStateException("Invalid connection handle.");
......@@ -260,8 +263,7 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
String subscriptionName,
String messageSelector,
ServerSessionPool sessionPool,
int maxMessages)
throws JMSException {
int maxMessages) throws JMSException {
if (! valid)
throw new javax.jms.IllegalStateException("Invalid connection handle.");
......@@ -294,17 +296,15 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
}
/**
* returns <code>true</code> if the
* parameter is a <code>Connection</code> instance sharing the same
* Returns <code>true</code> if the parameter is a <code>Connection</code> instance sharing the same
* proxy identifier and connection key.
*/
public boolean cnxEquals(Object obj) {
return (obj instanceof Connection)
&& xac.equals(obj);
return (obj instanceof Connection) && xac.equals(obj);
}
/**
* close all session.
* Close all sessions.
*/
public void cleanup() {
if (logger.isLoggable(BasicLevel.DEBUG))
......@@ -356,10 +356,12 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
}
}
@Override
public int getNumberOfSession() {
return sessions.size();
}
@Override
public String[] getSessions() {
String[] sessTab = new String[sessions.size()];
for (int i = 0; i < sessions.size(); i++) {
......@@ -394,14 +396,14 @@ public class OutboundConnection implements Connection, OutboundConnectionMBean {
public ConnectionConsumer createSharedConnectionConsumer(Topic topic,
String subscriptionName, String messageSelector,
ServerSessionPool sessionPool, int maxMessages) throws JMSException {
//TODO
// TODO ? Should be forbidden on OutboundConnection ?
throw new JMSException("not yet implemented.");
}
public ConnectionConsumer createSharedDurableConnectionConsumer(Topic topic,
String subscriptionName, String messageSelector,
ServerSessionPool sessionPool, int maxMessages) throws JMSException {
//TODO
// TODO ? Should be forbidden on OutboundConnection ?
throw new JMSException("not yet implemented.");
}
}
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