Class Helper
- java.lang.Object
-
- org.objectweb.joram.tools.rest.jms.Helper
-
- All Implemented Interfaces:
HelperMBean
public final class Helper extends Object implements HelperMBean
-
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description privateHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacknowledgeAllMsg(String consName)voidacknowledgeMsg(String consName, long id)booleanauthenticationRequired()booleancheckIPAddress(String addr)Check if the addr is authorized (all local address is authorized).voidclose(String clientId)voidcloseAll()Should only be called in stop.voidcloseSessionCtx(String ctxName)voidcommit(String name)jakarta.jms.Messageconsume(String consName, long timeout, boolean noLocal, boolean durable, boolean shared, String name, long msgId)StringcreateClientId()StringcreateConsumer(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)Create a consumerStringcreateConsumerId()StringcreateProducer(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)Create a producerStringcreateProducerId()StringdumpContexts()StringdumpSessions()longgetCleanerPeriod()RestClientContextgetClientContext(String id)Returns the context corresponding to the specified identifier.longgetDefaultIdleTimeout()static HelpergetInstance()StringgetIPAllowed()private jakarta.jms.ConnectionFactorygetJNDIcf(String cfName)Returns the value in cache, cleans the cache if needed.private jakarta.jms.DestinationgetJNDIdest(String destName)Returns the value in cache, cleans the cache if needed.StringgetLastCleanTime()intgetNbContexts()(package private) Map<String,RestClientContext>getRestClientCtxs()Only used by CleanerTask to remove unused contexts.StringgetRestPass()StringgetRestUser()SessionContextgetSessionCtx(String name)(package private) static ObjectgetValue(Map map, String key)private Objectlookup(String name)Retrieves ConnectionFactory and Destination objects from JNDI.jakarta.jms.ConnectionFactorylookupConnectionFactory(String cfName)Lookup the ConnectionFactoryjakarta.jms.DestinationlookupDestination(String destName)Lookup the destinationvoidrollback(String name)longsend(String prodName, String type, Map<String,Object> jmsHeaders, Map<String,Object> jmsProps, Object jmsBody, int deliveryMode, long deliveryDelay, int priority, long timeToLive, String correlationID)voidsetCleanerPeriod(long cleanerPeriod)voidsetConnectionFactoryName(String cfName)voidsetGlobalProperties(org.osgi.framework.BundleContext bundleContext)voidsetLastCleanTime()(package private) static voidsetMapMessage(Map<String,Object> jsonMap, jakarta.jms.MapMessage msg)
-
-
-
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_CF_PROP
public static final String BUNDLE_CF_PROP
- See Also:
- Constant Field Values
-
BUNDLE_JNDI_FACTORY_INITIAL_PROP
public static final String BUNDLE_JNDI_FACTORY_INITIAL_PROP
- See Also:
- Constant Field Values
-
BUNDLE_JNDI_FACTORY_HOST_PROP
public static final String BUNDLE_JNDI_FACTORY_HOST_PROP
- See Also:
- Constant Field Values
-
BUNDLE_JNDI_FACTORY_PORT_PROP
public static final String BUNDLE_JNDI_FACTORY_PORT_PROP
- See Also:
- Constant Field Values
-
BUNDLE_IDLE_TIMEOUT_PROP
public static final String BUNDLE_IDLE_TIMEOUT_PROP
- See Also:
- Constant Field Values
-
BUNDLE_CLEANER_PERIOD_PROP
public static final String BUNDLE_CLEANER_PERIOD_PROP
- See Also:
- Constant Field Values
-
BUNDLE_JMS_USER
public static final String BUNDLE_JMS_USER
- See Also:
- Constant Field Values
-
BUNDLE_JMS_PASS
public static final String BUNDLE_JMS_PASS
- See Also:
- Constant Field Values
-
BUNDLE_JMS_IP_ALLOWED
public static final String BUNDLE_JMS_IP_ALLOWED
- See Also:
- Constant Field Values
-
BUNDLE_JNDI_FACTORY_TIMEOUT_PROP
public static final String BUNDLE_JNDI_FACTORY_TIMEOUT_PROP
- See Also:
- Constant Field Values
-
BUNDLE_JNDI_FACTORY_LINGER_PROP
public static final String BUNDLE_JNDI_FACTORY_LINGER_PROP
- See Also:
- Constant Field Values
-
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
-
BUNDLE_CLIENTID_PREFIX_PROPERTY
public static final String BUNDLE_CLIENTID_PREFIX_PROPERTY
- See Also:
- Constant Field Values
-
CLIENTID_PREFIX_DEFAULT
public static final String CLIENTID_PREFIX_DEFAULT
- See Also:
- Constant Field Values
-
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.
-
DFLT_CLEANER_PERIOD
public static final int DFLT_CLEANER_PERIOD
- See Also:
- Constant Field Values
-
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
-
ictx
private InitialContext ictx
-
restClientCtxs
private Map<String,RestClientContext> restClientCtxs
-
sessionCtxs
private Map<String,SessionContext> sessionCtxs
-
cfName
private String cfName
-
globalIdleTimeout
private long globalIdleTimeout
-
jndiProps
private Properties jndiProps
-
restUser
private String restUser
-
restPass
private String restPass
-
IPAllowed
private String IPAllowed
-
ipfilter
private IPFilter ipfilter
-
lastCleanTime
private long lastCleanTime
-
cleanerPeriod
private long cleanerPeriod
-
cfhtLastUpdate
private long cfhtLastUpdate
-
desthtLastUpdate
private long desthtLastUpdate
-
-
Method Detail
-
getRestClientCtxs
Map<String,RestClientContext> getRestClientCtxs()
Only used by CleanerTask to remove unused contexts.- Returns:
- the restClientCtxs
-
getInstance
public static Helper getInstance()
-
getRestUser
public String getRestUser()
- Specified by:
getRestUserin interfaceHelperMBean- Returns:
- the Rest/Jms user
-
getRestPass
public String getRestPass()
- Returns:
- the Rest/Jms password
-
setGlobalProperties
public void setGlobalProperties(org.osgi.framework.BundleContext bundleContext) throws NamingException- Throws:
NamingException
-
getIPAllowed
public String getIPAllowed()
- Specified by:
getIPAllowedin interfaceHelperMBean- Returns:
- the IPAllowed
-
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:
UnknownHostExceptionSocketException
-
authenticationRequired
public boolean authenticationRequired()
-
setConnectionFactoryName
public void setConnectionFactoryName(String cfName)
- Parameters:
cfName- the connection factory name
-
setCleanerPeriod
public void setCleanerPeriod(long cleanerPeriod)
-
getCleanerPeriod
public long getCleanerPeriod()
- Specified by:
getCleanerPeriodin interfaceHelperMBean
-
getDefaultIdleTimeout
public long getDefaultIdleTimeout()
- Specified by:
getDefaultIdleTimeoutin interfaceHelperMBean
-
setLastCleanTime
public void setLastCleanTime()
-
getLastCleanTime
public String getLastCleanTime()
- Specified by:
getLastCleanTimein interfaceHelperMBean
-
getNbContexts
public int getNbContexts()
- Specified by:
getNbContextsin interfaceHelperMBean
-
dumpContexts
public String dumpContexts()
- Specified by:
dumpContextsin interfaceHelperMBean
-
dumpSessions
public String dumpSessions()
- Specified by:
dumpSessionsin interfaceHelperMBean
-
closeAll
public void closeAll()
Should only be called in stop.
-
close
public void close(String clientId)
- Specified by:
closein interfaceHelperMBean- 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 namepassword- the passwordclientId- the client idprodName- the producer namedest- the JMS destinationsessionMode- the session modedeliveryMode- the delivery modedeliveryDelay- the delivery delaycorrelationID- the correlation idpriority- the prioritytimeToLive- the time to livedestName- need for the jms createisQueue-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 namepassword- the passwordclientId- the client idconsName- the consumer namedest- the JMS destinationsessionMode- the session modemessageSelector-noLocal-durable-shared-name-destName- need for the jms createisQueue-idleTimeout-- Returns:
- the consumer name
- Throws:
Exception
-
setMapMessage
static final void setMapMessage(Map<String,Object> jsonMap, jakarta.jms.MapMessage msg) throws Exception
- 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()
-
getSessionCtx
public SessionContext getSessionCtx(String name)
-
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:
-
acknowledgeAllMsg
public void acknowledgeAllMsg(String consName) throws Exception
- Throws:
Exception
-
-