public class TransportConnectionImpl extends java.lang.Object implements TransportConnection, javax.jms.ExceptionListener
Title: Open Service Framework
Description: Transport Connection implementation
Copyright: Copyright (c) 2010
Company: StreamScape Technologies
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the connection.
|
void |
connect()
Connect to the message transport.
|
javax.jms.ConnectionConsumer |
createConnectionConsumer(javax.jms.Destination destination,
java.lang.String messageSelector,
javax.jms.ServerSessionPool sessionPool,
int maxMessages)
Creates a connection consumer for this connection (optional operation).
|
javax.jms.ConnectionConsumer |
createDurableConnectionConsumer(javax.jms.Topic topic,
java.lang.String subscriptionName,
java.lang.String messageSelector,
javax.jms.ServerSessionPool sessionPool,
int maxMessages)
Create a durable connection consumer for this connection (optional operation).
|
javax.jms.Session |
createSession(boolean transacted,
int acknowledgeMode)
Creates a
Session object. |
void |
disconnect()
Disconnects from the message transport.
|
void |
forceStateCheck()
Forces connection to check it's current state, e.g.
|
java.lang.String |
getClientID()
Gets the client identifier for this connection.
|
ExceptionEventListener |
getExceptionEventListener()
Returns the exception advisory listener for this connection.
|
javax.jms.ExceptionListener |
getExceptionListener()
Gets the
ExceptionListener object for this connection. |
javax.jms.ConnectionMetaData |
getMetaData()
Gets the metadata for this connection.
|
java.lang.String |
getName()
Returns the name of this connection.
|
Logger |
getServiceLogger()
Returns the logger for this connection.
|
ConnectionState |
getState()
Returns the state of this connection.
|
StateNotificationEventListener |
getStateNotificationEventListener()
Returns the state notification advisory listener for this connection.
|
boolean |
isActive()
Returns
true is the current connection is active and connected. |
boolean |
isPrimary()
Check if this connection is a primary in a connection group.
|
void |
onException(javax.jms.JMSException exception)
Notifies user of a JMS exception.
|
void |
raiseException(TransportException error)
Raises a user-defined exception for this connection.
|
void |
resume()
Resume a connection.
|
void |
setClientID(java.lang.String string)
Sets the client identifier for this connection.
|
void |
setExceptionEventListener(ExceptionEventListener listener)
Sets the exception (advisory) event listener for this connection.
|
void |
setExceptionListener(javax.jms.ExceptionListener exceptionListener)
Sets an exception listener for this connection.
|
void |
setPrimary(boolean primary)
Sets the connection in a group to be the primary.
|
void |
setServiceLogger(Logger logger)
Sets the logger for this connection's critical log events.
|
void |
setStateNotificationEventListener(StateNotificationEventListener listener)
Sets the state notification (advisory) event listener for this connection.
|
void |
start()
Starts (or restarts) a connection's delivery of incoming messages.
|
void |
stop()
Temporarily stops a connection's delivery of incoming messages.
|
void |
suspend()
Suspends a connection.
|
public void connect() throws TransportException
TransportConnection
TransportConnection.getState()
to determine when a connection is in
ConnectionState.CONNECTED
state before proceeding.connect
in interface TransportConnection
TransportException
public void disconnect() throws TransportException
TransportConnection
disconnect
in interface TransportConnection
TransportException
public void suspend()
TransportConnection
suspend
in interface TransportConnection
public void resume()
TransportConnection
resume
in interface TransportConnection
public void forceStateCheck()
TransportConnection
forceStateCheck
in interface TransportConnection
public java.lang.String getName()
TransportConnection
Transport Factory
are unique.getName
in interface TransportConnection
public Logger getServiceLogger()
TransportConnection
null
if one is not set.getServiceLogger
in interface TransportConnection
public ConnectionState getState()
TransportConnection
getState
in interface TransportConnection
public boolean isActive()
TransportConnection
true
is the current connection is active and connected.isActive
in interface TransportConnection
public void setPrimary(boolean primary)
TransportConnection
setPrimary
in interface TransportConnection
primary
- booleanpublic void setServiceLogger(Logger logger)
TransportConnection
setServiceLogger
in interface TransportConnection
logger
- ILoggerpublic boolean isPrimary()
TransportConnection
isPrimary
in interface TransportConnection
public void setStateNotificationEventListener(StateNotificationEventListener listener)
TransportConnection
ConnectionStateChangeAdvisory
event every time a connection state change occurs.setStateNotificationEventListener
in interface TransportConnection
listener
- IStateNotificationEventListenerpublic StateNotificationEventListener getStateNotificationEventListener()
TransportConnection
null
if a listener is not set.getStateNotificationEventListener
in interface TransportConnection
public void setExceptionEventListener(ExceptionEventListener listener)
TransportConnection
TransportException
event in case of
an exception.setExceptionEventListener
in interface TransportConnection
listener
- IExceptionEventListenerpublic ExceptionEventListener getExceptionEventListener()
TransportConnection
null
if a listener is not set.getExceptionEventListener
in interface TransportConnection
public void raiseException(TransportException error)
TransportConnection
raiseException
in interface TransportConnection
error
- TransportExceptionpublic java.lang.String getClientID() throws javax.jms.JMSException
javax.jms.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.
getClientID
in interface javax.jms.Connection
javax.jms.JMSException
- if the JMS provider fails to return
the client ID for this connection due
to some internal error.public javax.jms.ExceptionListener getExceptionListener() throws javax.jms.JMSException
javax.jms.Connection
ExceptionListener
object for this connection.
Not every Connection
has an ExceptionListener
associated with it.getExceptionListener
in interface javax.jms.Connection
ExceptionListener
for this connection, or null.
if no ExceptionListener
is associated
with this connection.javax.jms.JMSException
- if the JMS provider fails to
get the ExceptionListener
for this
connection.Connection.setExceptionListener(javax.jms.ExceptionListener)
public javax.jms.ConnectionMetaData getMetaData() throws javax.jms.JMSException
javax.jms.Connection
getMetaData
in interface javax.jms.Connection
javax.jms.JMSException
- if the JMS provider fails to
get the connection metadata for this connection.ConnectionMetaData
public void setClientID(java.lang.String string) throws javax.jms.JMSException
javax.jms.Connection
The preferred way to assign a JMS client's client identifier is for
it to be configured in a client-specific ConnectionFactory
object and transparently assigned to the Connection
object
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 an
IllegalStateException
.
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 JMS API is that required to support durable subscriptions.
If another connection with the same clientID
is already running when
this method is called, the JMS provider should detect the duplicate ID and throw
an InvalidClientIDException
.
setClientID
in interface javax.jms.Connection
string
- the unique client identifierjavax.jms.JMSException
- if the JMS provider fails to
set the client ID for this connection due
to some internal error.public void setExceptionListener(javax.jms.ExceptionListener exceptionListener) throws javax.jms.JMSException
javax.jms.Connection
If a JMS 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's
onException
method, passing it a JMSException
object 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 JMS provider should attempt to resolve connection problems itself before it notifies the client of them.
setExceptionListener
in interface javax.jms.Connection
exceptionListener
- the exception listenerjavax.jms.JMSException
- if the JMS provider fails to
set the exception listener for this connection.public void start() throws javax.jms.JMSException
javax.jms.Connection
start
on a connection that has already been
started is ignored.start
in interface javax.jms.Connection
javax.jms.JMSException
- if the JMS provider fails to start
message delivery due to some internal error.Connection.stop()
public void stop() throws javax.jms.JMSException
javax.jms.Connection
start
method. 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.
This call blocks until 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
must 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 for receive
calls 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 stop
is invoked,
the stop
call 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.
stop
in interface javax.jms.Connection
javax.jms.JMSException
- if the JMS provider fails to stop
message delivery due to some internal error.Connection.start()
public void close() throws javax.jms.JMSException
javax.jms.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. 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
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.
close
in interface javax.jms.Connection
javax.jms.JMSException
- if the JMS 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.public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages) throws javax.jms.JMSException
javax.jms.Connection
createConnectionConsumer
in interface javax.jms.Connection
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 timejavax.jms.JMSException
- if the Connection
object fails
to create a connection consumer due to some
internal error or invalid arguments for
sessionPool
and
messageSelector
.ConnectionConsumer
public javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic, java.lang.String subscriptionName, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages) throws javax.jms.JMSException
javax.jms.Connection
createDurableConnectionConsumer
in interface javax.jms.Connection
topic
- 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 timejavax.jms.JMSException
- if the Connection
object fails
to create a connection consumer due to some
internal error or invalid arguments for
sessionPool
and
messageSelector
.ConnectionConsumer
public javax.jms.Session createSession(boolean transacted, int acknowledgeMode) throws javax.jms.JMSException
javax.jms.Connection
Session
object.createSession
in interface javax.jms.Connection
transacted
- indicates whether the session is transactedacknowledgeMode
- 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
.javax.jms.JMSException
- if the Connection
object fails
to create a session due to some internal error or
lack of support for the specific transaction
and acknowledgement mode.Session.AUTO_ACKNOWLEDGE
,
Session.CLIENT_ACKNOWLEDGE
,
Session.DUPS_OK_ACKNOWLEDGE
public void onException(javax.jms.JMSException exception)
javax.jms.ExceptionListener
onException
in interface javax.jms.ExceptionListener
exception
- the JMS exceptionCopyright © 2015-2024 StreamScape Technologies. All rights reserved.