Class JMSTopicRemoteConnection
- All Implemented Interfaces:
Serializable
,Runnable
Purpose: Define the implementation of the abstract RemoteConnection for JMS.
Description: Executing commands implementation of RemoteConnection is done via JMS Publisher. Using a single TopicConnection for both publishing and subscribing would allow subscriber to ignore messages sent through the same TopicConnection - and therefore allow JMSTopicRemoteConnection to ignore messages that it has itself published. Unfortunately J2EE doesn't allow that: J2EE spec. (J2EE.6.6 in v1.4) states: "The following methods may only be used by application components executing in the application client container: javax.jms.Session method setMessageListener ... Application components in the web and EJB containers must not attempt to create more than one active (not closed) Session object per connection." Because of these restrictions a) two JMSTopicRemoteConnection are required - one for publishing (external) and another one for listening (local); b) listening should be done using subscriber.receive() in an infinite loop in a separate thread, that's why the class implements Runnable interface. c) publishing connection (external) could be used concurrently to send messages, so it cannot use the same publisher/session/topicConnection Instead, it will store the TopicConnectionFactory and use it to create connections when executeCommandInternal is called (much like DatabaseAccessor when an external pool is used)
- Since:
- OracleAS TopLink 10g (10.0.3)
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected TopicSubscriber
protected Topic
protected TopicConnection
protected TopicConnectionFactory
protected TopicSession
static long
Fields inherited from class org.eclipse.persistence.internal.sessions.coordination.broadcast.BroadcastRemoteConnection
displayString, info, infoExt, rcm, state, STATE_ACTIVE, STATE_CLOSED, STATE_CLOSING, topicName
Fields inherited from class org.eclipse.persistence.internal.sessions.coordination.RemoteConnection
serviceId
-
Constructor Summary
ConstructorDescriptionCreates local connections that do not use a TopicConnection or TopicSession, useful only for processing already received JMS messagesJMSTopicRemoteConnection
(RemoteCommandManager rcm, TopicConnectionFactory topicConnectionFactory, Topic topic, boolean isLocalConnectionBeingCreated, boolean reuseJMSTopicPublisher) INTERNAL: Constructor creating either a local or external connection. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
INTERNAL: Indicates whether all the resources used by connection are freed after close method returns.protected void
INTERNAL: This method is called by close method.protected void
INTERNAL: Used for debug loggingprotected Object
executeCommandInternal
(Object command) INTERNAL: Execute the remote command.getTopic()
boolean
isLocal()
INTERNAL: Indicates whether connection is local (subscriber) or external (publisher).protected String
logDebugJMSTopic
(Message message) INTERNAL:void
INTERNAL: Process received JMS message.void
run()
INTERNAL: This method is used by local (listening) connection only.void
setPublisher
(TopicPublisher publisher) INTERNAL: set the TopicPublisher to be used when this RemoteConnection executes a command.void
setSuscriber
(TopicSubscriber subscriber) INTERNAL: set the TopicSubscriber on a local RemoteConnection for reading JMS messages when this runnable connection is started in a thread.void
INTERNAL: Set the Topic.void
setTopicConnection
(TopicConnection topicConnection) INTERNAL: Set the TopicConnection.void
setTopicConnectionFactory
(TopicConnectionFactory topicConnectionFactory) INTERNAL: Set the TopicConnectionFactory, which is used if the publisher is not set to obtain the TopicConnection, TopicSession and TopicPublishervoid
setTopicSession
(TopicSession topicSession) INTERNAL: set the TopicSession to be used when this RemoteConnection executes a command if the publisher is also set.protected boolean
INTERNAL: Return whether a BroadcastConnection should check a ServiceId against its own ServiceId to avoid the processing of Commands with the same ServiceId.Methods inherited from class org.eclipse.persistence.internal.sessions.coordination.broadcast.BroadcastRemoteConnection
close, executeCommand, executeCommand, failDeserializeMessage, getInfo, getInfoExt, getState, getTopicName, isActive, isClosed, isClosing, logDebugAfterPublish, logDebugBeforePublish, logDebugOnReceiveMessage, processReceivedObject, toString
Methods inherited from class org.eclipse.persistence.internal.sessions.coordination.RemoteConnection
getServiceId, setServiceId
-
Field Details
-
topicConnectionFactory
-
topic
-
isLocal
protected boolean isLocal -
topicConnection
-
topicSession
-
subscriber
-
WAIT_ON_ERROR_RECEIVING_JMS_MESSAGE
public static long WAIT_ON_ERROR_RECEIVING_JMS_MESSAGE
-
-
Constructor Details
-
JMSTopicRemoteConnection
public JMSTopicRemoteConnection(RemoteCommandManager rcm, TopicConnectionFactory topicConnectionFactory, Topic topic, boolean isLocalConnectionBeingCreated, boolean reuseJMSTopicPublisher) throws JMSException INTERNAL: Constructor creating either a local or external connection. Local connections created this way connect to the topicSession and cache the session and subscriber. External connections cache only the topicConnection and will obtain the session/publisher when needed.- Throws:
JMSException
-
JMSTopicRemoteConnection
Creates local connections that do not use a TopicConnection or TopicSession, useful only for processing already received JMS messages- See Also:
-
-
Method Details
-
isLocal
public boolean isLocal()INTERNAL: Indicates whether connection is local (subscriber) or external (publisher). -
executeCommandInternal
INTERNAL: Execute the remote command. The result of execution is returned. This method is used only by external (publishing) connection.- Specified by:
executeCommandInternal
in classBroadcastRemoteConnection
- Throws:
Exception
-
onMessage
INTERNAL: Process received JMS message. This method is used only by local (listening) connection. -
areAllResourcesFreedOnClose
protected boolean areAllResourcesFreedOnClose()INTERNAL: Indicates whether all the resources used by connection are freed after close method returns. Usually that's the case. However in case of local (listening) JMSTopicRemoteConnection close merely indicates to the listening thread that it should free TopicConnection and exit. Note that it may take a while: the listening thread waits until subscriber.receive method either returns a message or throws an exception.- Overrides:
areAllResourcesFreedOnClose
in classBroadcastRemoteConnection
-
closeInternal
INTERNAL: This method is called by close method. This method usually (but not always see comment to areAllResourcesFreedOnClose method) frees all the resources.- Specified by:
closeInternal
in classBroadcastRemoteConnection
- Throws:
JMSException
-
logDebugJMSTopic
INTERNAL:- Throws:
JMSException
-
run
public void run()INTERNAL: This method is used by local (listening) connection only. The only way to exit the loop is to set isActive to false - there should be no uncaught exceptions thrown from inside the loop. The execution exits the loop either in case of exception in remove connection on error mode; or by trasportManager.removeLocalConnection() call (which calls connection.close(), which sets isActive to false). -
createDisplayString
protected void createDisplayString()INTERNAL: Used for debug logging- Overrides:
createDisplayString
in classBroadcastRemoteConnection
-
shouldCheckServiceId
protected boolean shouldCheckServiceId()INTERNAL: Return whether a BroadcastConnection should check a ServiceId against its own ServiceId to avoid the processing of Commands with the same ServiceId. This should take place (return true) for a JMSTopicRemoteConnection.- Overrides:
shouldCheckServiceId
in classBroadcastRemoteConnection
- Returns:
- boolean
-
setPublisher
INTERNAL: set the TopicPublisher to be used when this RemoteConnection executes a command. Setting the TopicPublisher avoids having it obtained on each executeCommandInternal call. Passing in a publisher requires a TopicSession to also be set. These will not be closed until the external RemoteConnection is closed, and then only if the TopicConnection is also set. -
getPublisher
-
setSuscriber
INTERNAL: set the TopicSubscriber on a local RemoteConnection for reading JMS messages when this runnable connection is started in a thread. If setting this, a TopicConnection is also required to be set, in order for it to be closed when the thread completes. This is only to be used when using the JMSTopicRemoteConnection(rcm) constructor. -
getSubscriber
-
setTopicSession
INTERNAL: set the TopicSession to be used when this RemoteConnection executes a command if the publisher is also set. Setting the TopicSession and Publisher avoids having them obtained on each executeCommandInternal call. Passing in a TopicSession requires a TopicPublisher to also be set. These will not be closed until the external RemoteConnection is closed, and then only if the TopicConnection is also set. -
getTopicSession
-
setTopicConnectionFactory
INTERNAL: Set the TopicConnectionFactory, which is used if the publisher is not set to obtain the TopicConnection, TopicSession and TopicPublisher -
getTopicConnectionFactory
-
setTopicConnection
INTERNAL: Set the TopicConnection. If this is set, a Publisher and TopicSession must also be set, or a new TopicConnection will be obtained on each executeCommandInternal call. This TopicConnection is only used on close, as closing the TopicConnection also closes any open TopicSessions and Publishers obtained from it. -
getTopicConnection
-
setTopic
INTERNAL: Set the Topic. The Topic is required with the TopicConnectionFactory to obtain connections if the TopicPublisher is not set. -
getTopic
-