Connection


public interface Connection
Subinterfaces: QueueConnection, TopicConnection, XAQueueConnection, and
XATopicConnection

WebSphere MQ class: MQConnection



java.lang.Object
   |
   +----com.ibm.mq.jms.MQConnection

A JMS Connection is a client's active connection to its JMS provider.

See also: QueueConnection, TopicConnection, XAQueueConnection, and XATopicConnection

Methods

close
public void close() throws JMSException

Because a provider may allocate some resources outside the JVM on behalf of a Connection, clients should close them when they are not needed. You cannot rely on garbage collection to reclaim these resources eventually, because this may not occur soon enough. There is no need to close the sessions, producers, and consumers of a closed connection.

Closing a connection causes any of its sessions' in-process transactions to be rolled back. In the case where a session's work is coordinated by an external transaction manager, when using XASession, a session's commit and rollback methods are not used and the result of a closed session's work is determined later by a transaction manager. Closing a connection does NOT force an acknowledge of client acknowledged sessions.

WebSphere MQ JMS keeps a pool of WebSphere MQ hConns available for use by Sessions. Under some circumstances, Connection.close() clears this pool. If an application uses multiple Connections sequentially, it is possible to force the pool to remain active between JMS Connections. To do this, register an MQPoolToken with com.ibm.mq.MQEnvironment for the lifetime of your JMS application. For details, see Connection pooling and MQEnvironment.

Throws:
JMSException - if the JMS implementation fails to close the connection because of an internal error. Examples are a failure to release resources or to close a socket connection.

getClientID
public java.lang.String getClientID()
                                throws JMSException

Get the client identifier for this connection. The client identifier can either be preconfigured by the administrator in a ConnectionFactory, or assigned by calling setClientId.

Returns:
the unique client identifier.

Throws:
JMSException - if the JMS implementation fails to return the client ID for this Connection because of an internal error.

getExceptionListener
public ExceptionListener getExceptionListener()
                                            throws JMSException

Get the ExceptionListener for this Connection.

Returns:
The ExceptionListener for this Connection

Throws:
JMSException - general exception if the JMS implementation fails to get the Exception listener for this Connection.

getMetaData
public ConnectionMetaData getMetaData() throws JMSException

Get the metadata for this connection.

Returns:
the connection metadata.

Throws:
JMSException - general exception if the JMS implementation fails to get the Connection metadata for this Connection.

See also:
ConnectionMetaData

setClientID
public void setClientID(java.lang.String clientID)
                                             throws JMSException

Set the client identifier for this connection.

Note:
The client identifier is ignored for point-to-point connections.
WebSphere MQ Event Broker note

This method always throws an IllegalStateException when you make a direct connection to WebSphere MQ Event Broker.

Parameters:
clientID - the unique client identifier.

Throws:
  • JMSException - if the JMS implementation fails to set the client ID for this Connection because of an internal error.
  • InvalidClientIDException - if the JMS client specifies a non valid or duplicate client id.
  • IllegalStateException - if attempting to set a connection's client identifier at the wrong time, or if it has been configured administratively.

setExceptionListener
public void setExceptionListener(ExceptionListener listener)
                                                        throws JMSException

Set an exception listener for this connection.

Parameters:
handler - the exception listener.

Throws:
JMSException - general exception if the JMS implementation fails to set the Exception listener for this Connection.

start
public void start() throws JMSException

Start (or restart) a Connection's delivery of incoming messages. Starting a started session is ignored.

Throws:
JMSException - if the JMS implementation fails to start the message delivery because of an internal error.

See also:
stop

stop
public void stop() throws JMSException

Used to stop a Connection's delivery of incoming messages temporarily. It can be restarted using its start method. When stopped, delivery to all the Connection's message consumers is inhibited. Synchronous receives are blocked, and messages are not delivered to message listeners.

Stopping a session has no affect on its ability to send messages. Stopping a stopped session is ignored.

Throws:
JMSException - if the JMS implementation fails to stop the message delivery because of an internal error.

See also:
start



© IBM Corporation 1997, 2002. All Rights Reserved