Class ActiveMQConnection
- All Implemented Interfaces:
Connection,QueueConnection,TopicConnection,AutoCloseable,ActiveMQConnectionForContext
- Direct Known Subclasses:
ActiveMQXAConnection
The flat implementation of TopicConnection and QueueConnection is per design, following the common
usage of these as one flat API in JMS 1.1.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SimpleStringstatic final Stringstatic final Stringstatic final intstatic final intstatic final intFields inherited from class org.apache.activemq.artemis.jms.client.ActiveMQConnectionForContextImpl
threadAwareContext -
Constructor Summary
ConstructorsConstructorDescriptionActiveMQConnection(ConnectionFactoryOptions options, String username, String password, int connectionType, String clientID, int dupsOKBatchSize, int transactionBatchSize, boolean cacheDestinations, boolean enable1xPrefixes, ClientSessionFactory sessionFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTemporaryQueue(SimpleString queueAddress) voidvoidauthorize(boolean validateClientId) static intcheckAck(boolean transacted, int acknowledgeMode) I'm keeping this as static as the same check will be done within RA.protected final voidfinal voidclose()Closes the connection.booleancontainsTemporaryQueue(SimpleString queueAddress) protected ActiveMQSessioncreateAMQSession(boolean isXA, boolean transacted, int acknowledgeMode, ClientSession session, int type) createConnectionConsumer(Destination destination, String messageSelector, ServerSessionPool sessionPool, int maxMessages) Creates a connection consumer for this connection (optional operation) on the specific destination.createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int maxMessages) Creates a connection consumer for this connection (optional operation).createConnectionConsumer(Topic topic, String messageSelector, ServerSessionPool sessionPool, int maxMessages) Creates a connection consumer for this connection (optional operation).createDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) Create a durable connection consumer for this connection (optional operation).createNonXAQueueSession(boolean transacted, int acknowledgeMode) This internal method serves basically the Resource Adapter.createNonXASession(boolean transacted, int acknowledgeMode) This internal method serves basically the Resource Adapter.createNonXATopicSession(boolean transacted, int acknowledgeMode) This internal method serves basically the Resource Adapter.createQueueSession(boolean transacted, int acknowledgeMode) Creates aQueueSessionobject, specifyingtransactedandacknowledgeMode.Creates aSessionobject, specifying no arguments.createSession(boolean transacted, int acknowledgeMode) Creates aSessionobject, specifyingtransactedandacknowledgeMode.createSession(int sessionMode) Creates aSessionobject, specifyingsessionMode.protected final ActiveMQSessioncreateSessionInternal(boolean isXA, boolean transacted, int acknowledgeMode, int type) createSharedConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) Creates a connection consumer for this connection (optional operation) on the specific topic using a shared non-durable subscription with the specified name.createSharedDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) Creates a connection consumer for this connection (optional operation) on the specific topic using a shared durable subscription with the specified name.createTopicSession(boolean transacted, int acknowledgeMode) Creates aTopicSessionobject, specifyingtransactedandacknowledgeMode.Gets the client identifier for this connection.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Gets theExceptionListenerobject for this connection.ReturnsFailoverEventListenerthe current failover event listener for this connection.Gets the metadata for this connection.getUID()booleanbooleanprotected booleanisXA()voidremoveSession(ActiveMQSession session) voidremoveTemporaryQueue(SimpleString queueAddress) voidsetClientID(String clientID) Sets the client identifier for this connection.voidsetExceptionListener(ExceptionListener listener) Sets an exception listener for this connection.voidsetFailoverListener(FailoverEventListener listener) Sets a FailureListener for the session which is notified if a failure occurs on the session.voidvoidsetReference(ActiveMQConnectionFactory factory) voidvoidstart()Starts (or restarts) a connection's delivery of incoming messages.voidstop()Temporarily stops a connection's delivery of incoming messages.Methods inherited from class org.apache.activemq.artemis.jms.client.ActiveMQConnectionForContextImpl
closeFromContext, createContext, createXAContext, getThreadAwareContext, incrementRefCounter
-
Field Details
-
TYPE_GENERIC_CONNECTION
public static final int TYPE_GENERIC_CONNECTION- See Also:
-
TYPE_QUEUE_CONNECTION
public static final int TYPE_QUEUE_CONNECTION- See Also:
-
TYPE_TOPIC_CONNECTION
public static final int TYPE_TOPIC_CONNECTION- See Also:
-
EXCEPTION_FAILOVER
- See Also:
-
EXCEPTION_DISCONNECT
- See Also:
-
CONNECTION_ID_PROPERTY_NAME
-
-
Constructor Details
-
ActiveMQConnection
public ActiveMQConnection(ConnectionFactoryOptions options, String username, String password, int connectionType, String clientID, int dupsOKBatchSize, int transactionBatchSize, boolean cacheDestinations, boolean enable1xPrefixes, ClientSessionFactory sessionFactory)
-
-
Method Details
-
createNonXASession
This internal method serves basically the Resource Adapter. The resource adapter plays with an XASession and a non XASession. When there is no enlisted transaction, the EE specification mandates that the commit should be done as if it was a nonXA Session (i.e. SessionTransacted). For that reason we have this method to force that nonXASession, since the JMS Javadoc mandates createSession to return a XASession.- Throws:
JMSException
-
createNonXATopicSession
This internal method serves basically the Resource Adapter. The resource adapter plays with an XASession and a non XASession. When there is no enlisted transaction, the EE specification mandates that the commit should be done as if it was a nonXA Session (i.e. SessionTransacted). For that reason we have this method to force that nonXASession, since the JMS Javadoc mandates createSession to return a XASession.- Throws:
JMSException
-
createNonXAQueueSession
This internal method serves basically the Resource Adapter. The resource adapter plays with an XASession and a non XASession. When there is no enlisted transaction, the EE specification mandates that the commit should be done as if it was a nonXA Session (i.e. SessionTransacted). For that reason we have this method to force that nonXASession, since the JMS Javadoc mandates createSession to return a XASession.- Throws:
JMSException
-
createSession
Description copied from interface:ConnectionCreates aSessionobject, specifyingtransactedandacknowledgeMode.This method has been superseded by the method
createSession(int sessionMode)which specifies the same information using a single argument, and by the methodcreateSession()which is for use in a Jakarta EE JTA transaction. Applications should consider using those methods instead of this one.The effect of setting the
transactedandacknowledgeModearguments depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the effect of setting the transacted} andacknowledgeModearguments also depends on whether or not there is an active JTA transaction in progress.In a Java SE environment or in the Jakarta 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.
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
- Both arguments
transactedandacknowledgeModeare ignored. The session will participate in the JTA transaction and will be committed or rolled back when that transaction is committed or rolled back, not by calling the session'scommitorrollbackmethods. Since both arguments are ignored, developers are recommended to usecreateSession(), which has no arguments, instead of this method.
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
- If
transactedis set to false andacknowledgeModeis set toJMSContext.AUTO_ACKNOWLEDGEorSession.DUPS_OK_ACKNOWLEDGEthen the session will be non-transacted and messages will be acknowledged according to the value ofacknowledgeMode. - If
transactedis set to false andacknowledgeModeis set toJMSContext.CLIENT_ACKNOWLEDGEthen the Jakarta Messaging provider is recommended to ignore the specified parameters and instead provide a non-transacted, auto-acknowledged session. However the Jakarta Messaging provider may alternatively provide a non-transacted session with client acknowledgement. - If
transactedis set to true, then the Jakarta Messaging provider is recommended to ignore the specified parameters and instead provide a non-transacted, auto-acknowledged session. However the Jakarta Messaging provider may alternatively provide a local transacted session. - Applications are recommended to set
transactedto false andacknowledgeModetoJMSContext.AUTO_ACKNOWLEDGEorSession.DUPS_OK_ACKNOWLEDGEsince since applications which settransactedto false and setacknowledgeModetoJMSContext.CLIENT_ACKNOWLEDGE, or which settransactedto true, may not be portable.
Applications running in the Jakarta EE web and EJB containers must not attempt to create more than one active (not closed)
Sessionobject per connection. If this method is called in a Jakarta EE web or EJB container when an activeSessionobject already exists for this connection then aJMSExceptionmay be thrown.- Specified by:
createSessionin interfaceConnection- Parameters:
transacted- indicates whether the session will use a local transaction, except in the cases described above when this value is ignored..acknowledgeMode- when transacted is false, indicates how messages received by the session will be acknowledged, except in the cases described above when this value is ignored.- Returns:
- a newly created session
- Throws:
JMSException- if theConnectionobject fails to create a session due to- some internal error,
- lack of support for the specific transaction and acknowledgement mode, or
- because this method is being called in a Jakarta EE web or EJB application and an active session already exists for this connection.
- See Also:
- If
-
getClientID
Description copied from interface:ConnectionGets the client identifier for this connection.This value is specific to the Jakarta Messaging provider. It is either preconfigured by an administrator in a
ConnectionFactoryobject or assigned dynamically by the application by calling thesetClientIDmethod.- Specified by:
getClientIDin interfaceConnection- Returns:
- the unique client identifier
- Throws:
JMSException- if the Jakarta Messaging provider fails to return the client ID for this connection due to some internal error.
-
setClientID
Description copied from interface:ConnectionSets the client identifier for this connection.The preferred way to assign a Jakarta Messaging client's client identifier is for it to be configured in a client-specific
ConnectionFactoryobject and transparently assigned to theConnectionobject it creates.Alternatively, a client can set a connection's client identifier using a provider-specific value. The facility to set a connection's client identifier explicitly is not a mechanism for overriding the identifier that has been administratively configured. It is provided for the case where no administratively specified identifier exists. If one does exist, an attempt to change it by setting it must throw an
IllegalStateException. If a client sets the client identifier explicitly, it must do so immediately after it creates the connection and before any other action on the connection is taken. After this point, setting the client identifier is a programming error that should throw anIllegalStateException.The purpose of the client identifier is to associate a connection and its objects with a state maintained on behalf of the client by a provider. The only such state identified by the Jakarta Messaging API is that required to support durable subscriptions.
If another connection with the same
clientIDis already running when this method is called, the Jakarta Messaging provider should detect the duplicate ID and throw anInvalidClientIDException.This method must not be used in a Jakarta EE web or EJB application. Doing so may cause a
JMSExceptionto be thrown though this is not guaranteed.- Specified by:
setClientIDin interfaceConnection- Parameters:
clientID- the unique client identifier- Throws:
JMSException- if the Jakarta Messaging provider fails to set the client ID for the the connection for one of the following reasons:- an internal error has occurred or
- this method has been called in a Jakarta EE web or EJB application (though it is not guaranteed that an exception is thrown in this case)
InvalidClientIDException- if the Jakarta Messaging client specifies an invalid or duplicate client ID.IllegalStateException- if the Jakarta Messaging client attempts to set a connection's client ID at the wrong time or when it has been administratively configured.
-
getMetaData
Description copied from interface:ConnectionGets the metadata for this connection.- Specified by:
getMetaDatain interfaceConnection- Returns:
- the connection metadata
- Throws:
JMSException- if the Jakarta Messaging provider fails to get the connection metadata for this connection.- See Also:
-
getExceptionListener
Description copied from interface:ConnectionGets theExceptionListenerobject for this connection. Not everyConnectionhas anExceptionListenerassociated with it.- Specified by:
getExceptionListenerin interfaceConnection- Returns:
- the
ExceptionListenerfor this connection, or null. if noExceptionListeneris associated with this connection. - Throws:
JMSException- if the Jakarta Messaging provider fails to get theExceptionListenerfor this connection.- See Also:
-
setExceptionListener
Description copied from interface:ConnectionSets an exception listener for this connection.If a Jakarta Messaging provider 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'sonExceptionmethod, passing it aJMSExceptionobject describing the problem.An 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.A Jakarta Messaging provider should attempt to resolve connection problems itself before it notifies the client of them.
This method must not be used in a Jakarta EE web or EJB application. Doing so may cause a
JMSExceptionto be thrown though this is not guaranteed.- Specified by:
setExceptionListenerin interfaceConnection- Parameters:
listener- the exception listener- Throws:
JMSException- if the Jakarta Messaging provider fails to set the exception listener for one of the following reasons:- an internal error has occurred or
- this method has been called in a Jakarta EE web or EJB application (though it is not guaranteed that an exception is thrown in this case)
-
start
Description copied from interface:ConnectionStarts (or restarts) a connection's delivery of incoming messages. A call tostarton a connection that has already been started is ignored.- Specified by:
startin interfaceConnection- Throws:
JMSException- if the Jakarta Messaging provider fails to start message delivery due to some internal error.- See Also:
-
signalStopToAllSessions
public void signalStopToAllSessions() -
stop
Description copied from interface:ConnectionTemporarily stops a connection's delivery of incoming messages. Delivery can be restarted using the connection'sstartmethod. When the connection is stopped, delivery to all the connection's message consumers is inhibited: synchronous receives block, and messages are not delivered to message listeners.Stopping a connection has no effect on its ability to send messages. A call to
stopon a connection that has already been stopped is ignored.A call to
stopmust not return until delivery of messages has paused. This means that a client can rely on the fact that none of its message listeners will be called and that all threads of control waiting forreceivecalls to return will not return with a message until the connection is restarted. The receive timers for a stopped connection continue to advance, so receives may time out while the connection is stopped.If message listeners are running when
stopis invoked, thestopcall must wait until all of them have returned before it may return. While these message listeners are completing, they must have the full services of the connection available to them.However if the
stopmethod is called from a message listener on its own connection, then it will either fail and throw ajakarta.jms.IllegalStateException, or it will succeed and stop the connection, blocking until all other message listeners that may have been running have returned.Since two alternative behaviors are permitted in this case, applications should avoid calling
stopfrom a message listener on its own Connection because this is not portable.For the avoidance of doubt, if an exception listener for this connection is running when
stopis invoked, there is no requirement for thestopcall to wait until the exception listener has returned before it may return.This method must not be used in a Jakarta EE web or EJB application. Doing so may cause a
JMSExceptionto be thrown though this is not guaranteed.- Specified by:
stopin interfaceConnection- Throws:
IllegalStateException- this method has been called by a MessageListener on its own ConnectionJMSException- if the Jakarta Messaging provider fails to stop message delivery for one of the following reasons:- an internal error has occurred or
- this method has been called in a Jakarta EE web or EJB application (though it is not guaranteed that an exception is thrown in this case)
- See Also:
-
close
Description copied from interface:ConnectionCloses the connection.Since a provider typically allocates significant resources outside the JVM on behalf of a connection, clients should close these resources when they are not needed. Relying on garbage collection to eventually reclaim these resources may not be timely enough.
There is no need to close the sessions, producers, and consumers of a closed connection.
Closing a connection causes all temporary destinations to be deleted.
When this method is invoked, it should not return until message processing has been shut down in an orderly fashion. This means that all message listeners that may have been running have returned, and that all pending receives have returned.
However if the close method is called from a message listener on its own connection, then it will either fail and throw a
jakarta.jms.IllegalStateException, or it will succeed and close the connection, blocking until all other message listeners that may have been running have returned, and all pending receive calls have completed. If close succeeds and the acknowledge mode of the session is set toAUTO_ACKNOWLEDGE, the current message will still be acknowledged automatically when theonMessagecall completes. Since two alternative behaviors are permitted in this case, applications should avoid calling close from a message listener on its own connection because this is not portable.A close terminates all pending message receives on the connection's sessions' consumers. The receives may return with a message or with null, depending on whether there was a message available at the time of the close. If one or more of the connection's sessions' message listeners is processing a message at the time when connection
closeis invoked, all the facilities of the connection and its sessions must remain available to those listeners until they return control to the Jakarta Messaging provider.This method must not return until any incomplete asynchronous send operations for this Connection have been completed and any CompletionListener callbacks have returned. Incomplete sends should be allowed to complete normally unless an error occurs.
For the avoidance of doubt, if an exception listener for this connection is running when
closeis invoked, there is no requirement for theclosecall to wait until the exception listener has returned before it may return.Closing a connection causes any of its sessions' transactions in progress to be rolled back. In the case where a session's work is coordinated by an external transaction manager, a session's
commitandrollbackmethods are not used and the result of a closed session's work is determined later by the transaction manager. Closing a connection does NOT force an acknowledgment of client-acknowledged sessions.A CompletionListener callback method must not call close on its own Connection. Doing so will cause an IllegalStateException to be thrown.
Invoking the
acknowledgemethod of a received message from a closed connection's session must throw anIllegalStateException. Closing a closed connection must NOT throw an exception.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
IllegalStateException-- this method has been called by a MessageListener on its own Connection
- this method has been called by a CompletionListener callback method on its own Connection
JMSException- if the Jakarta Messaging provider fails to close the connection due to some internal error. For example, a failure to release resources or to close a socket connection can cause this exception to be thrown.
-
createConnectionConsumer
public ConnectionConsumer createConnectionConsumer(Destination destination, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException Description copied from interface:ConnectionCreates a connection consumer for this connection (optional operation) on the specific destination.This is an expert facility not used by ordinary Jakarta Messaging clients.
This method must not be used in a Jakarta EE web or Enterprise Bean application. Doing so may cause a
JMSExceptionto be thrown though this is not guaranteed.- Specified by:
createConnectionConsumerin interfaceConnection- Parameters:
destination- the destination to accessmessageSelector- 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 the message consumer.sessionPool- the server session pool to associate with this connection consumermaxMessages- the maximum number of messages that can be assigned to a server session at one time- Returns:
- the connection consumer
- Throws:
InvalidDestinationException- if an invalid destination is specified.InvalidSelectorException- if the message selector is invalid.JMSException- if theConnectionobject fails to create a connection consumer for one of the following reasons:- an internal error has occurred
- invalid arguments for
sessionPoolandmessageSelectoror - this method has been called in a Jakarta EE web or EJB application (though it is not guaranteed that an exception is thrown in this case)
- See Also:
-
createDurableConnectionConsumer
public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subscriptionName, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException Description copied from interface:TopicConnectionCreate a durable connection consumer for this connection (optional operation). This is an expert facility not used by regular Jakarta Messaging clients.- Specified by:
createDurableConnectionConsumerin interfaceConnection- Specified by:
createDurableConnectionConsumerin interfaceTopicConnection- Parameters:
topic- the topic to accesssubscriptionName- durable subscription namemessageSelector- 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 the message consumer.sessionPool- the server session pool to associate with this durable connection consumermaxMessages- the maximum number of messages that can be assigned to a server session at one time- Returns:
- the durable connection consumer
- Throws:
JMSException- if theTopicConnectionobject fails to create a connection consumer due to some internal error or invalid arguments forsessionPoolandmessageSelector.InvalidDestinationException- if an invalid topic is specified.InvalidSelectorException- if the message selector is invalid.- See Also:
-
createSession
Description copied from interface:ConnectionCreates aSessionobject, specifyingsessionMode.The effect of setting the
sessionModeargument depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the effect of setting thesessionModeargument also depends on whether or not there is an active JTA transaction in progress.In a Java SE environment or in the Jakarta EE application client container:
- If
sessionModeis set toSession.SESSION_TRANSACTEDthen the session will use a local transaction which may subsequently be committed or rolled back by calling the session'scommitorrollbackmethods. - If
sessionModeis set to any ofSession.CLIENT_ACKNOWLEDGE,Session.AUTO_ACKNOWLEDGEorSession.DUPS_OK_ACKNOWLEDGE. then the session will be non-transacted and messages received by this session will be acknowledged according to the value ofsessionMode. For a definition of the meaning of these acknowledgement modes see the links below.
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
- The argument
sessionModeis ignored. The session will participate in the JTA transaction and will be committed or rolled back when that transaction is committed or rolled back, not by calling the session'scommitorrollbackmethods. Since the argument is ignored, developers are recommended to usecreateSession(), which has no arguments, instead of this method.
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
- If
sessionModeis set toSession.AUTO_ACKNOWLEDGEorSession.DUPS_OK_ACKNOWLEDGEthen the session will be non-transacted and messages will be acknowledged according to the value ofsessionMode. - If
sessionModeis set toSession.CLIENT_ACKNOWLEDGEthen the Jakarta Messaging provider is recommended to ignore the specified parameter and instead provide a non-transacted, auto-acknowledged session. However the JMS provider may alternatively provide a non-transacted session with client acknowledgement. - If
sessionModeis set toSession.SESSION_TRANSACTED, then the Jakarta Messaging provider is recommended to ignore the specified parameter and instead provide a non-transacted, auto-acknowledged session. However the JMS provider may alternatively provide a local transacted session. - Applications are recommended to use only the values
Session.AUTO_ACKNOWLEDGEandSession.DUPS_OK_ACKNOWLEDGEsince applications which useSession.CLIENT_ACKNOWLEDGEorSession.SESSION_TRANSACTEDmay not be portable.
Applications running in the Jakarta EE web and EJB containers must not attempt to create more than one active (not closed)
Sessionobject per connection. If this method is called in a Jakarta EE web or EJB container when an activeSessionobject already exists for this connection then aJMSExceptionmay be thrown.- Specified by:
createSessionin interfaceConnection- Parameters:
sessionMode- specifies the session mode that will be used, except in the cases described above when this value is ignored. Legal values areJMSContext.SESSION_TRANSACTED,JMSContext.CLIENT_ACKNOWLEDGE,JMSContext.AUTO_ACKNOWLEDGEandJMSContext.DUPS_OK_ACKNOWLEDGE.- Returns:
- a newly created session
- Throws:
JMSException- if theConnectionobject fails to create a session due to- some internal error,
- lack of support for the specific transaction and acknowledgement mode, or
- because this method is being called in a Jakarta EE web or EJB application and an active session already exists for this connection.
- See Also:
- If
-
createSession
Description copied from interface:ConnectionCreates aSessionobject, specifying no arguments.The behaviour of the session that is created depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the behaviour of the session also depends on whether or not there is an active JTA transaction in progress.
In a Java SE environment or in the Jakarta 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.
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
- The session will participate in the JTA transaction and will be committed or rolled back when that transaction is
committed or rolled back, not by calling the session's
commitorrollbackmethods.
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
- 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.
Applications running in the Jakarta EE web and EJB containers must not attempt to create more than one active (not closed)
Sessionobject per connection. If this method is called in a Jakarta EE web or EJB container when an activeSessionobject already exists for this connection then aJMSExceptionmay be thrown.- Specified by:
createSessionin interfaceConnection- Returns:
- a newly created session
- Throws:
JMSException- if theConnectionobject fails to create a session due to- some internal error or
- because this method is being called in a Jakarta EE web or EJB application and an active session already exists for this connection.
- See Also:
- The session will be non-transacted and received messages will be acknowledged automatically using an
acknowledgement mode of
-
createQueueSession
Description copied from interface:QueueConnectionCreates aQueueSessionobject, specifyingtransactedandacknowledgeMode.The effect of setting the
transactedandacknowledgeModearguments depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the effect of setting the transacted} andacknowledgeModearguments also depends on whether or not there is an active JTA transaction in progress.In a Java SE environment or in the Jakarta 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.
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
- Both arguments
transactedandacknowledgeModeare ignored. The session will participate in the JTA transaction and will be committed or rolled back when that transaction is committed or rolled back, not by calling the session'scommitorrollbackmethods. Since both arguments are ignored, developers are recommended to usecreateSession(), which has no arguments, instead of this method.
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
- If
transactedis set to false andacknowledgeModeis set toJMSContext.AUTO_ACKNOWLEDGEorSession.DUPS_OK_ACKNOWLEDGEthen the session will be non-transacted and messages will be acknowledged according to the value ofacknowledgeMode. - If
transactedis set to false andacknowledgeModeis set toJMSContext.CLIENT_ACKNOWLEDGEthen the Jakarta Messaging provider is recommended to ignore the specified parameters and instead provide a non-transacted, auto-acknowledged session. However the Jakarta Messaging provider may alternatively provide a non-transacted session with client acknowledgement. - If
transactedis set to true, then the Jakarta Messaging provider is recommended to ignore the specified parameters and instead provide a non-transacted, auto-acknowledged session. However the Jakarta Messaging provider may alternatively provide a local transacted session. - Applications are recommended to set
transactedto false andacknowledgeModetoJMSContext.AUTO_ACKNOWLEDGEorSession.DUPS_OK_ACKNOWLEDGEsince since applications which settransactedto false and setacknowledgeModetoJMSContext.CLIENT_ACKNOWLEDGE, or which settransactedto true, may not be portable.
Applications running in the Jakarta EE web and EJB containers must not attempt to create more than one active (not closed)
Sessionobject per connection. If this method is called in a Jakarta EE web or EJB container when an activeSessionobject already exists for this connection then aJMSExceptionmay be thrown.- Specified by:
createQueueSessionin interfaceQueueConnection- Parameters:
transacted- indicates whether the session will use a local transaction, except in the cases described above when this value is ignored.acknowledgeMode- when transacted is false, indicates how messages received by the session will be acknowledged, except in the cases described above when this value is ignored.- Returns:
- a newly created
QueueSession - Throws:
JMSException- if theQueueConnectionobject fails to create aQueueSessiondue to- some internal error,
- lack of support for the specific transaction and acknowledgement mode, or
- because this method is being called in a Jakarta EE web or EJB application and an active session already exists for this connection.
- See Also:
- If
-
checkAck
public static int checkAck(boolean transacted, int acknowledgeMode) I'm keeping this as static as the same check will be done within RA. This is to conform with TCK Tests where we must return ackMode exactly as they want if transacted=false -
createConnectionConsumer
public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException Description copied from interface:QueueConnectionCreates a connection consumer for this connection (optional operation). This is an expert facility not used by regular Jakarta Messaging clients.- Specified by:
createConnectionConsumerin interfaceQueueConnection- Parameters:
queue- the queue to accessmessageSelector- 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 the message consumer.sessionPool- the server session pool to associate with this connection consumermaxMessages- the maximum number of messages that can be assigned to a server session at one time- Returns:
- the connection consumer
- Throws:
JMSException- if theQueueConnectionobject fails to create a connection consumer due to some internal error or invalid arguments forsessionPoolandmessageSelector.InvalidDestinationException- if an invalid queue is specified.InvalidSelectorException- if the message selector is invalid.- See Also:
-
createTopicSession
Description copied from interface:TopicConnectionCreates aTopicSessionobject, specifyingtransactedandacknowledgeMode.The effect of setting the
transactedandacknowledgeModearguments depends on whether this method is called in a Java SE environment, in the Jakarta EE application client container, or in the Jakarta EE web or EJB container. If this method is called in the Jakarta EE web or EJB container then the effect of setting the transacted} andacknowledgeModearguments also depends on whether or not there is an active JTA transaction in progress.In a Java SE environment or in the Jakarta 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.
In a Jakarta EE web or EJB container, when there is an active JTA transaction in progress:
- Both arguments
transactedandacknowledgeModeare ignored. The session will participate in the JTA transaction and will be committed or rolled back when that transaction is committed or rolled back, not by calling the session'scommitorrollbackmethods. Since both arguments are ignored, developers are recommended to usecreateSession(), which has no arguments, instead of this method.
In the Jakarta EE web or EJB container, when there is no active JTA transaction in progress:
- If
transactedis set to false andacknowledgeModeis set toJMSContext.AUTO_ACKNOWLEDGEorSession.DUPS_OK_ACKNOWLEDGEthen the session will be non-transacted and messages will be acknowledged according to the value ofacknowledgeMode. - If
transactedis set to false andacknowledgeModeis set toJMSContext.CLIENT_ACKNOWLEDGEthen the Jakarta Messaging provider is recommended to ignore the specified parameters and instead provide a non-transacted, auto-acknowledged session. However the Jakarta Messaging provider may alternatively provide a non-transacted session with client acknowledgement. - If
transactedis set to true, then the Jakarta Messaging provider is recommended to ignore the specified parameters and instead provide a non-transacted, auto-acknowledged session. However the Jakarta Messaging provider may alternatively provide a local transacted session. - Applications are recommended to set
transactedto false andacknowledgeModetoJMSContext.AUTO_ACKNOWLEDGEorSession.DUPS_OK_ACKNOWLEDGEsince since applications which settransactedto false and setacknowledgeModetoJMSContext.CLIENT_ACKNOWLEDGE, or which settransactedto true, may not be portable.
Applications running in the Jakarta EE web and EJB containers must not attempt to create more than one active (not closed)
Sessionobject per connection. If this method is called in a Jakarta EE web or EJB container when an activeSessionobject already exists for this connection then aJMSExceptionmay be thrown.- Specified by:
createTopicSessionin interfaceTopicConnection- Parameters:
transacted- indicates whether the session will use a local transaction, except in the cases described above when this value is ignored.acknowledgeMode- when transacted is false, indicates how messages received by the session will be acknowledged, except in the cases described above when this value is ignored.- Returns:
- a newly created
TopicSession - Throws:
JMSException- if theTopicConnectionobject fails to create aTopicSessiondue to- some internal error,
- lack of support for the specific transaction and acknowledgement mode, or
- because this method is being called in a Jakarta EE web or EJB application and an active session already exists for this connection.
- See Also:
- If
-
createConnectionConsumer
public ConnectionConsumer createConnectionConsumer(Topic topic, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException Description copied from interface:TopicConnectionCreates a connection consumer for this connection (optional operation). This is an expert facility not used by regular Jakarta Messaging clients.- Specified by:
createConnectionConsumerin interfaceTopicConnection- Parameters:
topic- the topic to accessmessageSelector- 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 the message consumer.sessionPool- the server session pool to associate with this connection consumermaxMessages- the maximum number of messages that can be assigned to a server session at one time- Returns:
- the connection consumer
- Throws:
JMSException- if theTopicConnectionobject fails to create a connection consumer due to some internal error or invalid arguments forsessionPoolandmessageSelector.InvalidDestinationException- if an invalid topic is specified.InvalidSelectorException- if the message selector is invalid.- See Also:
-
setFailoverListener
Sets a FailureListener for the session which is notified if a failure occurs on the session.- Parameters:
listener- the listener to add- Throws:
JMSException
-
getFailoverListener
ReturnsFailoverEventListenerthe current failover event listener for this connection.- Returns:
FailoverEventListenerthe current failover event listener for this connection- Throws:
JMSException
-
addTemporaryQueue
-
removeTemporaryQueue
-
containsTemporaryQueue
-
hasNoLocal
public boolean hasNoLocal() -
setHasNoLocal
public void setHasNoLocal() -
getUID
-
removeSession
-
getInitialSession
-
isXA
protected boolean isXA() -
createSessionInternal
protected final ActiveMQSession createSessionInternal(boolean isXA, boolean transacted, int acknowledgeMode, int type) throws JMSException - Throws:
JMSException
-
getSessionFactory
-
createAMQSession
protected ActiveMQSession createAMQSession(boolean isXA, boolean transacted, int acknowledgeMode, ClientSession session, int type) -
checkClosed
- Throws:
JMSException
-
authorize
- Throws:
JMSException
-
authorize
- Throws:
JMSException
-
setReference
-
isStarted
public boolean isStarted() -
getDeserializationBlackList
Deprecated, for removal: This API element is subject to removal in a future version. -
getDeserializationWhiteList
Deprecated, for removal: This API element is subject to removal in a future version. -
getDeserializationDenyList
-
getDeserializationAllowList
-