use of org.wso2.carbon.apimgt.common.jms.JMSTaskManager in project carbon-apimgt by wso2.
the class JMSTaskManagerFactory method createTaskManagerForService.
/**
* Create a ServiceTaskManager for the service passed in and its corresponding JMSConnectionFactory
*
* @param jcf JMS Connection factory definition
* @param name JMS consumer name
* @param workerPool Shared thread pool from the Listener
* @param svc JNDI context properties and other general properties
* @return JMSTaskManager instance
*/
public static JMSTaskManager createTaskManagerForService(JMSConnectionFactory jcf, String name, WorkerPool workerPool, Map<String, String> svc) {
Map<String, String> cf = jcf.getParameters();
JMSTaskManager stm = new JMSTaskManager();
stm.setJmsConsumerName(name);
stm.addJmsProperties(cf);
stm.addJmsProperties(svc);
stm.setConnFactoryJNDIName(getRqdStringProperty(JMSConstants.PARAM_CONFAC_JNDI_NAME, svc, cf));
String destName = getOptionalStringProperty(JMSConstants.PARAM_DESTINATION, svc, cf);
if (destName == null) {
destName = name;
}
stm.setDestinationJNDIName(destName);
stm.setDestinationType(getDestinationType(svc, cf));
if (getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf) != null && getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf)) {
stm.setDurableSubscriberClientId(getRqdStringProperty(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID, svc, cf));
}
stm.setJmsSpec11(getJMSSpecVersion(svc, cf));
stm.setTransactionality(getTransactionality(svc, cf));
stm.setCacheUserTransaction(getOptionalBooleanProperty(BaseConstants.PARAM_CACHE_USER_TXN, svc, cf));
stm.setUserTransactionJNDIName(getOptionalStringProperty(BaseConstants.PARAM_USER_TXN_JNDI_NAME, svc, cf));
stm.setSessionTransacted(getOptionalBooleanProperty(JMSConstants.PARAM_SESSION_TRANSACTED, svc, cf));
stm.setSessionAckMode(getSessionAck(svc, cf));
stm.setMessageSelector(getOptionalStringProperty(JMSConstants.PARAM_MSG_SELECTOR, svc, cf));
stm.setSubscriptionDurable(getOptionalBooleanProperty(JMSConstants.PARAM_SUB_DURABLE, svc, cf));
stm.setDurableSubscriberName(getOptionalStringProperty(JMSConstants.PARAM_DURABLE_SUB_NAME, svc, cf));
stm.setCacheLevel(getCacheLevel(svc, cf));
stm.setPubSubNoLocal(getOptionalBooleanProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL, svc, cf));
Integer value = getOptionalIntProperty(JMSConstants.PARAM_RCV_TIMEOUT, svc, cf);
if (value != null) {
stm.setReceiveTimeout(value);
}
value = getOptionalIntProperty(JMSConstants.PARAM_CONCURRENT_CONSUMERS, svc, cf);
if (value != null) {
stm.setConcurrentConsumers(value);
}
value = getOptionalIntProperty(JMSConstants.PARAM_MAX_CONSUMERS, svc, cf);
if (value != null) {
stm.setMaxConcurrentConsumers(value);
}
value = getOptionalIntProperty(JMSConstants.PARAM_IDLE_TASK_LIMIT, svc, cf);
if (value != null) {
stm.setIdleTaskExecutionLimit(value);
}
value = getOptionalIntProperty(JMSConstants.PARAM_MAX_MSGS_PER_TASK, svc, cf);
if (value != null) {
stm.setMaxMessagesPerTask(value);
}
value = getOptionalIntProperty(JMSConstants.PARAM_RECON_INIT_DURATION, svc, cf);
if (value != null) {
stm.setInitialReconnectDuration(value);
}
value = getOptionalIntProperty(JMSConstants.PARAM_RECON_MAX_DURATION, svc, cf);
if (value != null) {
stm.setMaxReconnectDuration(value);
}
Double dValue = getOptionalDoubleProperty(JMSConstants.PARAM_RECON_FACTOR, svc, cf);
if (dValue != null) {
stm.setReconnectionProgressionFactor(dValue);
}
stm.setWorkerPool(workerPool);
// remove processed properties from property bag
stm.removeJmsProperties(JMSConstants.PARAM_CONFAC_JNDI_NAME);
stm.removeJmsProperties(JMSConstants.PARAM_DESTINATION);
stm.removeJmsProperties(JMSConstants.PARAM_JMS_SPEC_VER);
stm.removeJmsProperties(BaseConstants.PARAM_TRANSACTIONALITY);
stm.removeJmsProperties(BaseConstants.PARAM_CACHE_USER_TXN);
stm.removeJmsProperties(BaseConstants.PARAM_USER_TXN_JNDI_NAME);
stm.removeJmsProperties(JMSConstants.PARAM_SESSION_TRANSACTED);
stm.removeJmsProperties(JMSConstants.PARAM_MSG_SELECTOR);
stm.removeJmsProperties(JMSConstants.PARAM_SUB_DURABLE);
stm.removeJmsProperties(JMSConstants.PARAM_DURABLE_SUB_NAME);
stm.removeJmsProperties(JMSConstants.PARAM_CACHE_LEVEL);
stm.removeJmsProperties(JMSConstants.PARAM_PUBSUB_NO_LOCAL);
stm.removeJmsProperties(JMSConstants.PARAM_RCV_TIMEOUT);
stm.removeJmsProperties(JMSConstants.PARAM_CONCURRENT_CONSUMERS);
stm.removeJmsProperties(JMSConstants.PARAM_MAX_CONSUMERS);
stm.removeJmsProperties(JMSConstants.PARAM_IDLE_TASK_LIMIT);
stm.removeJmsProperties(JMSConstants.PARAM_MAX_MSGS_PER_TASK);
stm.removeJmsProperties(JMSConstants.PARAM_RECON_INIT_DURATION);
stm.removeJmsProperties(JMSConstants.PARAM_RECON_MAX_DURATION);
stm.removeJmsProperties(JMSConstants.PARAM_RECON_FACTOR);
stm.removeJmsProperties(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID);
return stm;
}
Aggregations