All Implemented Interfaces:
Serializable, Runnable

public class JMSTopicRemoteConnection extends BroadcastRemoteConnection implements 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 Details

    • topicConnectionFactory

      protected TopicConnectionFactory topicConnectionFactory
    • topic

      protected Topic topic
    • isLocal

      protected boolean isLocal
    • topicConnection

      protected TopicConnection topicConnection
    • topicSession

      protected TopicSession topicSession
    • subscriber

      protected TopicSubscriber 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

      public JMSTopicRemoteConnection(RemoteCommandManager rcm)
      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

      protected Object executeCommandInternal(Object command) throws Exception
      INTERNAL: Execute the remote command. The result of execution is returned. This method is used only by external (publishing) connection.
      Specified by:
      executeCommandInternal in class BroadcastRemoteConnection
      Throws:
      Exception
    • onMessage

      public void onMessage(Message message)
      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 class BroadcastRemoteConnection
    • closeInternal

      protected void closeInternal() throws JMSException
      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 class BroadcastRemoteConnection
      Throws:
      JMSException
    • logDebugJMSTopic

      protected String logDebugJMSTopic(Message message) throws JMSException
      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).
      Specified by:
      run in interface Runnable
    • createDisplayString

      protected void createDisplayString()
      INTERNAL: Used for debug logging
      Overrides:
      createDisplayString in class BroadcastRemoteConnection
    • 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 class BroadcastRemoteConnection
      Returns:
      boolean
    • setPublisher

      public void setPublisher(TopicPublisher publisher)
      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

      public TopicPublisher getPublisher()
    • setSuscriber

      public 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. 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

      public TopicSubscriber getSubscriber()
    • setTopicSession

      public void setTopicSession(TopicSession topicSession)
      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

      public TopicSession getTopicSession()
    • setTopicConnectionFactory

      public void setTopicConnectionFactory(TopicConnectionFactory topicConnectionFactory)
      INTERNAL: Set the TopicConnectionFactory, which is used if the publisher is not set to obtain the TopicConnection, TopicSession and TopicPublisher
    • getTopicConnectionFactory

      public TopicConnection getTopicConnectionFactory()
    • setTopicConnection

      public void setTopicConnection(TopicConnection topicConnection)
      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

      public TopicConnection getTopicConnection()
    • setTopic

      public void setTopic(Topic topic)
      INTERNAL: Set the Topic. The Topic is required with the TopicConnectionFactory to obtain connections if the TopicPublisher is not set.
    • getTopic

      public Topic getTopic()