Class UserAgent

    • Field Detail

      • serialVersionUID

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

        private static final Logger logger
      • DEBUG

        static final boolean DEBUG
      • interceptorsOUT

        private transient List<MessageInterceptor> interceptorsOUT
        the in and out interceptors list.
      • clientIDs

        private transient Map<Integer,​String> clientIDs
        Map contains the clientID
      • period

        private long period
        period to run the cleaning task, by default 60s.
      • nbMsgsSentToDMQSinceCreation

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

        private transient List<ClientContext> modifiedClientContexts
        The ClientContexts to be saved after a react.
      • modifiedClientSubscriptions

        private transient List<ClientSubscription> modifiedClientSubscriptions
        The ClientSubscriptions to be saved after a react.
      • redeliveryDelay

        private int redeliveryDelay
        The redelivery delay use to wait before re-delivering messages after a deny.
      • dmqId

        private AgentId dmqId
        Identifier of this proxy dead message queue, null for DMQ not set.
      • threshold

        private int threshold
        Threshold above which messages are considered as undeliverable because constantly denied. This value is used as default value at subscription creation. 0 stands for no threshold, -1 for value not set (use default value).
      • nbMaxMsg

        private int nbMaxMsg
        Maximum number of Message store in subscriptions (-1 set no limit). This value is used as default value at subscription creation.
      • contexts

        private Map<Integer,​ClientContext> contexts
        Table of the proxy's ClientContext instances.

        Key: context identifier
        Value: context

      • validCC

        private static Set<CCUID> validCC
        Static collection referencing all valid context in the server. It allows to avoid to reply to request from closed context (JORAM-281).
      • subsTable

        private Map<String,​ClientSubscription> subsTable
        Table holding the ClientSubscription instances.

        Key: subscription name
        Value: client subscription

      • sharedSubs

        private transient Map<String,​UserAgent.SharedCtx> sharedSubs
        Table holding the SharedCtx instances.

        Key: subscription name
        Value: the shared context

      • subsClientIDs

        private Properties subsClientIDs
        Key: subscription name
        Value: clientID
      • recoveredTransactions

        private Map<Xid,​XACnxPrepare> recoveredTransactions
        Table holding the recovered transactions branches.

        Key: transaction identifier
        Value: XACnxPrepare instance

      • topicsTable

        private transient Map<AgentId,​TopicSubscription> topicsTable
        Table holding the TopicSubscription instances.

        Key: topic identifier
        Value: topic subscription

      • messagesTable

        private transient MessageTable messagesTable
        Table holding the subscriptions' messages.

        Key: message identifier
        Value: message

      • activeCtx

        private transient ClientContext activeCtx
        Reference to the active ClientContext instance. Be careful, do not update activeCtx, or activeCtxId, directly. Always used mthods below: resetActiveCtx, addNewActiveCtx and setActiveCtx.
      • connections

        private transient Hashtable<Integer,​ConnectionContext> connections
        Table that contains the user connections: - key = Integer (connection key) - value =
      • keyCounter

        private int keyCounter
        Counter of the connection keys
      • cleaningTask

        private transient WakeUpTask cleaningTask
      • msgTxname

        transient String msgTxname
    • Constructor Detail

      • UserAgent

        protected UserAgent​(String name,
                            boolean fixed,
                            int stamp)
        Used by the Encodable framework
      • UserAgent

        public UserAgent()
        Constructs a UserAgent instance.
    • Method Detail

      • getPeriod

        public long getPeriod()
        Returns the period value of this queue, -1 if not set.
        Specified by:
        getPeriod in interface UserAgentMBean
        Returns:
        the period value of this queue; -1 if not set.
      • setPeriod

        public void setPeriod​(long period)
        Sets or unsets the period for this queue.
        Specified by:
        setPeriod in interface UserAgentMBean
        Parameters:
        period - The period value to be set or -1 for unsetting previous value.
      • getRedeliveryDelay

        public int getRedeliveryDelay()
        Gets the redelivery delay.
        Specified by:
        getRedeliveryDelay in interface UserAgentMBean
        Returns:
        the redeliveryDelay
      • setRedeliveryDelay

        public void setRedeliveryDelay​(int redeliveryDelay)
        Sets the redelivery delay.
        Specified by:
        setRedeliveryDelay in interface UserAgentMBean
        Parameters:
        redeliveryDelay - the redeliveryDelay to set
      • getDMQId

        public String getDMQId()
        Returns the default DMQ for subscription of this user.
        Specified by:
        getDMQId in interface UserAgentMBean
        Returns:
        the default DMQ for subscription of this user.
      • getThreshold

        public int getThreshold()
        Returns the default threshold for the subscription of this user. 0 stands for no threshold, -1 for value not set.
        Specified by:
        getThreshold in interface UserAgentMBean
        Returns:
        the maximum number of message if set; -1 otherwise.
      • setThreshold

        public void setThreshold​(int threshold)
        Sets the default threshold for the subscription of this user. 0 stands for no threshold, -1 for value not set.
        Specified by:
        setThreshold in interface UserAgentMBean
        Parameters:
        threshold - the threshold to set.
      • getNbMaxMsg

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

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

        protected static void addValidCC​(ClientContext cc)
      • removeValidCC

        protected static void removeValidCC​(ClientContext cc)
      • isValidCC

        public static boolean isValidCC​(AgentId ua,
                                        int ctxid)
      • activeCtxId

        private final int activeCtxId()
        Returns the identifier of the active context. Value -1 means that there's no active context.
      • resetActiveCtx

        private void resetActiveCtx()
      • addNewActiveCtx

        private void addNewActiveCtx​(int key)
      • setActiveCtx

        private void setActiveCtx​(int key)
                           throws StateException
        Updates the reference to the active context.
        Parameters:
        key - Key of the activated context.
        Throws:
        StateException - If the context has actually been closed or lost.
      • agentInitialize

        public void agentInitialize​(boolean firstTime)
                             throws Exception
        (Re)initializes the agent when (re)loading.
        Overrides:
        agentInitialize in class Agent
        Parameters:
        firstTime - true when first called by the factory
        Throws:
        Exception - unspecialized exception
      • agentFinalize

        public void agentFinalize​(boolean lastTime)
        Finalizes the agent before it is garbaged.
        Overrides:
        agentFinalize in class Agent
        Parameters:
        lastTime - true when last called by the factory on agent deletion.
      • react

        public void react​(AgentId from,
                          Notification not)
                   throws Exception
        Overrides the Agent class react method for providing the JMS client proxy with its specific behaviour.

        A JMS proxy specifically reacts to the following notifications:

        • OpenConnectionNot
        Overrides:
        react in class Agent
        Parameters:
        from - agent sending notification
        not - notification to react to
        Throws:
        Exception - unspecialized exception
      • agentSave

        protected void agentSave()
                          throws IOException
        Description copied from class: Agent
        Enables the sub-classes to save their state.
        Overrides:
        agentSave in class Agent
        Throws:
        IOException - if any error occurs.
      • doReact

        private void doReact​(AgentId from,
                             GetClientSubscriptions not)
        Used to get number of local subscribers to 'from'. This number is sent as an Admin reply.
        Parameters:
        from - should be a Topic agent ID.
        not - contains the original Admin not sent to 'from'.
      • doReact

        private void doReact​(AgentId from,
                             ReconnectSubscribersNot not)
        Sends reconnection messages to one or more subscribers.
        Parameters:
        from -
        not -
      • doSetPeriod

        private void doSetPeriod​(long period)
      • doReact

        private void doReact​(OpenConnectionNot not)
        Registers and starts the UserConnection.
      • doReact

        private void doReact​(ReturnConnectionNot not)
        Differs the reply because the connection key counter must be saved before the OpenConnectionNot returns.
      • doReact

        private void doReact​(RequestNot not)
      • doReact

        private void doReact​(SendReplyNot not)
        Notification sent by local agents (destinations) indicating that the proxy can reply to a client.
        Parameters:
        not -
      • sendNot

        public void sendNot​(AgentId to,
                            Notification not)
        Sends a notification to the specified agent.
        Specified by:
        sendNot in interface ProxyAgentItf
        Parameters:
        to - the identifier of the recipient agent
        not - the notification to send
      • sendToClient

        public void sendToClient​(int key,
                                 AbstractJmsReply reply)
        Sends a reply to the client connected through the specified connection.
        Parameters:
        key - the key of the connection the client is connected through.
        reply - the reply to send to the client.
      • setNoSave

        public void setNoSave()
        Description copied from class: Agent
        Sets the updated field to false so that the agent state is not saved after the current reaction; the field is set back to true for the next reaction.
        Overrides:
        setNoSave in class Agent
      • setSave

        public void setSave()
        Description copied from class: Agent
        Sets the updated field to true so that the agent state is saved after the current reaction.
        Overrides:
        setSave in class Agent
      • setInterceptors

        public void setInterceptors​(Properties prop)
                             throws Exception
        Only call in UserAgent creation.
        Parameters:
        prop - properties
        Throws:
        Exception
      • initialize

        private void initialize​(boolean firstTime)
                         throws Exception
        (Re)initializes the proxy.
        Parameters:
        firstTime -
        Throws:
        Exception - If the proxy state could not be fully retrieved, leading to an inconsistent state.
      • reactToClientRequest

        protected void reactToClientRequest​(int key,
                                            AbstractJmsRequest request,
                                            CallbackNotification callbackNotification)
        Method processing clients requests.

        Some of the client requests are directly forwarded, some others are sent to the proxy so that their processing occurs in a transaction.

        A MomExceptionReply wrapping a DestinationException might be sent back if a target destination can't be identified.

      • reactToClientRequest

        private void reactToClientRequest​(int key,
                                          ProducerMessages req,
                                          CallbackNotification callbackNotification)
                                   throws RequestException
        Forwards the messages sent by the client in a ProducerMessages request as a ClientMessages MOM request directly to a destination, and acknowledges them by sending a ServerReply back.
        Throws:
        RequestException - The destination id is undefined
      • sendToDMQ

        private void sendToDMQ​(Message msg,
                               short messageError)
      • reactToClientRequest

        private void reactToClientRequest​(int key,
                                          ConsumerReceiveRequest req)
                                   throws RequestException
        Either forwards the ConsumerReceiveRequest request as a ReceiveRequest directly to the target queue, or wraps it and sends it to the proxy if destinated to a subscription.
        Throws:
        RequestException - Undefined (null) destination
      • reactToClientRequest

        private void reactToClientRequest​(int key,
                                          ConsumerSetListRequest req)
                                   throws RequestException
        Either forwards the ConsumerSetListRequest request as a ReceiveRequest directly to the target queue, or wraps it and sends it to the proxy if destinated to a subscription.
        Throws:
        RequestException - Undefined (null) destination
      • reactToClientRequest

        private void reactToClientRequest​(int key,
                                          QBrowseRequest req)
                                   throws RequestException
        Forwards the client's QBrowseRequest request as a BrowseRequest MOM request directly to a destination.
        Throws:
        RequestException - Undefined (null) destination
      • reactToClientRequest

        private void reactToClientRequest​(int key,
                                          JmsRequestGroup request)
      • doReact

        private void doReact​(int key,
                             AbstractJmsRequest request,
                             CallbackNotification callbackNotification)
        Distributes the client requests to the appropriate reactions.

        The proxy accepts the following requests:

        • GetAdminTopicRequest
        • CnxConnectRequest
        • CnxStartRequest
        • CnxStopRequest
        • SessCreateTQRequest
        • SessCreateTTRequest
        • ConsumerSubRequest
        • ConsumerUnsubRequest
        • ConsumerCloseSubRequest
        • ConsumerSetListRequest
        • ConsumerUnsetListRequest
        • ConsumerReceiveRequest
        • ConsumerAckRequest
        • ConsumerDenyRequest
        • SessAckRequest
        • SessDenyRequest
        • TempDestDeleteRequest
        • XACnxPrepare
        • XACnxCommit
        • XACnxRollback
        • XACnxRecoverRequest

        A JmsExceptReply is sent back to the client when an exception is thrown by the reaction.

      • doReact

        private void doReact​(int key,
                             GetAdminTopicRequest req)
                      throws AccessException
        Method implementing the reaction to a GetAdminTopicRequest requesting the identifier of the local admin topic.

        It simply sends back a GetAdminTopicReply holding the admin topic identifier.

        Throws:
        AccessException - If the requester is not an administrator.
      • doReact

        private void doReact​(int key,
                             CnxConnectRequest req)
                      throws DestinationException
        Method implementing the reaction to a CnxConnectRequest requesting the key of the active context.

        It simply sends back a ConnectReply holding the active context's key.

        Throws:
        DestinationException - In case of a first administrator context, if the local administration topic reference is not available.
      • doReact

        private void doReact​(CnxStartRequest req)
        Method implementing the proxy reaction to a CnxStartRequest requesting to start a context.

        This method sends the pending ConsumerMessages replies, if any.

      • doReact

        private void doReact​(CnxStopRequest req)
        Method implementing the JMS proxy reaction to a CnxStopRequest requesting to stop a context.

        This method sends a ServerReply back.

      • doReact

        private void doReact​(SessCreateDestRequest req)
                      throws RequestException
        Method implementing the JMS proxy reaction to a SessCreateDestRequest requesting the creation of a destination.

        Creates the queue, sends it a SetRightRequest for granting WRITE access to all, and wraps a SessCreateTDReply in a SyncReply notification it sends to itself. This latest action's purpose is to preserve causality.

        Creates the topic, sends it a SetRightRequest for granting WRITE access to all, and wraps a SessCreateTDReply in a SyncReply notification it sends to itself. This latest action's purpose is to preserve causality.

        Throws:
        RequestException - If the destination could not be deployed.
      • doReact

        private void doReact​(ConsumerSetListRequest req)
                      throws DestinationException
        Method implementing the JMS proxy reaction to a ConsumerSetListRequest notifying the creation of a client listener.

        Sets the listener for the subscription, launches a delivery sequence.

        Throws:
        DestinationException - If the subscription does not exist.
      • doReact

        private void doReact​(ConsumerReceiveRequest req)
                      throws DestinationException
        Method implementing the proxy reaction to a ConsumerReceiveRequest instance, requesting a message from a subscription.

        This method registers the request and launches a delivery sequence.

        Throws:
        DestinationException - If the subscription does not exist.
      • doReact

        private void doReact​(SessAckRequest req)
        Method implementing the JMS proxy reaction to a SessAckRequest acknowledging messages either on a queue or on a subscription.
      • doReact

        private void doReact​(SessDenyRequest req)
        Method implementing the JMS proxy reaction to a SessDenyRequest denying messages either on a queue or on a subscription.
      • doReact

        private void doReact​(ConsumerAckRequest req)
        Method implementing the JMS proxy reaction to a ConsumerAckRequest acknowledging a message either on a queue or on a subscription.
      • doReact

        private void doReact​(ConsumerDenyRequest req)
        Method implementing the JMS proxy reaction to a ConsumerDenyRequest denying a message either on a queue or on a subscription.

        This request is acknowledged when destinated to a queue.

      • doReact

        private void doReact​(TempDestDeleteRequest req)
        Method implementing the JMS proxy reaction to a TempDestDeleteRequest request for deleting a temporary destination.

        This method sends a fr.dyade.aaa.agent.DeleteNot to the destination and acknowledges the request.

      • deleteTemporaryDestination

        private void deleteTemporaryDestination​(AgentId destId)
      • doReact

        private void doReact​(XACnxPrepare req)
                      throws StateException
        Method implementing the JMS proxy reaction to an XACnxPrepare request holding messages and acknowledgements produced in an XA transaction.
        Throws:
        StateException - If the proxy has already received a prepare order for the same transaction.
      • doReact

        private void doReact​(XACnxCommit req)
                      throws StateException
        Method implementing the JMS proxy reaction to an XACnxCommit request committing the operations performed in a given transaction.

        This method actually processes the objects sent at the prepare phase, and acknowledges the request.

        Throws:
        StateException - If committing an unknown transaction.
      • doReact

        private void doReact​(XACnxRollback req)
        Method implementing the JMS proxy reaction to an XACnxRollback request rolling back the operations performed in a given transaction.
      • doReact

        private void doReact​(XACnxRecoverRequest req)
                      throws StateException
        Reacts to a XACnxRecoverRequest request requesting the identifiers of the prepared transactions.

        Returns the identifiers of the recovered transactions, puts the prepared data into the active context for future commit or rollback.

        Throws:
        StateException - If a recovered transaction branch is already present in the context.
      • doReact

        private void doReact​(SyncReply not)
        Method implementing the JMS proxy reaction to a SyncReply notification sent by itself, wrapping a reply to be sent to a client.
      • doReact

        private void doReact​(int key,
                             CnxCloseRequest req)
        The method closes a given context by denying the non acknowledged messages delivered to this context, and deleting its temporary subscriptions and destinations.
      • getKeyByValue

        private <K,​V> K getKeyByValue​(Map<K,​V> map,
                                            V value)
      • doReact

        private void doReact​(int key,
                             AddClientIDRequest req)
                      throws Exception
        Method implementing the reaction to a AddClientIDRequest instance add the clientID value of a connection.
        Throws:
        Exception
      • doFwd

        private void doFwd​(AgentId from,
                           AbstractReplyNot rep)
        Distributes the JMS replies to the appropriate reactions.

        JMS proxies react the following replies:

        • QueueMsgReply
        • BrowseReply
        • SubscribeReply
        • TopicMsgsReply
        • ExceptionReply
      • doFwd

        private void doFwd​(AgentId from,
                           QueueMsgReply rep)
        Actually forwards a QueueMsgReply coming from a destination as a ConsumerMessages destinated to the requesting client.

        If the corresponding context is stopped, stores the ConsumerMessages for later delivery.

      • doFwd

        private void doFwd​(BrowseReply rep)
        Actually forwards a BrowseReply coming from a destination as a QBrowseReply destinated to the requesting client.
      • doFwd

        private void doFwd​(SubscribeReply rep)
        Forwards the topic's SubscribeReply as a ServerReply.
      • getMsgTxname

        protected final String getMsgTxname()
      • setMsgTxName

        protected final void setMsgTxName​(Message msg)
      • doFwd

        private void doFwd​(AgentId from,
                           TopicMsgsReply rep)
        Method implementing the proxy reaction to a TopicMsgsReply. This method allows the distribution of messages received from the topic to the different local subscriptions.
      • delivers

        private final void delivers​(String subName,
                                    ClientSubscription sub)
        If the subscription is active, launching a delivery sequence.
        Parameters:
        subName -
        sub -
      • persistDeliveryTimeMessage

        private final void persistDeliveryTimeMessage​(Message msg)
      • doReact

        private void doReact​(TopicDeliveryTimeNot not)
        Processes a delayed message ready to be delivered.
        Parameters:
        not -
      • doReact

        private void doReact​(AgentId from,
                             ExceptionReply rep)
        Actually forwards an ExceptionReply coming from a destination as a MomExceptionReply destinated to the requesting client.

        If the wrapped exception is an AccessException thrown by a Topic as a reply to a SubscribeRequest, removing the corresponding subscriptions.

      • getSubMBeanName

        private String getSubMBeanName​(String name)
      • doReact

        private void doReact​(AdminReplyNot reply)
        An AdminReply acknowledges the setting of a temporary destination; nothing needs to be done.
      • doReact

        private void doReact​(UnknownAgent uA)
        Method implementing the JMS proxy reaction to an UnknownAgent notification notifying that a destination does not exist or is deleted.

        If it notifies of a deleted topic, the method removes the corresponding subscriptions. If the wrapped request is messages sending, the messages are sent to the DMQ.

        A JmsExceptReply is sent to the concerned requester.

        This case might also happen when sending a ClientMessages to a dead message queue. In that case, the invalid DMQ identifier is set to null.

      • getSubscriptionNames

        public String[] getSubscriptionNames()
        Returns the list of subscriptions for this user. Each subscription is identified by its unique 'symbolic' name.
        Specified by:
        getSubscriptionNames in interface UserAgentMBean
        Returns:
        The list of subscriptions for this user.
      • deleteSubscriptionMessage

        public void deleteSubscriptionMessage​(String subName,
                                              String msgId)
        Deletes a particular pending message in a subscription. The subscription is identified by its unique name, the message is pointed out through its unique identifier.
        Parameters:
        subName - The subscription unique name.
        msgId - The unique message's identifier.
      • doReply

        private void doReply​(AbstractJmsReply reply)
        Method used for sending an AbstractJmsReply back to an external client within the active context.
        Parameters:
        reply - The reply to send.
      • getClientContext

        protected ClientContext getClientContext​(int ctxId)
      • cleanPendingMessages

        protected void cleanPendingMessages​(long currentTime)
      • delete

        public void delete()
        Description copied from class: Agent
        Permits this agent to destroy itself. If necessary, this method should be overloaded to work properly.
        Specified by:
        delete in interface AgentMBean
        Specified by:
        delete in interface UserAgentMBean
        Overrides:
        delete in class Agent
      • deleteProxy

        private void deleteProxy​(FwdAdminRequestNot not)
        This method deletes the proxy by notifying its connected clients, denying the non acknowledged messages, deleting the temporary destinations, removing the subscriptions.
        Parameters:
        not - the request.
      • updateSubscriptionToTopic

        private boolean updateSubscriptionToTopic​(AgentId topicId,
                                                  int contextId,
                                                  int requestId)
        Updates the proxy's subscription to a topic.
        Parameters:
        topicId - Identifier of the topic to subscribe to.
        contextId - Identifier of the subscription context.
        requestId - Identifier of the subscription request.
        Returns:
        true if a SubscribeRequest has been sent to the topic.
      • updateSubscriptionToTopic

        private boolean updateSubscriptionToTopic​(AgentId topicId,
                                                  int contextId,
                                                  int requestId,
                                                  boolean asyncSub)
        Updates the proxy's subscription to a topic.
        Parameters:
        topicId - Identifier of the topic to subscribe to.
        contextId - Identifier of the subscription context.
        requestId - Identifier of the subscription request.
        asyncSub - asynchronous subscription request.
        Returns:
        true if a SubscribeRequest has been sent to the topic.
      • getNbMsgsSentToDMQSinceCreation

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

        private void saveModifiedClientContexts()
      • saveModifiedClientSubscriptions

        private void saveModifiedClientSubscriptions()