Class JMSTopicRemoteConnection

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Runnable

    public class JMSTopicRemoteConnection
    extends BroadcastRemoteConnection
    implements java.lang.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)
    Author:
    Steven Vo
    See Also:
    Serialized Form
    • Field Detail

      • topicConnectionFactory

        protected javax.jms.TopicConnectionFactory topicConnectionFactory
      • topic

        protected javax.jms.Topic topic
      • isLocal

        protected boolean isLocal
      • topicConnection

        protected javax.jms.TopicConnection topicConnection
      • topicSession

        protected javax.jms.TopicSession topicSession
      • subscriber

        protected javax.jms.TopicSubscriber subscriber
      • WAIT_ON_ERROR_RECEIVING_JMS_MESSAGE

        public static long WAIT_ON_ERROR_RECEIVING_JMS_MESSAGE
    • Constructor Detail

      • JMSTopicRemoteConnection

        public JMSTopicRemoteConnection​(RemoteCommandManager rcm,
                                        javax.jms.TopicConnectionFactory topicConnectionFactory,
                                        javax.jms.Topic topic,
                                        boolean isLocalConnectionBeingCreated,
                                        boolean reuseJMSTopicPublisher)
                                 throws javax.jms.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.
        Parameters:
        rcm -
        Throws:
        javax.jms.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
        Parameters:
        rcm -
        See Also:
        onMessage(javax.jms.Message)
    • Method Detail

      • isLocal

        public boolean isLocal()
        INTERNAL: Indicates whether connection is local (subscriber) or external (publisher).
      • executeCommandInternal

        protected java.lang.Object executeCommandInternal​(java.lang.Object command)
                                                   throws java.lang.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:
        java.lang.Exception
      • onMessage

        public void onMessage​(javax.jms.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 javax.jms.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:
        javax.jms.JMSException
      • logDebugJMSTopic

        protected java.lang.String logDebugJMSTopic​(javax.jms.Message message)
                                             throws javax.jms.JMSException
        INTERNAL:
        Throws:
        javax.jms.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 java.lang.Runnable
      • 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​(javax.jms.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 javax.jms.TopicPublisher getPublisher()
      • setSuscriber

        public void setSuscriber​(javax.jms.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 javax.jms.TopicSubscriber getSubscriber()
      • setTopicSession

        public void setTopicSession​(javax.jms.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 javax.jms.TopicSession getTopicSession()
      • setTopicConnectionFactory

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

        public javax.jms.TopicConnection getTopicConnectionFactory()
      • setTopicConnection

        public void setTopicConnection​(javax.jms.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 javax.jms.TopicConnection getTopicConnection()
      • setTopic

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

        public javax.jms.Topic getTopic()