1 18 package org.apache.activemq.tool.spi; 19 20 import org.apache.activemq.ActiveMQConnectionFactory; 21 22 import javax.jms.ConnectionFactory ; 23 import java.util.Properties ; 24 25 public class ActiveMQPojoSPI implements SPIConnectionFactory { 26 public static final String KEY_BROKER_URL = "brokerUrl"; 27 public static final String KEY_USERNAME = "username"; 28 public static final String KEY_PASSWORD = "password"; 29 public static final String KEY_CLIENT_ID = "clientID"; 30 31 public static final String KEY_ASYNC_SEND = "asyncSend"; 32 public static final String KEY_ASYNC_DISPATCH = "asyncDispatch"; 33 public static final String KEY_ASYNC_SESSION = "asyncSession"; 34 public static final String KEY_CLOSE_TIMEOUT = "closeTimeout"; 35 public static final String KEY_COPY_MSG_ON_SEND = "copyMsgOnSend"; 36 public static final String KEY_DISABLE_TIMESTAMP = "disableTimestamp"; 37 public static final String KEY_DEFER_OBJ_SERIAL = "deferObjSerial"; 38 public static final String KEY_OPTIM_ACK = "optimAck"; 39 public static final String KEY_OPTIM_DISPATCH = "optimDispatch"; 40 public static final String KEY_PREFETCH_QUEUE = "prefetchQueue"; 41 public static final String KEY_PREFETCH_TOPIC = "prefetchTopic"; 42 public static final String KEY_USE_COMPRESSION = "useCompression"; 43 public static final String KEY_USE_RETROACTIVE = "useRetroactive"; 44 45 public ConnectionFactory createConnectionFactory(Properties settings) throws Exception { 46 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); 47 configureConnectionFactory(factory, settings); 48 return factory; 49 } 50 51 public void configureConnectionFactory(ConnectionFactory jmsFactory, Properties settings) throws Exception { 52 ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory)jmsFactory; 53 String setting; 54 55 setting = settings.getProperty(KEY_BROKER_URL); 56 if (setting != null && setting.length() > 0) { 57 factory.setBrokerURL(setting); 58 } 59 60 setting = settings.getProperty(KEY_USERNAME); 61 if (setting != null && setting.length() > 0) { 62 factory.setUserName(setting); 63 } 64 65 setting = settings.getProperty(KEY_PASSWORD); 66 if (setting != null && setting.length() > 0) { 67 factory.setPassword(setting); 68 } 69 70 setting = settings.getProperty(KEY_CLIENT_ID); 71 if (setting != null && setting.length() > 0) { 72 factory.setClientID(setting); 73 } 74 75 setting = settings.getProperty(KEY_ASYNC_SEND); 76 if (setting != null && setting.length() > 0) { 77 factory.setUseAsyncSend(Boolean.getBoolean(setting)); 78 } 79 80 setting = settings.getProperty(KEY_ASYNC_DISPATCH); 81 if (setting != null && setting.length() > 0) { 82 factory.setDispatchAsync(Boolean.getBoolean(setting)); 83 } 84 85 setting = settings.getProperty(KEY_ASYNC_SESSION); 86 if (setting != null && setting.length() > 0) { 87 factory.setAlwaysSessionAsync(Boolean.getBoolean(setting)); 88 } 89 90 setting = settings.getProperty(KEY_CLOSE_TIMEOUT); 91 if (setting != null && setting.length() > 0) { 92 factory.setCloseTimeout(Integer.parseInt(setting)); 93 } 94 95 setting = settings.getProperty(KEY_COPY_MSG_ON_SEND); 96 if (setting != null && setting.length() > 0) { 97 factory.setCopyMessageOnSend(Boolean.getBoolean(setting)); 98 } 99 100 setting = settings.getProperty(KEY_DISABLE_TIMESTAMP); 101 if (setting != null && setting.length() > 0) { 102 factory.setDisableTimeStampsByDefault(Boolean.getBoolean(setting)); 103 } 104 105 setting = settings.getProperty(KEY_DEFER_OBJ_SERIAL); 106 if (setting != null && setting.length() > 0) { 107 factory.setObjectMessageSerializationDefered(Boolean.getBoolean(setting)); 108 } 109 110 setting = settings.getProperty(KEY_OPTIM_ACK); 111 if (setting != null && setting.length() > 0) { 112 factory.setOptimizeAcknowledge(Boolean.getBoolean(setting)); 113 } 114 115 setting = settings.getProperty(KEY_OPTIM_DISPATCH); 116 if (setting != null && setting.length() > 0) { 117 factory.setOptimizedMessageDispatch(Boolean.getBoolean(setting)); 118 } 119 120 setting = settings.getProperty(KEY_PREFETCH_QUEUE); 121 if (setting != null && setting.length() > 0) { 122 factory.getPrefetchPolicy().setQueuePrefetch(Integer.parseInt(setting)); 123 } 124 125 setting = settings.getProperty(KEY_PREFETCH_TOPIC); 126 if (setting != null && setting.length() > 0) { 127 factory.getPrefetchPolicy().setTopicPrefetch(Integer.parseInt(setting)); 128 } 129 130 setting = settings.getProperty(KEY_USE_COMPRESSION); 131 if (setting != null && setting.length() > 0) { 132 factory.setUseCompression(Boolean.getBoolean(setting)); 133 } 134 135 setting = settings.getProperty(KEY_USE_RETROACTIVE); 136 if (setting != null && setting.length() > 0) { 137 factory.setUseRetroactiveConsumer(Boolean.getBoolean(setting)); 138 } 139 } 140 } 141 | Popular Tags |