Packagecom.kaazing.gateway.jms.client
Interfacepublic interface Connection
ImplementorsConnectionListenerAdapter, StompConnectionFactory

A Connection object is a client's active connection to its JMS provider. It typically allocates provider resources outside the environment.

Connections support concurrent use.

A connection serves several purposes:

Because the creation of a connection involves setting up authentication and communication, a connection is a relatively heavyweight object. Most clients will do all their messaging with a single connection. Other more advanced applications may use several connections. The JMS API does not architect a reason for using multiple connections; however, there may be operational reasons for doing so.

A JMS client typically creates a connection, one or more sessions, and a number of message producers and consumers. When a connection is created, it is in stopped mode. That means that no messages are being delivered.

It is typical to leave the connection in stopped mode until setup is complete (that is, until all message consumers have been created). At that point, the client calls the connection's start method, and messages begin arriving at the connection's consumers. This setup convention minimizes any client confusion that may result from asynchronous message delivery while the client is still in the process of setting itself up.

A connection can be started immediately, and the setup can be done afterwards. Clients that do this must be prepared to handle asynchronous message delivery while they are still in the process of setting up.

A message producer can send messages while a connection is stopped.



Public Properties
 PropertyDefined by
  clientID : String
Gets the client identifier for this connection.
Connection
  connectionListener : ConnectionListener
Gets the connectionListener associated with this connection.
Connection
  exceptionListener : ExceptionListener
Gets the ExceptionListener object for this connection.
Connection
  metaData : ConnectionMetaData
[read-only] Gets the metadata for this connection.
Connection
Public Methods
 MethodDefined by
  
close(callback:Function):VoidFuture
Closes the connection.
Connection
  
createSession(transacted:Boolean, acknowledgeMode:int):Session
Creates a Session object.
Connection
  
isConnected():Boolean
Returns true if the underlying WebSocket connection is established and currently connected.
Connection
  
start(callback:Function):VoidFuture
Starts (or restarts) a connection's delivery of incoming messages.
Connection
  
stop(callback:Function):VoidFuture
Temporarily stops a connection's delivery of incoming messages.
Connection
Property detail
clientIDproperty
clientID:String  [read-write]

Gets the client identifier for this connection.

This value is specific to the JMS provider. It is either preconfigured by an administrator in a ConnectionFactory object or assigned dynamically by the application by calling the setClientID method.

Implementation
    public function get clientID():String
    public function set clientID(value:String):void
connectionListenerproperty 
connectionListener:ConnectionListener  [read-write]

Gets the connectionListener associated with this connection.

Implementation
    public function get connectionListener():ConnectionListener
    public function set connectionListener(value:ConnectionListener):void
exceptionListenerproperty 
exceptionListener:ExceptionListener  [read-write]

Gets the ExceptionListener object for this connection. Not every Connection has an ExceptionListener associated with it.

Implementation
    public function get exceptionListener():ExceptionListener
    public function set exceptionListener(value:ExceptionListener):void
metaDataproperty 
metaData:ConnectionMetaData  [read-only]

Gets the metadata for this connection.

Implementation
    public function get metaData():ConnectionMetaData

See also

Method detail
close()method
public function close(callback:Function):VoidFuture

Closes 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 executes asynchronously (returns immediately), but does not invoke the callback 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. A close terminates all pending message receives on the connection's sessions' consumers. The receive callbacks may be invoked 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 are processing a message at the time when connection close is invoked, all the facilities of the connection and its sessions must remain available to those listeners until they return control to the JMS provider.

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 commit and rollback methods 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.

Invoking the acknowledge method of a received message from a closed connection's session must throw an IllegalStateException. Closing a closed connection must NOT throw an exception.

Parameters
callback:Function — called when function has returned a value or thrown an exception

Returns
VoidFuture
createSession()method 
public function createSession(transacted:Boolean, acknowledgeMode:int):Session

Creates a Session object.

Parameters
transacted:Boolean — indicates whether the session is transacted
 
acknowledgeMode:int — 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.

Returns
Session — a newly created session

See also

isConnected()method 
public function isConnected():Boolean

Returns true if the underlying WebSocket connection is established and currently connected. If the WebSocket connection is broken due to a network failure or similar transient issue, the WebSocket will attempt to reconnect until the connection is explicitly closed by calling connection.close().

Returns
Boolean
start()method 
public function start(callback:Function):VoidFuture

Starts (or restarts) a connection's delivery of incoming messages. A call to start on a connection that has already been started is ignored.

Parameters
callback:Function — called when function has returned a value or thrown an exception

Returns
VoidFuture
stop()method 
public function stop(callback:Function):VoidFuture

Temporarily stops a 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: callbacks from receive are delayed, and messages are not delivered to message listeners.

This call executes asynchronously (returns immediately). The callback is invoked when receives and/or message listeners in progress have completed.

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.

A call to stop does not invoke the callback 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 callbacks waiting for receive will not be invoked 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 stop is invoked, the stop will not invoke the callback until all of them have returned. While these message listeners are completing, they must have the full services of the connection available to them.

Parameters
callback:Function — called when function has returned a value or thrown an exception

Returns
VoidFuture