psdi.iface.jms

Class JMSClient

  • java.lang.Object
    • psdi.iface.jms.JMSClient
  • Direct Known Subclasses:
    JMSConsumer, JMSProducer, JMSQueueBrowser


    public abstract class JMSClient
    extends java.lang.Object
    Abstract base class for all JMS clients - for both Topics and Queues. Responsible for handling the Session and transactional details.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected java.lang.String conFactoryName
      The JNDI name of the ConnectionFactory.
      protected javax.jms.Connection conn
      The Connection handle obtained from the ConnectionFactory.
      protected javax.jms.Destination destinationHandle
      The javax.jms.Destination [Queue, Topic] for the JMS client
      protected java.lang.String destinationName
      The JNDI name of the javax.jms.Destination [Queue, Topic] to which the client will connect.
      protected java.lang.String destinationType
      The type of Destination the client is connecting to.
      protected java.util.Properties env
      The env properties to get an InitialContext.
      protected boolean isExternalSession
      Indicates if its an externally owned Session or this JMS client owned Session.
      static java.lang.String JMS_LOGGER
      The JMS logger.
      protected static MXLogger jmsLogger
      JMS Logger
      static int NO_TX
      Setting this mode will result in non transacted JMS client Session.
      protected java.lang.String providerPassword 
      protected java.lang.String providerUserName 
      static java.lang.String QUEUE
      Queue Destination type
      protected javax.jms.Session session
      The JMS client Session.
      static int SESSION_TX
      Setting this mode will result in transacted JMS client session.
      static java.lang.String TOPIC
      Topic Destination type
      protected int txMode
      The transaction mode for the JMS client Session.
      protected boolean valid
      Indicates if the JMS client is still having a live Session to the JMS provider.
    • Constructor Summary

      Constructors 
      Modifier Constructor and Description
      protected JMSClient(java.lang.String destinationName, java.lang.String conFactoryName, int txMode, java.util.Properties env) 
      protected JMSClient(java.lang.String destinationName, java.lang.String conFactoryName, int txMode, java.util.Properties env, java.lang.String providerUserName, java.lang.String providerPassword) 
    • Field Detail

      • NO_TX

        public static final int NO_TX
        Setting this mode will result in non transacted JMS client Session. Use thid mode when the client will be invoked in JTA context.
        See Also:
        Constant Field Values
      • SESSION_TX

        public static final int SESSION_TX
        Setting this mode will result in transacted JMS client session.
        See Also:
        Constant Field Values
      • QUEUE

        public static final java.lang.String QUEUE
        Queue Destination type
        See Also:
        Constant Field Values
      • TOPIC

        public static final java.lang.String TOPIC
        Topic Destination type
        See Also:
        Constant Field Values
      • destinationType

        protected java.lang.String destinationType
        The type of Destination the client is connecting to.
      • JMS_LOGGER

        public static final java.lang.String JMS_LOGGER
        The JMS logger.
        See Also:
        Constant Field Values
      • providerUserName

        protected java.lang.String providerUserName
      • providerPassword

        protected java.lang.String providerPassword
      • txMode

        protected int txMode
        The transaction mode for the JMS client Session.
      • valid

        protected boolean valid
        Indicates if the JMS client is still having a live Session to the JMS provider.
      • session

        protected javax.jms.Session session
        The JMS client Session.
      • conn

        protected javax.jms.Connection conn
        The Connection handle obtained from the ConnectionFactory. The JMS client uses this to conect to the JMS provider.
      • destinationName

        protected java.lang.String destinationName
        The JNDI name of the javax.jms.Destination [Queue, Topic] to which the client will connect.
      • destinationHandle

        protected javax.jms.Destination destinationHandle
        The javax.jms.Destination [Queue, Topic] for the JMS client
      • conFactoryName

        protected java.lang.String conFactoryName
        The JNDI name of the ConnectionFactory. The JMS client uses this to get a Connection handle.
      • env

        protected java.util.Properties env
        The env properties to get an InitialContext. If this attribute is set it will used for creating a new InitialContext as below: InitialContext ctx = new InitialContext(env). This context will be used to lookup the JNDI tree to get the administered objects like Destination and ConnectionFactory. The common properties that can be provided are as below: Context.PROVIDER_URL - the JMS providers URL Context.INITIAL_CONTEXT_FACTORY - the Initial Context Factory class name. If nothing is provided all default valus are picked from the running process [J2EE server].
      • isExternalSession

        protected boolean isExternalSession
        Indicates if its an externally owned Session or this JMS client owned Session.
      • jmsLogger

        protected static final MXLogger jmsLogger
        JMS Logger
    • Constructor Detail

      • JMSClient

        protected JMSClient(java.lang.String destinationName,
                            java.lang.String conFactoryName,
                            int txMode,
                            java.util.Properties env)
                     throws MXException
        Parameters:
        destinationName - the JNDI name of the Destination.
        conFactoryName - the JNDI name of the ConnectionFactory.
        txMode - the Transaction mode - NO_TX[default] or SESSION_TX
        env - The env that would be used to create the IntialContext.
        Throws:
        MXException
      • JMSClient

        protected JMSClient(java.lang.String destinationName,
                            java.lang.String conFactoryName,
                            int txMode,
                            java.util.Properties env,
                            java.lang.String providerUserName,
                            java.lang.String providerPassword)
                     throws MXException
        Parameters:
        destinationName - the JNDI name of the Destination.
        conFactoryName - the JNDI name of the ConnectionFactory.
        txMode - the Transaction mode - NO_TX[default] or SESSION_TX
        env - The env that would be used to create the IntialContext.
        providerUserName - The provider connection user.
        providerPassword - The provider connection password.
        Throws:
        MXException
    • Method Detail

      • setDestination

        protected void setDestination()
                               throws javax.naming.NamingException
        Looks up the Destination from the JNDI tree.
        Throws:
        javax.naming.NamingException
      • getProviderUserName

        public java.lang.String getProviderUserName()
        Returns:
        the provider connection username
      • getProviderPassword

        public java.lang.String getProviderPassword()
        Returns:
        the provider connection password
      • getSession

        @Deprecated
        public javax.jms.Session getSession()
        Deprecated. 
        This method funtionality been replaced by createClientInSession().
        Returns:
        JMS Session used by this client.
      • createClientInSession

        public abstract JMSClient createClientInSession()
                                                 throws MXException
        Creates another JMSClient of the same type in this clients Session. This is used for making the this client and the newly created client to work off the same Session and hence be in the same JMS transaction context.
        Returns:
        the newly created JMSClient instance.
        Throws:
        MXException
      • createClientInSession

        public abstract JMSClient createClientInSession(java.lang.String destinationName,
                                                        java.util.Properties env)
                                                 throws MXException
        Creates another JMSClient of the same type in this clients Session. This is used for making the this client and the newly created client to work off the same Session and hence be in the same JMS transaction context.
        Returns:
        the newly created JMSClient instance.
        Throws:
        MXException
      • getEnvironment

        public java.util.Properties getEnvironment()
        Returns:
        the env properties used JNDI lookup.
      • getDestinationName

        public java.lang.String getDestinationName()
        Returns:
        the JNDI name of the Queue.
      • isValid

        public boolean isValid()
        Determines if the client is still valid. An invalid client has all its resources released and hence cannot be used for further communication to the JMS provider.
      • close

        public void close()
        Releses all resources that is cached by the client like JMS Session and Connection. If the Session is owned by another client then this operation will not close that Session (and Connection). Calling this method on the originating client (which created the Session and Connection) will close these resources.
      • rollbackTx

        public void rollbackTx()
                        throws MXException
        Rollback the JMS Session transaction. Will do nothing if the trsansaction mode is NO_TX.
        Throws:
        MXException
      • commitTx

        public void commitTx()
                      throws MXException
        Commits the JMS Session transaction. Will do nothing if the trsansaction mode is NO_TX.
        Throws:
        MXException
      • invalidate

        protected void invalidate()
        Invalidates the jms client. After this call the client cannot be used to communicate with the JMS provider.
        Throws:
        javax.naming.NamingException
      • createSession

        protected void createSession(boolean transacted)
                              throws javax.naming.NamingException,
                                     javax.jms.JMSException
        Creates a JMS Session.
        Parameters:
        transacted - indicates if the Session is transacted or not.
        Throws:
        javax.naming.NamingException
        javax.jms.JMSException
      • createConnection

        protected javax.jms.Connection createConnection(java.lang.String conFactoryJNDIName)
                                                 throws javax.naming.NamingException,
                                                        javax.jms.JMSException
        Create the JMS Connection from the configured ConnectionFactory.
        Parameters:
        conFactoryJNDIName - the JNDI name of the ConnectionFactory.
        Returns:
        Connection a Connection from the configured ConnectionFactory
        Throws:
        javax.naming.NamingException
        javax.jms.JMSException