Class WmClusterSessionImpl

    • Field Detail

      • subSessions

        protected java.util.Vector<WmSessionImpl> subSessions
      • policy

        protected int policy
      • map

        protected java.util.HashMap<java.lang.String,​WmSessionImpl> map
      • random

        protected java.util.Random random
      • currentBrokerURL

        protected java.lang.String currentBrokerURL
      • activeSubSessions

        protected java.util.Set<WmSessionImpl> activeSubSessions
      • sharedReadWriteLock

        protected java.util.concurrent.locks.ReentrantReadWriteLock sharedReadWriteLock
      • sharedQueue

        protected java.util.concurrent.LinkedBlockingQueue<WmMessageImpl> sharedQueue
    • Constructor Detail

      • WmClusterSessionImpl

        protected WmClusterSessionImpl​(WmConnectionImpl connection)
        Default constructor for subclasses.
      • WmClusterSessionImpl

        protected WmClusterSessionImpl​(WmClusterConnectionImpl connection,
                                       boolean transacted,
                                       boolean isXA,
                                       int acknowledgeMode)
                                throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
    • Method Detail

      • createSubSession

        public WmSessionImpl createSubSession​(WmConnectionImpl conn)
                                       throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • start

        public void start()
                   throws javax.jms.JMSException
        Description copied from class: WmSessionImpl
        Starts synchronous and asynchronous message delivery. Called by Connection.start().
        Overrides:
        start in class WmSessionImpl
        Throws:
        javax.jms.JMSException
      • stop

        public void stop()
                  throws javax.jms.JMSException
        Description copied from class: WmSessionImpl
        Stops synchronous and asynchronous message delivery. Called by Connection.stop().
        Overrides:
        stop in class WmSessionImpl
        Throws:
        javax.jms.JMSException
      • getSubSessions

        public java.util.Vector<WmSessionImpl> getSubSessions()
      • getCurrentBrokerURL

        public java.lang.String getCurrentBrokerURL()
      • setCurrentBrokerURL

        public void setCurrentBrokerURL​(java.lang.String brokerUrl)
      • close

        public void close()
                   throws javax.jms.JMSException
        Closes the subsessions and will be blocked until all session close calls return.
        Specified by:
        close in interface javax.jms.Session
        Overrides:
        close in class WmSessionImpl
        Throws:
        javax.jms.JMSException
      • setMessageQueue

        public void setMessageQueue​(WmSessionQueue queue)
        Added to change the implementation of the WmSessionQueue to the WmClusterSessionQueueImpl incase of cluster sessions
        Overrides:
        setMessageQueue in class WmSessionImpl
        Parameters:
        queue -
      • commit

        public void commit()
                    throws javax.jms.JMSException
        Description copied from class: WmSessionImpl
        Commits all messages done in this transaction and releases any locks currently held.
        Specified by:
        commit in interface javax.jms.Session
        Overrides:
        commit in class WmSessionImpl
        Throws:
        javax.jms.JMSException - if the JMS provider fails to commit the transaction due to some internal error.
        javax.jms.TransactionRolledBackException - if the transaction is rolled back due to some internal error during commit.
        javax.jms.IllegalStateException - if the method is not called by a transacted session.
      • recover

        public void recover()
                     throws javax.jms.JMSException
        Stops message delivery in this cluster session, and restarts message delivery with the oldest unacknowledged message.
        Specified by:
        recover in interface javax.jms.Session
        Overrides:
        recover in class WmSessionImpl
        Throws:
        javax.jms.JMSException - if the JMS provider fails to stop and restart message delivery due to some internal error.
        javax.jms.IllegalStateException - if the method is called by a transacted session.
      • rollback

        public void rollback()
                      throws javax.jms.JMSException
        Description copied from class: WmSessionImpl
        Rolls back any messages done in this transaction and releases any locks currently held.
        Specified by:
        rollback in interface javax.jms.Session
        Overrides:
        rollback in class WmSessionImpl
        Throws:
        javax.jms.JMSException - if the JMS provider fails to roll back the transaction due to some internal error.
        javax.jms.IllegalStateException - if the method is not called by a transacted session.
      • clearOnTransactionComplete

        public void clearOnTransactionComplete()
        Clears the currentBrokerURL to mark the transaction complete/rollback.
      • createConsumer

        public javax.jms.MessageConsumer createConsumer​(javax.jms.Destination destination,
                                                        java.lang.String messageSelector,
                                                        boolean noLocal)
                                                 throws javax.jms.JMSException
        Creates MessageConsumer for the specified destination, using a message selector. This method can specify whether messages published by its own connection should be delivered to it, if the destination is a topic.

        Since Queue and Topic both inherit from Destination, they can be used in the destination parameter to create a MessageConsumer.

        A client uses a MessageConsumer object to receive messages that have been published to a destination.

        In some cases, a connection may both publish and subscribe to a topic. The consumer noLocal attribute allows a consumer to inhibit the delivery of messages published by its own connection. The default value for this attribute is False. The noLocal value must be supported by destinations that are topics.

        Specified by:
        createConsumer in interface javax.jms.Session
        Overrides:
        createConsumer in class WmSessionImpl
        Parameters:
        destination - the Destination to access
        messageSelector - 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.
        noLocal - - if true, and the destination is a topic, inhibits the delivery of messages published by its own connection. The behavior for noLocal is not specified if the destination is a queue.
        Throws:
        javax.jms.JMSException - if the session fails to create a MessageConsumer due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid destination is specified.
        javax.jms.InvalidSelectorException - if the message selector is invalid.
      • createDurableSubscriber

        public javax.jms.TopicSubscriber createDurableSubscriber​(javax.jms.Topic topic,
                                                                 java.lang.String name,
                                                                 java.lang.String messageSelector,
                                                                 boolean noLocal)
                                                          throws javax.jms.JMSException
        Creates a durable subscriber to the specified topic, using a message selector and specifying whether messages published by its own connection should be delivered to it.

        If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it uses a durable TopicSubscriber. The JMS provider retains a record of this durable subscription and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable subscriber or they have expired.

        Sessions with durable subscribers must always provide the same client identifier. In addition, each client must specify a name which uniquely identifies (within client identifier) each durable subscription it creates. Only one session at a time can have a TopicSubscriber for a particular durable subscription. An inactive durable subscriber is one that exists but does not currently have a message consumer associated with it.

        A client can change an existing durable subscription by creating a durable TopicSubscriber with the same name and a new topic and/or message selector. Changing a durable subscriber is equivalent to unsubscribing (deleting) the old one and creating a new one.

        Specified by:
        createDurableSubscriber in interface javax.jms.Session
        Overrides:
        createDurableSubscriber in class WmSessionImpl
        Parameters:
        topic - the non-temporary Topic to subscribe to
        name - the name used to identify this subscription
        messageSelector - 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.
        noLocal - if set, inhibits the delivery of messages published by its own connection
        Throws:
        javax.jms.JMSException - if the session fails to create a subscriber due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid topic is specified.
        javax.jms.InvalidSelectorException - if the message selector is invalid.
      • createBrowser

        public javax.jms.QueueBrowser createBrowser​(javax.jms.Queue queue,
                                                    java.lang.String messageSelector)
                                             throws javax.jms.JMSException
        Creates a QueueBrowser object to peek at the messages on the specified cluster queue using a message selector.
        Specified by:
        createBrowser in interface javax.jms.Session
        Overrides:
        createBrowser in class WmSessionImpl
        Parameters:
        queue - the queue to access
        messageSelector - 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.
        Throws:
        javax.jms.JMSException - if the session fails to create a browser due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid destination is specified
        javax.jms.InvalidSelectorException - if the message selector is invalid.
      • createQueueBrowserImpl

        protected WmQueueBrowserImpl createQueueBrowserImpl​(WmQueueImpl queue,
                                                            java.lang.String messageSelector)
                                                     throws javax.jms.JMSException
        Creates a queue implementation instance.
        Overrides:
        createQueueBrowserImpl in class WmSessionImpl
        Parameters:
        queue -
        messageSelector -
        Throws:
        javax.jms.JMSException
      • createTemporaryQueue

        public javax.jms.TemporaryQueue createTemporaryQueue()
                                                      throws javax.jms.JMSException
        Creates a TemporaryQueue object. Its lifetime will be that of the Connection unless it is deleted earlier.
        Specified by:
        createTemporaryQueue in interface javax.jms.Session
        Overrides:
        createTemporaryQueue in class WmSessionImpl
        Returns:
        a temporary queue identity
        Throws:
        javax.jms.JMSException - if the session fails to create a temporary queue due to some internal error.
      • createTemporaryQueue

        public javax.jms.TemporaryQueue createTemporaryQueue​(java.lang.String queueName)
                                                      throws javax.jms.JMSException
        Overrides:
        createTemporaryQueue in class WmSessionImpl
        Throws:
        javax.jms.JMSException
      • createTemporaryTopic

        public javax.jms.TemporaryTopic createTemporaryTopic()
                                                      throws javax.jms.JMSException
        Creates a TemporaryTopic object. Its lifetime will be that of the Connection unless it is deleted earlier.
        Specified by:
        createTemporaryTopic in interface javax.jms.Session
        Overrides:
        createTemporaryTopic in class WmSessionImpl
        Returns:
        a temporary topic identity
        Throws:
        javax.jms.JMSException - if the session fails to create a temporary topic due to some internal error.
      • createTemporaryTopic

        public javax.jms.TemporaryTopic createTemporaryTopic​(javax.jms.Destination destination)
                                                      throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • publish

        public void publish​(WmMessageImpl message,
                            int deliveryMode,
                            boolean deliver)
                     throws javax.jms.JMSException
        Publishes a message to one of the JMS connections. Overwrite the superclass publish logics.
        Overrides:
        publish in class WmSessionImpl
        Parameters:
        message -
        deliveryMode -
        deliver -
        Throws:
        javax.jms.JMSException
      • publishToWorker

        public void publishToWorker​(WmMessageImpl[] messages,
                                    int deliveryMode,
                                    boolean deliver,
                                    java.lang.String brokerURL,
                                    boolean overrideClusterPolicy,
                                    boolean fallBackToPolicy)
                             throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • getRemainingBrokersToPublish

        public java.util.List<java.lang.String> getRemainingBrokersToPublish()
                                                                      throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • getNextBrokerToPublish

        public java.util.List<java.lang.String> getNextBrokerToPublish()
                                                                throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • publish

        public void publish​(WmMessageImpl[] messages,
                            int deliveryMode,
                            boolean deliver)
                     throws javax.jms.JMSException
        Publishes a message to one of the JMS connections. Overwrite the superclass publish logics.
        Overrides:
        publish in class WmSessionImpl
        Parameters:
        messages -
        deliveryMode -
        deliver -
        Throws:
        javax.jms.JMSException
      • initMultiSendBestEffortSeeder

        protected int[] initMultiSendBestEffortSeeder​(int size)
      • selectPrimaryWithRotation

        protected void selectPrimaryWithRotation​(java.lang.Object[] arr)
      • sessionAcknowledge

        public void sessionAcknowledge()
                                throws javax.jms.JMSException
        Overrides:
        sessionAcknowledge in class WmSessionImpl
        Throws:
        javax.jms.JMSException
      • sessionAcknowledge

        public void sessionAcknowledge​(boolean preAck)
                                throws javax.jms.JMSException
        Acknowledge all received but unacknowledged messages on this cluster session. Only takes effect if the session is in CLIENT_ACKNOWLEDGE acknowledgment mode. Called by WmMessageImpl.acknowledge().
        Throws:
        javax.jms.JMSException
      • unsubscribe

        public void unsubscribe​(java.lang.String name)
                         throws javax.jms.JMSException
        Unsubscribes a durable subscription that has been created by the cluster client.

        This method deletes the state being maintained on behalf of the subscriber by the cluster. * @param name the name used to identify this subscription

        Specified by:
        unsubscribe in interface javax.jms.Session
        Overrides:
        unsubscribe in class WmSessionImpl
        Parameters:
        name - the name used to identify this subscription
        Throws:
        javax.jms.JMSException - if the session fails to unsubscribe to the durable subscription due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid subscription name is specified.
      • unsubscribe

        public void unsubscribe​(java.lang.String name,
                                boolean force)
                         throws javax.jms.JMSException
        Unsubscribes a durable subscription that has been created by the cluster client.

        This method deletes the state being maintained on behalf of the subscriber by the Cluster.

        Overrides:
        unsubscribe in class WmSessionImpl
        Parameters:
        name - the name used to identify this subscription
        force - true to forcibly unsubscribe even if the subscriber has consumed messages that are a part of the pending transaction or has not been acknowledged in the session
        Throws:
        javax.jms.JMSException - if the session fails to unsubscribe to the durable subscription due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid subscription name is specified.
      • createDurableSubscriber

        public javax.jms.TopicSubscriber createDurableSubscriber​(javax.jms.Topic topic,
                                                                 java.lang.String name)
                                                          throws javax.jms.JMSException
        Description copied from class: WmSessionImpl
        Creates a durable subscriber to the specified topic.

        If a client needs to receive all the messages published on a topic, including the ones published while the subscriber is inactive, it uses a durable TopicSubscriber. The JMS provider retains a record of this durable subscription and insures that all messages from the topic's publishers are retained until they are acknowledged by this durable subscriber or they have expired.

        Sessions with durable subscribers must always provide the same client identifier. In addition, each client must specify a name that uniquely identifies (within client identifier) each durable subscription it creates. Only one session at a time can have a TopicSubscriber for a particular durable subscription.

        A client can change an existing durable subscription by creating a durable TopicSubscriber with the same name and a new topic and/or message selector. Changing a durable subscriber is equivalent to unsubscribing (deleting) the old one and creating a new one.

        In some cases, a connection may both publish and subscribe to a topic. The subscriber noLocal attribute allows a subscriber to inhibit the delivery of messages published by its own connection. The default value for this attribute is false.

        Specified by:
        createDurableSubscriber in interface javax.jms.Session
        Overrides:
        createDurableSubscriber in class WmSessionImpl
        Parameters:
        topic - the non-temporary Topic to subscribe to
        name - the name used to identify this subscription
        Throws:
        javax.jms.JMSException - if the session fails to create a subscriber due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid topic is specified.
      • checkState

        public void checkState()
                        throws javax.jms.JMSException
        Overrides:
        checkState in class WmSessionImpl
        Throws:
        javax.jms.JMSException
      • createReceiver

        public javax.jms.QueueReceiver createReceiver​(javax.jms.Queue queue)
                                               throws javax.jms.JMSException
        Creates a QueueReceiver object to receive messages from the specified queues in the cluster.
        Overrides:
        createReceiver in class WmSessionImpl
        Parameters:
        queue - the Queue to access
        Throws:
        javax.jms.JMSException - if the cluster session fails to create a receiver due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid queue is specified.
      • createReceiver

        public javax.jms.QueueReceiver createReceiver​(javax.jms.Queue queue,
                                                      java.lang.String messageSelector)
                                               throws javax.jms.JMSException
        Creates a QueueReceiver object to receive messages from the specified cluster queue using a message selector.
        Overrides:
        createReceiver in class WmSessionImpl
        Parameters:
        queue - the Queue to access
        messageSelector - 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.
        Throws:
        javax.jms.JMSException - if the session fails to create a receiver due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid queue is specified.
        javax.jms.InvalidSelectorException - if the message selector is invalid.
      • createBrowser

        public javax.jms.QueueBrowser createBrowser​(javax.jms.Queue queue)
                                             throws javax.jms.JMSException
        Creates a QueueBrowser object to peek at the messages on the specified queue on the cluster.
        Specified by:
        createBrowser in interface javax.jms.Session
        Overrides:
        createBrowser in class WmSessionImpl
        Parameters:
        queue - the queue to access
        Throws:
        javax.jms.JMSException - if the session fails to create a browser due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid destination is specified
      • checkCreateDurableConsumer

        protected void checkCreateDurableConsumer​(javax.jms.Destination destination)
                                           throws javax.jms.JMSException
        Overrides:
        checkCreateDurableConsumer in class WmSessionImpl
        Throws:
        javax.jms.JMSException
      • createConsumer

        public javax.jms.MessageConsumer createConsumer​(javax.jms.Destination destination)
                                                 throws javax.jms.JMSException
        Creates a MessageConsumer for the specified destinations on the Broker Cluster. Since Queue and Topic both inherit from Destination, they can be used in the destination parameter to create a MessageConsumer.
        Specified by:
        createConsumer in interface javax.jms.Session
        Overrides:
        createConsumer in class WmSessionImpl
        Parameters:
        destination - the Destination to access.
        Throws:
        javax.jms.JMSException - if the session fails to create a consumer due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid destination is specified.
      • createConsumer

        public javax.jms.MessageConsumer createConsumer​(javax.jms.Destination destination,
                                                        java.lang.String messageSelector)
                                                 throws javax.jms.JMSException
        Creates a MessageConsumer for the specified destination, on the Broker Cluster using a message selector. Since Queue and Topic both inherit from Destination, they can be used in the destination parameter to create a MessageConsumer.

        A client uses a MessageConsumer object to receive messages that have been sent to a destination.

        Specified by:
        createConsumer in interface javax.jms.Session
        Overrides:
        createConsumer in class WmSessionImpl
        Parameters:
        destination - the Destination to access
        messageSelector - 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.
        Throws:
        javax.jms.JMSException - if the session fails to create a MessageConsumer due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid destination is specified.
        javax.jms.InvalidSelectorException - if the message selector is invalid.
      • createSubscriber

        public javax.jms.TopicSubscriber createSubscriber​(javax.jms.Topic topic)
                                                   throws javax.jms.JMSException
        Creates a nondurable subscriber to the specified topics on the cluster.

        A client uses a TopicSubscriber object to receive messages that have been published to a topic.

        Overrides:
        createSubscriber in class WmSessionImpl
        Parameters:
        topic - the Topic to subscribe to
        Throws:
        javax.jms.JMSException - if the session fails to create a subscriber due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid topic is specified.
      • createSubscriber

        public javax.jms.TopicSubscriber createSubscriber​(javax.jms.Topic topic,
                                                          java.lang.String messageSelector,
                                                          boolean noLocal)
                                                   throws javax.jms.JMSException
        Creates a nondurable subscriber to the specified topic on the Broker Cluster, using a message selector or specifying whether messages published by its own connection should be delivered to it.

        Messages filtered out by a subscriber's message selector will never be delivered to the subscriber. From the subscriber's perspective, they do not exist. * @param topic the Topic to subscribe to on the cluster

        Overrides:
        createSubscriber in class WmSessionImpl
        Parameters:
        messageSelector - 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.
        noLocal - if set, inhibits the delivery of messages published by its own connection
        topic - the Topic to subscribe to
        Throws:
        javax.jms.JMSException - if the session fails to create a subscriber due to some internal error.
        javax.jms.InvalidDestinationException - if an invalid topic is specified.
        javax.jms.InvalidSelectorException - if the message selector is invalid.
      • getTransacted

        public boolean getTransacted()
                              throws javax.jms.JMSException
        Indicates whether the cluster session is in transacted mode.
        Specified by:
        getTransacted in interface javax.jms.Session
        Overrides:
        getTransacted in class WmSessionImpl
        Returns:
        true if the cluster session is in transacted mode
        Throws:
        javax.jms.JMSException - if the JMS provider fails to return the transaction mode due to some internal error.
      • isXA

        public boolean isXA()
                     throws javax.jms.JMSException
        returns whether the cluster session is in XA mode.
        Throws:
        javax.jms.JMSException
      • setMessageListener

        public void setMessageListener​(javax.jms.MessageListener listener)
                                throws javax.jms.JMSException
        Sets the session's distinguished message listener (optional).

        When the distinguished message listener is set, no other form of message receipt in the session can be used; however, all forms of sending messages are still supported.

        This is an expert facility not used by regular JMS clients.

        Specified by:
        setMessageListener in interface javax.jms.Session
        Overrides:
        setMessageListener in class WmSessionImpl
        Parameters:
        listener - the message listener to associate with this session
        Throws:
        javax.jms.JMSException - if the JMS provider fails to set the message listener due to an internal error.
      • run

        public void run()
        Optional operation, intended to be used only by Application Servers, not by ordinary JMS clients.
        Specified by:
        run in interface java.lang.Runnable
        Specified by:
        run in interface javax.jms.Session
        Overrides:
        run in class WmSessionImpl
      • getMessageListener

        public javax.jms.MessageListener getMessageListener()
                                                     throws javax.jms.JMSException
        Returns the cluster session's distinguished message listener (optional).
        Specified by:
        getMessageListener in interface javax.jms.Session
        Overrides:
        getMessageListener in class WmSessionImpl
        Returns:
        the message listener associated with this cluster session
        Throws:
        javax.jms.JMSException - if the JMS provider fails to get the message listener due to an internal error.
      • createQueue

        public javax.jms.Queue createQueue​(java.lang.String queueName)
                                    throws javax.jms.JMSException
        Creates a queue identity on the Cluster given a Queue name.

        This facility is provided for the rare cases where clients need to dynamically manipulate queue identity. It allows the creation of a queue identity with a provider-specific name. Clients that depend on this ability are not portable.

        Note that this method is not for creating the physical queue. The physical creation of queues is an administrative task and is not to be initiated by the JMS API. The one exception is the creation of temporary queues, which is accomplished with the createTemporaryQueue method.

        Specified by:
        createQueue in interface javax.jms.Session
        Overrides:
        createQueue in class WmSessionImpl
        Parameters:
        queueName - the name of this Queue
        Returns:
        a Queue with the given name
        Throws:
        javax.jms.JMSException - if the session fails to create a queue due to some internal error.
      • createTopic

        public javax.jms.Topic createTopic​(java.lang.String topicName)
                                    throws javax.jms.JMSException
        Creates a topic identity given a Topic name.

        This facility is provided for the rare cases where clients need to dynamically manipulate topic identity. This allows the creation of a topic identity with a provider-specific name. Clients that depend on this ability are not portable.

        Note that this method is not for creating the physical topic. The physical creation of topics is an administrative task and is not to be initiated by the JMS API. The one exception is the creation of temporary topics, which is accomplished with the createTemporaryTopic method.

        Specified by:
        createTopic in interface javax.jms.Session
        Overrides:
        createTopic in class WmSessionImpl
        Parameters:
        topicName - the name of this Topic
        Returns:
        a Topic with the given name
        Throws:
        javax.jms.JMSException - if the session fails to create a topic due to some internal error.
      • getBrokerSessionIfActive

        public WmSessionImpl getBrokerSessionIfActive​(java.lang.String brokerURL)
      • addToSubSessions

        public void addToSubSessions​(WmSessionImpl session)
      • logActiveClusterSessions

        public void logActiveClusterSessions()