Class ClientSubscription

    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        define serialVersionUID for interoperability
        See Also:
        Constant Field Values
      • logger

        private static final Logger logger
      • DEBUG

        private static final boolean DEBUG
      • proxyId

        private AgentId proxyId
        The proxy's agent identifier.
      • proxy

        private transient ProxyAgentItf proxy
        An handle to proxy Agent
      • durable

        private boolean durable
        true if the subscription is durable.
      • topicId

        private AgentId topicId
        The topic identifier.
      • name

        private String name
        The subscription name.
      • selector

        private String selector
        The selector for filtering messages.
      • dmqId

        private AgentId dmqId
        Identifier of the subscriber's dead message queue, null for DMQ not set.
      • threshold

        private int threshold
        Threshold above which messages are considered as undeliverable because constantly denied. 0 stands for no threshold, -1 for value not set (use servers' default value).
      • nbMaxMsg

        private int nbMaxMsg
        Max number of Message stored in the queue (-1 no limit).
      • messageIds

        private transient MessageIdList messageIds
        List of identifiers of the messages to deliver.
      • messageTimeIds

        private transient MessageIdList messageTimeIds
        List of identifiers of the messages delivery time.
      • deliveredIds

        private Map<String,​String> deliveredIds
        Table of delivered messages identifiers.
      • deniedMsgs

        private Map<String,​Integer> deniedMsgs
        Table keeping the denied messages identifiers.
      • contextId

        private transient int contextId
        Identifier of the subscription context.
      • subRequestId

        private transient int subRequestId
        Identifier of the subscription request.
      • noLocal

        private transient boolean noLocal
        true if the subscriber does not wish to consume messages published in the same context.
      • noFiltering

        private transient boolean noFiltering
        true if the subscription does not filter messages in any way.
      • active

        private transient int active
        Give the maximum number of messages per request if the subscription is active, 0 if the subscription is passive.
      • requestId

        private transient int requestId
        Identifier of the request requesting messages, either the listener's request, or a "receive" request.
      • toListener

        private transient boolean toListener
        true if the messages are destinated to a listener.
      • requestExpTime

        private transient long requestExpTime
        Expiration time of the "receive" request, if any.
      • messagesTable

        private transient MessageTable messagesTable
        Proxy messages table. Be careful: currently this table is shared between all subscription.
      • nbMsgsSentToDMQSinceCreation

        private long nbMsgsSentToDMQSinceCreation
        the number of erroneous messages forwarded to the DMQ
      • nbMsgsDeliveredSinceCreation

        private long nbMsgsDeliveredSinceCreation
        the number of delivered messages
      • MAX_NUMBER_OF_MSG_PER_REQUEST_PROPERTY

        public static final String MAX_NUMBER_OF_MSG_PER_REQUEST_PROPERTY
        See Also:
        Constant Field Values
      • MAX_NUMBER_OF_MSG_PER_REQUEST

        public static final int MAX_NUMBER_OF_MSG_PER_REQUEST
      • txName

        private transient String txName
        Transient should be useless, should only be used via the engine thread..
      • modified

        private transient boolean modified
        Transient should be useless, should only be used via the engine thread..
      • clientID

        private String clientID
    • Constructor Detail

      • ClientSubscription

        ClientSubscription()
      • ClientSubscription

        ClientSubscription​(AgentId proxyId,
                           int contextId,
                           int reqId,
                           boolean durable,
                           AgentId topicId,
                           String name,
                           String selector,
                           boolean noLocal,
                           AgentId dmqId,
                           int threshold,
                           int nbMaxMsg,
                           MessageTable messagesTable,
                           String clientID)
                    throws RequestException
        Constructs a ClientSubscription instance.
        Parameters:
        proxyId - Proxy's identifier.
        contextId - Context identifier.
        reqId - Request identifier.
        durable - true for a durable subscription.
        topicId - Topic identifier.
        name - Subscription's name.
        selector - Selector for filtering messages.
        noLocal - true for not consuming messages published within the same proxy's context.
        dmqId - Identifier of the proxy's dead message queue, if any.
        threshold - Proxy's threshold value, if any.
        messagesTable - Proxy's messages table.
        clientID - the clientID
        Throws:
        RequestException
    • Method Detail

      • getTopicId

        public AgentId getTopicId()
        Returns the identifier of the subscription topic.
      • getThreshold

        public int getThreshold()
        Returns the threshold above which messages are considered undeliverable because constantly denied.
        Specified by:
        getThreshold in interface ClientSubscriptionMBean
        Returns:
        the threshold if set; -1 otherwise.
      • setThreshold

        public void setThreshold​(int threshold)
        Sets the subscription's threshold value.
      • getNbMaxMsg

        public int getNbMaxMsg()
        Returns the maximum number of message for the subscription. If the limit is unset the method returns -1.
        Specified by:
        getNbMaxMsg in interface ClientSubscriptionMBean
        Returns:
        the maximum number of message for subscription if set; -1 otherwise.
      • setNbMaxMsg

        public void setNbMaxMsg​(int nbMaxMsg)
        Sets the maximum number of message for the subscription.
        Specified by:
        setNbMaxMsg in interface ClientSubscriptionMBean
        Parameters:
        nbMaxMsg - the maximum number of message for subscription (-1 set no limit).
      • getPendingMessageCount

        public int getPendingMessageCount()
        Returns the number of pending messages for the subscription.
        Specified by:
        getPendingMessageCount in interface ClientSubscriptionMBean
        Returns:
        The number of pending message for the subscription.
      • getPendingDeliveryTimeMessageCount

        public int getPendingDeliveryTimeMessageCount()
        Returns the number of pending delivery time messages for the subscription.
        Returns:
        The number of pending delivery time message for the subscription.
      • getDeliveredIds

        Map<String,​String> getDeliveredIds()
        Only used in tests.
      • getActive

        public int getActive()
        Returns the maximum number of messages per request if the subscription is active.
        Specified by:
        getActive in interface ClientSubscriptionMBean
      • setActive

        void setActive​(int active)
      • setModified

        private void setModified()
      • getClientID

        String getClientID()
        Only used in tests.
      • getDeliveredMessageCount

        public int getDeliveredMessageCount()
        Returns the number of messages delivered and waiting for acknowledge.
        Specified by:
        getDeliveredMessageCount in interface ClientSubscriptionMBean
        Returns:
        The number of messages delivered and waiting for acknowledge.
      • getMessageIds

        public String[] getMessageIds()
        Returns the list of message's identifiers for the subscription.
        Specified by:
        getMessageIds in interface ClientSubscriptionMBean
        Returns:
        the list of message's identifiers for the subscription.
      • reinitialize

        void reinitialize​(MessageTable messagesTable,
                          List<Message> persistedMessages,
                          boolean denyDeliveredMessages)
        Re-initializes the client subscription.
        Parameters:
        messagesTable - Proxy's table where storing the messages.
        persistedMessages - Proxy's persisted messages.
        denyDeliveredMessages - Denies already delivered messages.
      • reactivate

        void reactivate​(int contextId,
                        int reqId,
                        AgentId topicId,
                        String selector,
                        boolean noLocal)
        Reactivates the subscription.
        Parameters:
        contextId - Re-activation context.
        reqId - Re-activation request identifier.
        topicId - Topic identifier.
        selector - Selector for filtering messages.
        noLocal - true for not consuming messages published within the same proxy's context.
      • deactivate

        void deactivate​(boolean denies)
        De-activates the subscription.
        Parameters:
        denies - denies the non acknowledged messages.
      • setListener

        void setListener​(int requestId)
        Sets a listener.
        Parameters:
        requestId - Identifier of the listener request.
      • unsetListener

        void unsetListener()
        Unsets the listener.
      • setReceiver

        void setReceiver​(int requestId,
                         long timeToLive)
        Sets a receiver request.
        Parameters:
        requestId - Identifier of the "receive" request.
        timeToLive - Request's time to live value.
      • unsetReceiver

        void unsetReceiver()
        Unsets a receiver request.
      • setDMQId

        void setDMQId​(AgentId dmqId)
        Sets the subscription's dead message queue identifier.
      • scheduleDeliveryTimeMessage

        void scheduleDeliveryTimeMessage​(Message message)
        schedule the delivery time message.
        Parameters:
        message - the message.
      • removeMessagesTimeIds

        void removeMessagesTimeIds​(String msgId)
      • browseNewMessages

        void browseNewMessages​(List<Message> newMessages)
        Browses messages and keeps those which will have to be delivered to the subscriber.
      • deliver

        ConsumerMessages deliver()
        Launches a delivery sequence, either for a listener, or for a receiver.
      • acknowledge

        void acknowledge​(Iterator<String> acks)
        Acknowledges messages.
      • acknowledge

        void acknowledge​(String id)
      • deny

        void deny​(Iterator<String> denies,
                  boolean redelivered)
        Denies messages.
        Parameters:
        denies - all ids of the messages to deny
        redelivered - true if redelivered.
      • deny

        private void deny​(Iterator<String> denies,
                          boolean remove,
                          boolean redelivered)
        Denies the messages.
        Parameters:
        denies - all ids of the messages to deny
        remove - true to remove messages from deliveredIds map. Must be false when denies iterates over deliveredIds map keys, to avoid a ConcurrentModificationException.
        redelivered - true if redelivered.
      • deleteMessages

        void deleteMessages()
        Decreases the subscription's messages acknowledgement expectations, deletes those not to be consumed anymore.
      • isUndeliverable

        private boolean isUndeliverable​(int deliveryAttempts)
        Returns true if a given message is considered as undeliverable, because its delivery count matches the subscription's threshold, if any, or the server's default threshold value (if any).
      • getNbMsgsSentToDMQSinceCreation

        public long getNbMsgsSentToDMQSinceCreation()
        Description copied from interface: ClientSubscriptionMBean
        Returns the number of erroneous messages forwarded to the DMQ since creation time of this subscription.
        Specified by:
        getNbMsgsSentToDMQSinceCreation in interface ClientSubscriptionMBean
        Returns:
        the number of erroneous messages forwarded to the DMQ.
      • getSubscriptionMessage

        Message getSubscriptionMessage​(String msgId)
      • deleteMessage

        public void deleteMessage​(String msgId)
        Description copied from interface: ClientSubscriptionMBean
        Deletes a particular pending message in the subscription. The message is pointed out through its unique identifier.
        Specified by:
        deleteMessage in interface ClientSubscriptionMBean
        Parameters:
        msgId - The unique message's identifier.
      • removeMessage

        Message removeMessage​(String msgId)
        Removes a particular pending message in the subscription. The message is pointed out through its unique identifier.
        Parameters:
        msgId - The unique message's identifier.
      • decrAckCounters

        private void decrAckCounters​(String msgId,
                                     Message message)
      • getMessagesView

        public List<MessageView> getMessagesView()
        Only used from shell-mom MOMCommandsImpl.
      • getTransactionPrefix

        public static String getTransactionPrefix​(AgentId proxyId)
      • getTxName

        private final String getTxName()
      • save

        public void save()
      • delete

        public void delete()
      • getEncodableClassId

        public int getEncodableClassId()
        Description copied from interface: Encodable
        Returns a unique class identifier.
        Specified by:
        getEncodableClassId in interface Encodable
        Returns:
        a unique class identifier
      • getEncodedSize

        public int getEncodedSize()
                           throws Exception
        Description copied from interface: Encodable
        Returns the size of the byte array that results from the encoding of this object.
        Specified by:
        getEncodedSize in interface Encodable
        Returns:
        the size of the encoded byte array
        Throws:
        Exception - if an error occurs
      • encode

        public void encode​(Encoder encoder)
                    throws Exception
        Description copied from interface: Encodable
        Encodes the content of this object
        Specified by:
        encode in interface Encodable
        Parameters:
        encoder - the encoder to be used for the encoding
        Throws:
        Exception - if an error occurs
      • decode

        public void decode​(Decoder decoder)
                    throws Exception
        Description copied from interface: Encodable
        Decodes the content of this object
        Specified by:
        decode in interface Encodable
        Parameters:
        decoder - the decoder to be used for the decoding
        Throws:
        Exception - if an error occurs