Class Connection
- java.lang.Object
-
- org.objectweb.joram.client.jms.Connection
-
- All Implemented Interfaces:
AutoCloseable,Connection,ConnectionMBean
- Direct Known Subclasses:
QueueConnection,TopicConnection,XAConnection
public class Connection extends Object implements Connection, ConnectionMBean
Implements thejavax.jms.Connectioninterface.A Connection object allows the client's active connection to the Joram server. Connections support concurrent use, it serves several purposes:
- It encapsulates the real connection with the Joram server (for example an open TCP/IP socket between the client and the server).
- It needs the client authentication.
- It specifies a unique client identifier.
- It supports the ExceptionListener object.
When a connection is created, it is in stopped mode that means that no messages are being delivered. In order to minimize any client confusion that may result from asynchronous message delivery during setup, it is typical to leave the connection in stopped mode until setup is complete. A message producer can send messages while a connection is stopped.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classConnection.AtomicCounter(package private) classConnection.CloserThis class synchronizes the close.private static classConnection.StatusStatus of the connection.
-
Field Summary
Fields Modifier and Type Field Description private Vector<MultiSessionConsumer>cconsumersVector of the connection's consumers.private StringclientIDClient's identifier.private Connection.ClosercloserUsed to synchronize the method close()private FactoryParametersfactoryParametersThe factory's parameters.private inthashCodeprivate org.objectweb.joram.shared.security.Identityidentityprotected StringJMXBeanBaseNameprivate intkeyConnection key.private booleanlockClientIDstatic org.objectweb.util.monolog.api.LoggerloggerStringMESSAGE_ID_PREFIX_PROPERTY(package private) Map<String,Integer>messageConsumersprivate Connection.AtomicCountermessagesCMessages counter.private ConnectionMetaDatametaDataConnection meta data.private RequestMultiplexermtpxThe request multiplexer used to communicate with the user proxy.private StringproxyIdClient's agent proxy identifier.private RequestorrequestorThe requestor used to communicate with the user proxy.private Vector<Session>sessionsVector of the connection's sessions.private Connection.AtomicCountersessionsCSessions counter.private intstatusStatus of the connection.private StringstringImageprivate Connection.AtomicCountersubsCSubscriptions counter.static org.objectweb.util.monolog.api.Loggertracker
-
Constructor Summary
Constructors Constructor Description Connection()Creates aConnectioninstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddClientIDToProxy(String clientID)protected voidaddSession(Session session)Called here and by sub-classes.(package private) booleancheckCLMessageProducer(Session session, MessageProducer mp)protected voidcheckClosed()Checks if the connection is closed.(package private) booleancheckCLSession(Session session)(package private) voidcheckConsumers(String agentId)Called by temporary destinations deletion.(package private) booleancheckThread()voidcleanup(boolean close)Used by OutboundConnection in the connector layer.voidclose()API method for closing the connection; even if the connection appears to be broken, closes the sessions.(package private) voidcloseConnectionConsumer(MultiSessionConsumer cc)Called by MultiSessionConsumer.(package private) booleancloseMessageConsumer(String targetName)(package private) voidcloseSession(Session session)Called by Session.private ConnectionConsumercreateConnectionConsumer(Destination dest, String subName, String selector, ServerSessionPool sessionPool, int maxMessages)ConnectionConsumercreateConnectionConsumer(Destination dest, String selector, ServerSessionPool sessionPool, int maxMessages)API method.ConnectionConsumercreateDurableConnectionConsumer(Topic topic, String subName, String selector, ServerSessionPool sessionPool, int maxMessages)API method.SessioncreateSession()Creates a session using JMS 2.O specificationSessioncreateSession(boolean transacted, int acknowledgeMode)API method.SessioncreateSession(int sessionMode)Creates a session using JMS 2.O specificationConnectionConsumercreateSharedConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages)ConnectionConsumercreateSharedDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages)(package private) voiddoClose()booleanequals(Object obj)Returnstrueif the parameter is aConnectioninstance sharing the same proxy identifier and connection key.booleangetAsyncSend()Indicates whether the persistent produced messages are asynchronously sent (without acknowledge) or not.StringgetClientID()API method.intgetCompressedMinSize()Returns the minimum size beyond which the message body is compressed.intgetCompressionLevel()Get the compression level (0..9) for this Connection, this attribute is inherited from FactoryParameters.ExceptionListenergetExceptionListener()API method.booleangetImplicitAck()Indicates whether the messages consumed are implicitly acknowledged or not.(package private) List<MessageInterceptor>getInInterceptors()returns the list of IN message interceptors.StringgetJMXBeanName()ConnectionMetaDatagetMetaData()API method.(package private) List<MessageInterceptor>getOutInterceptors()returns the list of OUT message interceptors.StringgetOutLocalAddress()Returns the local IP address on which the TCP connection is activated.intgetOutLocalPort()Returns the local IP address port on which the TCP connection is activated(package private) StringgetProxyId()intgetQueueMessageReadMax()Get the maximum number of messages that can be read at once from a queue for this Connection.protected RequestMultiplexergetRequestMultiplexer()intgetTopicAckBufferMax()Get the maximum number of acknowledgements that can be buffered when using Session.DUPS_OK_ACKNOWLEDGE mode for this Connection.intgetTopicActivationThreshold()Get the threshold of activation for this Connection.intgetTopicPassivationThreshold()Get the threshold of passivation for this Connection.longgetTxPendingTimer()Returns the duration in seconds during which a JMS transacted (non XA) session might be pending; above that duration the session is rolled back and closed; the 0 value means "no timer".inthashCode()(package private) booleanisOpenMessageConsumer(String targetName)booleanisStopped()voidlockClientId()(package private) StringnextMessageId()Returns a new message identifier.(package private) StringnextSessionId()Returns a new session identifier.(package private) StringnextSubName()Returns a new subscription name.voidopen(FactoryParameters factoryParameters, RequestChannel requestChannel)Open theConnection.(package private) voidopenMessageConsumer(String targetName)StringregisterMBean(String base)voidsetClientID(String clientID)API method.voidsetExceptionListener(ExceptionListener listener)API method.voidsetJMXBeanBaseName(String JMXBeanBaseName)(package private) voidsetProviderClientID()private voidsetStatus(int status)voidstart()API method for starting the connection.voidstop()API method for stopping the connection; even if the connection appears to be broken, stops the sessions.(package private) org.objectweb.joram.shared.client.AbstractJmsReplysyncRequest(org.objectweb.joram.shared.client.AbstractJmsRequest request)StringtoString()String image of the connection.voidunregisterMBean()
-
-
-
Field Detail
-
logger
public static org.objectweb.util.monolog.api.Logger logger
-
tracker
public static org.objectweb.util.monolog.api.Logger tracker
-
mtpx
private RequestMultiplexer mtpx
The request multiplexer used to communicate with the user proxy.
-
requestor
private Requestor requestor
The requestor used to communicate with the user proxy.
-
metaData
private ConnectionMetaData metaData
Connection meta data.
-
sessionsC
private Connection.AtomicCounter sessionsC
Sessions counter.
-
messagesC
private Connection.AtomicCounter messagesC
Messages counter.
-
subsC
private Connection.AtomicCounter subsC
Subscriptions counter.
-
proxyId
private String proxyId
Client's agent proxy identifier.
-
key
private int key
Connection key.
-
factoryParameters
private FactoryParameters factoryParameters
The factory's parameters.
-
status
private int status
Status of the connection. STOP, START, CLOSE
-
cconsumers
private Vector<MultiSessionConsumer> cconsumers
Vector of the connection's consumers.
-
closer
private Connection.Closer closer
Used to synchronize the method close()
-
stringImage
private String stringImage
-
hashCode
private int hashCode
-
identity
private org.objectweb.joram.shared.security.Identity identity
-
clientID
private String clientID
Client's identifier.
-
lockClientID
private boolean lockClientID
-
MESSAGE_ID_PREFIX_PROPERTY
public final String MESSAGE_ID_PREFIX_PROPERTY
- See Also:
- Constant Field Values
-
JMXBeanBaseName
protected String JMXBeanBaseName
-
-
Method Detail
-
checkThread
boolean checkThread()
-
checkCLSession
boolean checkCLSession(Session session)
-
checkCLMessageProducer
boolean checkCLMessageProducer(Session session, MessageProducer mp)
-
getProxyId
final String getProxyId()
-
lockClientId
public void lockClientId()
-
open
public void open(FactoryParameters factoryParameters, RequestChannel requestChannel) throws JMSException
Open theConnection.- Parameters:
factoryParameters- The factory parameters.requestChannel- The actual connection to wrap.- Throws:
JMSSecurityException- If the user identification is incorrect.IllegalStateException- If the server is not listening.JMSException
-
setJMXBeanBaseName
public void setJMXBeanBaseName(String JMXBeanBaseName)
-
getJMXBeanName
public String getJMXBeanName()
-
unregisterMBean
public void unregisterMBean()
-
setStatus
private void setStatus(int status)
-
isStopped
public boolean isStopped()
- Specified by:
isStoppedin interfaceConnectionMBean
-
toString
public String toString()
String image of the connection.
-
equals
public boolean equals(Object obj)
Returnstrueif the parameter is aConnectioninstance sharing the same proxy identifier and connection key.
-
getTxPendingTimer
public final long getTxPendingTimer()
Returns the duration in seconds during which a JMS transacted (non XA) session might be pending; above that duration the session is rolled back and closed; the 0 value means "no timer".- Specified by:
getTxPendingTimerin interfaceConnectionMBean- Returns:
- the duration in seconds during which a JMS transacted (non XA) session might be pending.
- See Also:
FactoryParameters.txPendingTimer
-
getImplicitAck
public final boolean getImplicitAck()
Indicates whether the messages consumed are implicitly acknowledged or not. If true messages are immediately removed from queue when delivered and there is none acknowledge message from client to server.This attribute is inherited from FactoryParameters, by default false.
- Specified by:
getImplicitAckin interfaceConnectionMBean- Returns:
- true if messages produced are implicitly acknowledged.
- See Also:
FactoryParameters.implicitAck,Session.isImplicitAck()
-
getAsyncSend
public final boolean getAsyncSend()
Indicates whether the persistent produced messages are asynchronously sent (without acknowledge) or not. Messages sent asynchronously may be lost if a failure occurs before the message is persisted on the server.Non persistent messages are always sent without acknowledgment.
This attribute is inherited from FactoryParameters, by default false, persistent messages are sent with acknowledge.
- Specified by:
getAsyncSendin interfaceConnectionMBean- Returns:
- true if messages produced are asynchronously sent.
- See Also:
FactoryParameters.asyncSend,Session.isAsyncSend()
-
getQueueMessageReadMax
public final int getQueueMessageReadMax()
Get the maximum number of messages that can be read at once from a queue for this Connection.This attribute is inherited from FactoryParameters, default value is 1.
- Specified by:
getQueueMessageReadMaxin interfaceConnectionMBean- Returns:
- The maximum number of messages that can be read at once from a queue.
- See Also:
FactoryParameters.queueMessageReadMax,Session.getQueueMessageReadMax()
-
getTopicAckBufferMax
public final int getTopicAckBufferMax()
Get the maximum number of acknowledgements that can be buffered when using Session.DUPS_OK_ACKNOWLEDGE mode for this Connection.This attribute is inherited from FactoryParameters, default value is 0.
- Specified by:
getTopicAckBufferMaxin interfaceConnectionMBean- Returns:
- The Maximum number of acknowledgements that can be buffered when using Session.DUPS_OK_ACKNOWLEDGE mode.
- See Also:
FactoryParameters.topicAckBufferMax,Session.getTopicAckBufferMax()
-
getTopicPassivationThreshold
public final int getTopicPassivationThreshold()
Get the threshold of passivation for this Connection.This threshold is the maximum messages number over which the subscription is passivated.
This attribute is inherited from FactoryParameters, default value is Integer.MAX_VALUE.
- Specified by:
getTopicPassivationThresholdin interfaceConnectionMBean- Returns:
- The maximum messages number over which the subscription is passivated.
- See Also:
FactoryParameters.topicPassivationThreshold,Session.getTopicPassivationThreshold()
-
getTopicActivationThreshold
public final int getTopicActivationThreshold()
Get the threshold of activation for this Connection.This threshold is the minimum messages number below which the subscription is activated.
This attribute is inherited from FactoryParameters, default value is 0.
- Specified by:
getTopicActivationThresholdin interfaceConnectionMBean- Returns:
- The minimum messages number below which the subscription is activated.
- See Also:
FactoryParameters.topicActivationThreshold,Session.getTopicActivationThreshold()
-
getCompressedMinSize
public final int getCompressedMinSize()
Returns the minimum size beyond which the message body is compressed. The default value is 0 (no compression).- Returns:
- the minimum size beyond which the message body is compressed
- See Also:
FactoryParameters.compressedMinSize
-
getCompressionLevel
public final int getCompressionLevel()
Get the compression level (0..9) for this Connection, this attribute is inherited from FactoryParameters. The default value is 1 (Deflater.BEST_SPEED).- Returns:
- The compression level
- See Also:
FactoryParameters.compressionLevel
-
getOutLocalAddress
public final String getOutLocalAddress()
Returns the local IP address on which the TCP connection is activated.This attribute is inherited from FactoryParameters.
- Specified by:
getOutLocalAddressin interfaceConnectionMBean- Returns:
- the local IP address on which the TCP connection is activated.
- See Also:
FactoryParameters.outLocalAddress
-
getOutLocalPort
public final int getOutLocalPort()
Returns the local IP address port on which the TCP connection is activatedThis attribute is inherited from FactoryParameters.
- Specified by:
getOutLocalPortin interfaceConnectionMBean- Returns:
- the local IP address port on which the TCP connection is activated.
- See Also:
FactoryParameters.outLocalPort
-
getInInterceptors
final List<MessageInterceptor> getInInterceptors()
returns the list of IN message interceptors.
Each IN message interceptor is called when receiving a message.
The execution follows the order of the elements within the list.- Returns:
- the list of the IN message interceptors.
-
getOutInterceptors
final List<MessageInterceptor> getOutInterceptors()
returns the list of OUT message interceptors.
Each OUT message interceptor is called when sending a message.
The execution follows the order of the elements within the list.- Returns:
- the list of the OUT message interceptors.
-
checkClosed
protected final void checkClosed() throws IllegalStateExceptionChecks if the connection is closed. If true raises an IllegalStateException.- Throws:
IllegalStateException
-
createConnectionConsumer
public ConnectionConsumer createConnectionConsumer(Destination dest, String selector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
API method. Creates a connection consumer for this connection, this is an expert facility needed for applications servers.- Specified by:
createConnectionConsumerin interfaceConnection- Parameters:
dest- the destination to access.selector- only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for this message consumer.sessionPool- the server session pool to associate with this connection consumer.maxMessages- the maximum number of messages that can be assigned to a server session at one time.- Returns:
- The connection consumer.
- Throws:
IllegalStateException- If the connection is closed.InvalidSelectorException- If the selector syntax is wrong.InvalidDestinationException- If the target destination does not exist.JMSException- If the method fails for any other reason.
-
createDurableConnectionConsumer
public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subName, String selector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
API method. Create a durable connection consumer for this connection, this is an expert facility needed for applications servers.- Specified by:
createDurableConnectionConsumerin interfaceConnection- Parameters:
topic- the topic to access.subName- durable subscription name.selector- only messages with properties matching the message selector expression are delivered. A value of null or an empty string indicates that there is no message selector for this message consumer.sessionPool- the server session pool to associate with this connection consumer.maxMessages- the maximum number of messages that can be assigned to a server session at one time.- Returns:
- The durable connection consumer.
- Throws:
IllegalStateException- If the connection is closed.InvalidSelectorException- If the selector syntax is wrong.InvalidDestinationException- If the target topic does not exist.JMSException- If the method fails for any other reason.
-
createConnectionConsumer
private ConnectionConsumer createConnectionConsumer(Destination dest, String subName, String selector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
- Throws:
JMSException
-
createSession
public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException
API method. Creates a Session object.- Specified by:
createSessionin interfaceConnection- Parameters:
transacted- indicates whether the session is transacted.acknowledgeMode- indicates whether the consumer or the client will acknowledge any messages it receives; ignored if the session is transacted. Legal values are Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, and Session.DUPS_OK_ACKNOWLEDGE. Additionnaly Joram defines INDIVIDUAL_ACKNOWLEDGE: With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method. Contrary to CLIENT_ACKNOWLEDGE mode this mode allows to acknowledge only the specified message.- Returns:
- A newly created session.
- Throws:
IllegalStateException- If the connection is closed.JMSException- In case of an invalid acknowledge mode.
-
createSession
public Session createSession() throws JMSException
Creates a session using JMS 2.O specificationIn a Java SE environment or in the Java EE application client container:
- The session will be non-transacted and received messages will be acknowledged automatically
using an acknowledgement mode of
Session.AUTO_ACKNOWLEDGEFor a definition of the meaning of this acknowledgement mode see the link below.
- Specified by:
createSessionin interfaceConnection- Throws:
JMSException
- The session will be non-transacted and received messages will be acknowledged automatically
using an acknowledgement mode of
-
createSession
public Session createSession(int sessionMode) throws JMSException
Creates a session using JMS 2.O specification- Specified by:
createSessionin interfaceConnection- Parameters:
sessionMode-In a Java SE environment or in the Java EE application client container:
- If
transactedis set totruethen the session will use a local transaction which may subsequently be committed or rolled back by calling the session'scommitorrollbackmethods. The argumentacknowledgeModeis ignored. - If
transactedis set tofalsethen the session will be non-transacted. In this case the argumentacknowledgeModeis used to specify how messages received by this session will be acknowledged. The permitted values areSession.CLIENT_ACKNOWLEDGE,Session.AUTO_ACKNOWLEDGEandSession.DUPS_OK_ACKNOWLEDGE. For a definition of the meaning of these acknowledgement modes see the links below.
- If
- Throws:
JMSException- in case of invalid session mode
-
addSession
protected void addSession(Session session)
Called here and by sub-classes.
-
setExceptionListener
public void setExceptionListener(ExceptionListener listener) throws JMSException
API method. Sets an exception listener for this connection. When Joram detects a serious problem with a connection, it informs the connection's ExceptionListener, if one has been registered. It does this by calling the listener's onException method, passing it a JMSException object describing the problem.The exception listener allows a client to be notified of a problem asynchronously. Some connections only consume messages, so they would have no other way to learn their connection has failed. A connection serializes execution of its ExceptionListener.
- Specified by:
setExceptionListenerin interfaceConnection- Parameters:
listener- the exception listener.- Throws:
IllegalStateException- If the connection is closed.JMSException
-
getExceptionListener
public ExceptionListener getExceptionListener() throws JMSException
API method. Gets the ExceptionListener object for this connection if it is configured.- Specified by:
getExceptionListenerin interfaceConnection- Returns:
- the ExceptionListener for this connection, or null. if no ExceptionListener is associated with this connection.
- Throws:
IllegalStateException- If the connection is closed.JMSException
-
setClientID
public void setClientID(String clientID) throws JMSException
API method. Sets the client identifier for this connection. Joram automatically allocates a client identifier when the connection is created, so this method always throws an IllegalStateException.- Specified by:
setClientIDin interfaceConnection- Parameters:
clientID- the unique client identifier.- Throws:
IllegalStateException- if the JMS client attempts to set a connection's client ID at the wrong time or when it has been administratively configured.JMSException
-
setProviderClientID
void setProviderClientID() throws JMSException- Throws:
JMSException
-
addClientIDToProxy
private void addClientIDToProxy(String clientID) throws JMSException
- Throws:
JMSException
-
getClientID
public String getClientID() throws JMSException
API method. Gets the client identifier for this connection. This value is specific to the Joram, it is automatically assigned by the server.- Specified by:
getClientIDin interfaceConnection- Specified by:
getClientIDin interfaceConnectionMBean- Returns:
- the unique client identifier.
- Throws:
IllegalStateException- If the connection is closed.JMSException
-
getMetaData
public ConnectionMetaData getMetaData() throws JMSException
API method. Gets the metadata for this connection.- Specified by:
getMetaDatain interfaceConnection- Returns:
- the connection metadata.
- Throws:
IllegalStateException- If the connection is closed.JMSException- See Also:
ConnectionMetadata
-
start
public void start() throws JMSExceptionAPI method for starting the connection.Starts (or restarts) the connection's delivery of incoming messages. A call to start on a connection that has already been started is ignored.
- Specified by:
startin interfaceConnection- Specified by:
startin interfaceConnectionMBean- Throws:
IllegalStateException- If the connection is closed or broken.JMSException
-
stop
public void stop() throws JMSExceptionAPI method for stopping the connection; even if the connection appears to be broken, stops the sessions.Temporarily stops the connection's delivery of incoming messages. Delivery can be restarted using the connection's start method. When the connection is stopped, delivery to all the connection's message consumers is inhibited.
Stopping a connection has no effect on its ability to send messages. A call to stop on a connection that has already been stopped is ignored. This call blocks until receives and/or message listeners in progress have completed, it must not return until delivery of messages has paused.
- Specified by:
stopin interfaceConnection- Specified by:
stopin interfaceConnectionMBean- Throws:
IllegalStateException- If the connection is closed or broken.JMSException
-
close
public void close() throws JMSExceptionAPI method for closing the connection; even if the connection appears to be broken, closes the sessions.In order to free significant resources allocated on behalf of a connection, clients should close connections when they are not needed. Closing a connection automatically close all related sessions, producers, and consumers and causes all temporary destinations to be deleted.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Specified by:
closein interfaceConnectionMBean- Throws:
JMSException- Actually never thrown.
-
doClose
void doClose()
-
cleanup
public void cleanup(boolean close)
Used by OutboundConnection in the connector layer. When a connection is put back in a pool, it must be cleaned up.- Parameters:
close- If true close underlying sessions.
-
nextSessionId
String nextSessionId()
Returns a new session identifier.
-
nextMessageId
String nextMessageId()
Returns a new message identifier.
-
nextSubName
String nextSubName()
Returns a new subscription name.
-
closeSession
void closeSession(Session session)
Called by Session.
-
closeConnectionConsumer
void closeConnectionConsumer(MultiSessionConsumer cc)
Called by MultiSessionConsumer. Synchronized with run().
-
syncRequest
org.objectweb.joram.shared.client.AbstractJmsReply syncRequest(org.objectweb.joram.shared.client.AbstractJmsRequest request) throws JMSException- Throws:
JMSException
-
checkConsumers
void checkConsumers(String agentId) throws JMSException
Called by temporary destinations deletion.- Throws:
JMSException
-
getRequestMultiplexer
protected final RequestMultiplexer getRequestMultiplexer()
-
createSharedConnectionConsumer
public ConnectionConsumer createSharedConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
- Specified by:
createSharedConnectionConsumerin interfaceConnection- Throws:
JMSException
-
createSharedDurableConnectionConsumer
public ConnectionConsumer createSharedDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
- Specified by:
createSharedDurableConnectionConsumerin interfaceConnection- Throws:
JMSException
-
openMessageConsumer
void openMessageConsumer(String targetName)
-
isOpenMessageConsumer
boolean isOpenMessageConsumer(String targetName)
-
closeMessageConsumer
boolean closeMessageConsumer(String targetName)
-
-