Class Helper

    • Field Detail

      • logger

        private static final Logger logger
      • DEBUG

        private static final boolean DEBUG
      • BYTES_CLASS_NAME

        private static final String BYTES_CLASS_NAME
      • BUNDLE_JNDI_FACTORY_REUSE_ADDRESS_PROP

        public static final String BUNDLE_JNDI_FACTORY_REUSE_ADDRESS_PROP
        See Also:
        Constant Field Values
      • BUNDLE_JNDI_CACHE_UPDATE_PERIOD_PROPERTY

        public static final String BUNDLE_JNDI_CACHE_UPDATE_PERIOD_PROPERTY
        See Also:
        Constant Field Values
      • JNDI_CACHE_UPDATE_PERIOD_DEFAULT

        public static final int JNDI_CACHE_UPDATE_PERIOD_DEFAULT
        See Also:
        Constant Field Values
      • BUNDLE_MAX_NUMBER_OF_CONTEXT_PROPERTY

        public static final String BUNDLE_MAX_NUMBER_OF_CONTEXT_PROPERTY
        See Also:
        Constant Field Values
      • MAX_NUMBER_OF_CONTEXT_DEFAULT

        public static final int MAX_NUMBER_OF_CONTEXT_DEFAULT
        See Also:
        Constant Field Values
      • maxNumberOfContext

        public static int maxNumberOfContext
      • clientIdPrefix

        public static String clientIdPrefix
      • jndiUpdatePeriod

        private static int jndiUpdatePeriod
        JNDI cache update period in ms. If 0, the cache is not use, if it is less than 0 it is never updated.
      • rand

        private Random rand
        This random generator is used to built random identifiers of producer and consumer. May be we should use SecureRandom.
      • counter

        private static final AtomicLong counter
      • helper

        private static Helper helper
      • cfName

        private String cfName
      • globalIdleTimeout

        private long globalIdleTimeout
      • restUser

        private String restUser
      • restPass

        private String restPass
      • IPAllowed

        private String IPAllowed
      • lastCleanTime

        private long lastCleanTime
      • cleanerPeriod

        private long cleanerPeriod
      • cfhtLastUpdate

        private long cfhtLastUpdate
      • desthtLastUpdate

        private long desthtLastUpdate
    • Constructor Detail

      • Helper

        private Helper()
    • Method Detail

      • getRestClientCtxs

        Map<String,​RestClientContext> getRestClientCtxs()
        Only used by CleanerTask to remove unused contexts.
        Returns:
        the restClientCtxs
      • getInstance

        public static Helper getInstance()
      • getRestPass

        public String getRestPass()
        Returns:
        the Rest/Jms password
      • setGlobalProperties

        public void setGlobalProperties​(org.osgi.framework.BundleContext bundleContext)
                                 throws NamingException
        Throws:
        NamingException
      • checkIPAddress

        public boolean checkIPAddress​(String addr)
        Check if the addr is authorized (all local address is authorized).
        Parameters:
        addr - The ip address to check
        Returns:
        true if authorized
        Throws:
        UnknownHostException
        SocketException
      • authenticationRequired

        public boolean authenticationRequired()
      • setConnectionFactoryName

        public void setConnectionFactoryName​(String cfName)
        Parameters:
        cfName - the connection factory name
      • setCleanerPeriod

        public void setCleanerPeriod​(long cleanerPeriod)
      • setLastCleanTime

        public void setLastCleanTime()
      • closeAll

        public void closeAll()
        Should only be called in stop.
      • close

        public void close​(String clientId)
        Specified by:
        close in interface HelperMBean
        Parameters:
        clientId - the client id
      • closeSessionCtx

        public void closeSessionCtx​(String ctxName)
        Parameters:
        ctxName - the producer or consumer name
      • getJNDIcf

        private final jakarta.jms.ConnectionFactory getJNDIcf​(String cfName)
        Returns the value in cache, cleans the cache if needed.
        Parameters:
        cfName -
        Returns:
      • lookupConnectionFactory

        public final jakarta.jms.ConnectionFactory lookupConnectionFactory​(String cfName)
                                                                    throws NamingException
        Lookup the ConnectionFactory
        Parameters:
        cfName - the ConnectionFactory name
        Returns:
        the ConnectionFactory if found
        Throws:
        NamingException
      • getJNDIdest

        private final jakarta.jms.Destination getJNDIdest​(String destName)
        Returns the value in cache, cleans the cache if needed.
        Parameters:
        destName -
        Returns:
      • lookupDestination

        public final jakarta.jms.Destination lookupDestination​(String destName)
                                                        throws NamingException
        Lookup the destination
        Parameters:
        destName - the destination name
        Returns:
        the destination if found
        Throws:
        NamingException
      • lookup

        private Object lookup​(String name)
        Retrieves ConnectionFactory and Destination objects from JNDI. This method converts 'old' javax.jms references to the new Jakarta JMS API. TODO (AF): We should replace this code by a call to Helper.retrieveJakartaJMSObjectFromJNDI method (org.ow2.joram.jndi package).
        Parameters:
        jndiName -
        Returns:
        Throws:
        Exception
      • createProducer

        public String createProducer​(String userName,
                                     String password,
                                     String clientId,
                                     String prodName,
                                     jakarta.jms.Destination dest,
                                     int sessionMode,
                                     int deliveryMode,
                                     long deliveryDelay,
                                     String correlationID,
                                     int priority,
                                     long timeToLive,
                                     String destName,
                                     boolean isQueue,
                                     long idleTimeout)
                              throws Exception
        Create a producer
        Parameters:
        userName - the user name
        password - the password
        clientId - the client id
        prodName - the producer name
        dest - the JMS destination
        sessionMode - the session mode
        deliveryMode - the delivery mode
        deliveryDelay - the delivery delay
        correlationID - the correlation id
        priority - the priority
        timeToLive - the time to live
        destName - need for the jms create
        isQueue -
        idleTimeout -
        Returns:
        the producer name
        Throws:
        Exception
      • createConsumer

        public String createConsumer​(String userName,
                                     String password,
                                     String clientId,
                                     String consName,
                                     jakarta.jms.Destination dest,
                                     int sessionMode,
                                     String messageSelector,
                                     boolean noLocal,
                                     boolean durable,
                                     boolean shared,
                                     String name,
                                     String destName,
                                     boolean isQueue,
                                     long idleTimeout)
                              throws Exception
        Create a consumer
        Parameters:
        userName - the user name
        password - the password
        clientId - the client id
        consName - the consumer name
        dest - the JMS destination
        sessionMode - the session mode
        messageSelector -
        noLocal -
        durable -
        shared -
        name -
        destName - need for the jms create
        isQueue -
        idleTimeout -
        Returns:
        the consumer name
        Throws:
        Exception
      • send

        public long send​(String prodName,
                         String type,
                         Map<String,​Object> jmsHeaders,
                         Map<String,​Object> jmsProps,
                         Object jmsBody,
                         int deliveryMode,
                         long deliveryDelay,
                         int priority,
                         long timeToLive,
                         String correlationID)
                  throws Exception
        Parameters:
        prodName -
        type -
        jmsHeaders -
        jmsProps -
        jmsBody -
        deliveryMode -
        deliveryDelay -
        priority -
        timeToLive -
        correlationID -
        Returns:
        Throws:
        Exception
      • consume

        public jakarta.jms.Message consume​(String consName,
                                           long timeout,
                                           boolean noLocal,
                                           boolean durable,
                                           boolean shared,
                                           String name,
                                           long msgId)
                                    throws Exception
        Throws:
        Exception
      • createClientId

        public String createClientId()
      • createProducerId

        public String createProducerId()
      • createConsumerId

        public String createConsumerId()
      • getClientContext

        public RestClientContext getClientContext​(String id)
        Returns the context corresponding to the specified identifier. If no matching context exists, try to create one. Be careful, if there is too many existing contexts returns null.
        Parameters:
        id -
        Returns: