KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > tool > spi > ActiveMQPojoSPI


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.tool.spi;
19
20 import org.apache.activemq.ActiveMQConnectionFactory;
21
22 import javax.jms.ConnectionFactory JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 public class ActiveMQPojoSPI implements SPIConnectionFactory {
26     public static final String JavaDoc KEY_BROKER_URL = "brokerUrl";
27     public static final String JavaDoc KEY_USERNAME = "username";
28     public static final String JavaDoc KEY_PASSWORD = "password";
29     public static final String JavaDoc KEY_CLIENT_ID = "clientID";
30
31     public static final String JavaDoc KEY_ASYNC_SEND = "asyncSend";
32     public static final String JavaDoc KEY_ASYNC_DISPATCH = "asyncDispatch";
33     public static final String JavaDoc KEY_ASYNC_SESSION = "asyncSession";
34     public static final String JavaDoc KEY_CLOSE_TIMEOUT = "closeTimeout";
35     public static final String JavaDoc KEY_COPY_MSG_ON_SEND = "copyMsgOnSend";
36     public static final String JavaDoc KEY_DISABLE_TIMESTAMP = "disableTimestamp";
37     public static final String JavaDoc KEY_DEFER_OBJ_SERIAL = "deferObjSerial";
38     public static final String JavaDoc KEY_OPTIM_ACK = "optimAck";
39     public static final String JavaDoc KEY_OPTIM_DISPATCH = "optimDispatch";
40     public static final String JavaDoc KEY_PREFETCH_QUEUE = "prefetchQueue";
41     public static final String JavaDoc KEY_PREFETCH_TOPIC = "prefetchTopic";
42     public static final String JavaDoc KEY_USE_COMPRESSION = "useCompression";
43     public static final String JavaDoc KEY_USE_RETROACTIVE = "useRetroactive";
44
45     public ConnectionFactory createConnectionFactory(Properties JavaDoc settings) throws Exception JavaDoc {
46         ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
47         configureConnectionFactory(factory, settings);
48         return factory;
49     }
50
51     public void configureConnectionFactory(ConnectionFactory jmsFactory, Properties JavaDoc settings) throws Exception JavaDoc {
52         ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory)jmsFactory;
53         String JavaDoc 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