KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > FactoryParameters


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2007 ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - 2000 Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (INRIA)
22  * Contributor(s): ScalAgent Distributed Technologies
23  * Benoit Pelletier (Bull SA)
24  */

25 package org.objectweb.joram.client.jms;
26
27 import java.util.Hashtable JavaDoc;
28
29 import javax.naming.Reference JavaDoc;
30 import javax.naming.StringRefAddr JavaDoc;
31
32 /**
33  * A <code>FactoryParameters</code> instance holds a
34  * <code>&lt;XA&gt;ConnectionFactory</code> configuration parameters.
35  */

36 public class FactoryParameters implements java.io.Serializable JavaDoc {
37   /** Name of host hosting the server to create connections with. */
38   private String JavaDoc host;
39   /** Port to be used for accessing the server. */
40   private int port;
41
42   /**
43    * url to connect to joram ha
44    */

45   private String JavaDoc url;
46
47   /**
48    * Duration in seconds during which connecting is attempted (connecting
49    * might take time if the server is temporarily not reachable); the 0 value
50    * is set for connecting only once and aborting if connecting failed.
51    */

52   public int connectingTimer = 0;
53   /**
54    * Duration in seconds during which a JMS transacted (non XA) session might
55    * be pending; above that duration the session is rolled back and closed;
56    * the 0 value means "no timer".
57    */

58   public int txPendingTimer = 0;
59   /**
60    * Period in milliseconds between two ping requests sent by the client
61    * connection to the server; if the server does not receive any ping
62    * request during more than 2 * cnxPendingTimer, the connection is
63    * considered as dead and processed as required.
64    */

65   public int cnxPendingTimer = 0;
66
67   /**
68    * Determines whether the produced messages are asynchronously
69    * sent or not (without or with acknowledgement)
70    * Default is false (with ack).
71    */

72   public boolean asyncSend = false;
73
74   /**
75    * The maximum number of messages that can be
76    * read at once from a queue.
77    * Default is 1.
78    */

79   public int queueMessageReadMax = 1;
80
81   /**
82    * The maximum number of acknowledgements
83    * that can be buffered in
84    * Session.DUPS_OK_ACKNOWLEDGE mode when listening to a topic.
85    * Default is 0.
86    */

87   public int topicAckBufferMax = 0;
88
89   /**
90    * Determines whether client threads
91    * which are using the same connection
92    * are synchronized
93    * in order to group together the requests they
94    * send.
95    */

96   public boolean multiThreadSync = false;
97
98   /**
99    * The maximum time the threads hang if 'multiThreadSync' is true.
100    * Either they wake up (wait time out) or they are notified (by the
101    * first woken up thread).
102    * Default value is 1ms.
103    */

104   public int multiThreadSyncDelay = 1;
105
106   /**
107    * The maximum numbers of threads that hang if 'multiThreadSync' is true.
108    * Default value is 10 waiting threads.
109    */

110   public int multiThreadSyncThreshold = 10;
111
112   /**
113    * This threshold is the maximum messages number over which the
114    * subscription is passivated.
115    * Default is Integer.MAX_VALUE.
116    */

117   public int topicPassivationThreshold = Integer.MAX_VALUE;
118
119   /**
120    * This threshold is the minimum messages number below which the
121    * subscription is activated.
122    * Default is 0.
123    */

124   public int topicActivationThreshold = 0;
125
126   /**
127    * Constructs a <code>FactoryParameters</code> instance.
128    *
129    * @param host Name of host hosting the server to create connections with.
130    * @param port Port to be used for accessing the server.
131    */

132   public FactoryParameters(String JavaDoc host, int port) {
133     this.host = host;
134     this.port = port;
135   }
136
137   /**
138    * Constructs a <code>FactoryParameters</code> instance.
139    *
140    * @param url joram ha url
141    */

142   public FactoryParameters(String JavaDoc url) {
143     this.url = url;
144     host = "";
145     port = -1;
146   }
147
148   /**
149    * Constructs an empty <code>FactoryParameters</code>.
150    */

151   public FactoryParameters() {
152   }
153
154   /**
155    * Returns the name of host hosting the server to create connections with.
156    */

157   public String JavaDoc getHost() {
158     return host;
159   }
160
161   /** Returns the port to be used for accessing the server. */
162   public int getPort() {
163     return port;
164   }
165
166   /**
167    * Returns the url.
168    */

169   public String JavaDoc getUrl() {
170     return url;
171   }
172
173 // public void toReference(Reference ref) {
174
// toReference(ref, "cf");
175
// }
176

177   public void toReference(Reference JavaDoc ref, String JavaDoc prefix) {
178 // if (prefix == null) prefix = "cf";
179

180     ref.add(new StringRefAddr JavaDoc(prefix + ".host", getHost()));
181     ref.add(new StringRefAddr JavaDoc(prefix + ".port",
182                               new Integer JavaDoc(getPort()).toString()));
183
184     ref.add(new StringRefAddr JavaDoc(prefix + ".url", getUrl()));
185     ref.add(new StringRefAddr JavaDoc(prefix + ".cnxT",
186                               new Integer JavaDoc(connectingTimer).toString()));
187     ref.add(new StringRefAddr JavaDoc(prefix + ".txT",
188                               new Integer JavaDoc(txPendingTimer).toString()));
189     ref.add(new StringRefAddr JavaDoc(prefix + ".cnxPT",
190                               new Integer JavaDoc(cnxPendingTimer).toString()));
191     ref.add(new StringRefAddr JavaDoc(prefix + ".asyncSend",
192                               new Boolean JavaDoc(asyncSend).toString()));
193     ref.add(new StringRefAddr JavaDoc(prefix + ".queueMessageReadMax",
194                               new Integer JavaDoc(queueMessageReadMax).toString()));
195     ref.add(new StringRefAddr JavaDoc(prefix + ".topicAckBufferMax",
196                               new Integer JavaDoc(topicAckBufferMax).toString()));
197     ref.add(new StringRefAddr JavaDoc(prefix + ".multiThreadSync",
198                               new Boolean JavaDoc(multiThreadSync).toString()));
199     ref.add(new StringRefAddr JavaDoc(prefix + ".multiThreadSyncDelay",
200                               new Integer JavaDoc(multiThreadSyncDelay).toString()));
201     ref.add(new StringRefAddr JavaDoc(prefix + ".multiThreadSyncThreshold",
202                               new Integer JavaDoc(multiThreadSyncThreshold).toString()));
203     ref.add(new StringRefAddr JavaDoc(prefix + ".topicPassivationThreshold",
204                               new Integer JavaDoc(topicPassivationThreshold).toString()));
205     ref.add(new StringRefAddr JavaDoc(prefix + ".topicActivationThreshold",
206                               new Integer JavaDoc(topicActivationThreshold).toString()));
207   }
208
209 // public void fromReference(Reference ref) {
210
// fromReference(ref, "cf");
211
// }
212

213   public void fromReference(Reference JavaDoc ref, String JavaDoc prefix) {
214 // if (prefix == null) prefix = "cf";
215

216     host = (String JavaDoc) ref.get(prefix + ".host").getContent();
217     port = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".port").getContent()).intValue();
218
219     connectingTimer = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".cnxT").getContent()).intValue();
220     txPendingTimer = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".txT").getContent()).intValue();
221     cnxPendingTimer = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".cnxPT").getContent()).intValue();
222     asyncSend = new Boolean JavaDoc((String JavaDoc) ref.get(prefix + ".asyncSend").getContent()).booleanValue();
223     queueMessageReadMax = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".queueMessageReadMax").getContent()).intValue();
224     topicAckBufferMax = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".topicAckBufferMax").getContent()).intValue();
225     multiThreadSync = new Boolean JavaDoc((String JavaDoc) ref.get(prefix + ".multiThreadSync").getContent()).booleanValue();
226     multiThreadSyncDelay = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".multiThreadSyncDelay").getContent()).intValue();
227     multiThreadSyncThreshold = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".multiThreadSyncThreshold").getContent()).intValue();
228     topicPassivationThreshold = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".topicPassivationThreshold").getContent()).intValue();
229     topicActivationThreshold = new Integer JavaDoc((String JavaDoc) ref.get(prefix + ".topicActivationThreshold").getContent()).intValue();
230   }
231
232   public Hashtable JavaDoc toHashtable() {
233     Hashtable JavaDoc h = new Hashtable JavaDoc();
234
235     h.put("host", getHost());
236     h.put("port", new Integer JavaDoc(getPort()));
237     h.put("connectingTimer", new Integer JavaDoc(connectingTimer));
238     h.put("txPendingTimer", new Integer JavaDoc(txPendingTimer));
239     h.put("cnxPendingTimer", new Integer JavaDoc(cnxPendingTimer));
240     h.put("asyncSend", new Boolean JavaDoc(asyncSend));
241     h.put("queueMessageReadMax", new Integer JavaDoc(queueMessageReadMax));
242     h.put("topicAckBufferMax", new Integer JavaDoc(topicAckBufferMax));
243     h.put("multiThreadSync", new Boolean JavaDoc(multiThreadSync));
244     h.put("multiThreadSyncDelay", new Integer JavaDoc(multiThreadSyncDelay));
245     h.put("multiThreadSyncThreshold", new Integer JavaDoc(multiThreadSyncThreshold));
246     h.put("topicPassivationThreshold", new Integer JavaDoc(topicPassivationThreshold));
247     h.put("topicActivationThreshold", new Integer JavaDoc(topicActivationThreshold));
248
249     return h;
250   }
251
252   public static FactoryParameters fromHashtable(Hashtable JavaDoc h) {
253     FactoryParameters params = new FactoryParameters((String JavaDoc) h.get("host"),
254         ((Integer JavaDoc) h.get("port")).intValue());
255     params.connectingTimer = ((Integer JavaDoc) h.get("connectingTimer")).intValue();
256     params.txPendingTimer = ((Integer JavaDoc) h.get("txPendingTimer")).intValue();
257     params.cnxPendingTimer = ((Integer JavaDoc) h.get("cnxPendingTimer")).intValue();
258     params.asyncSend = ((Boolean JavaDoc) h.get("asyncSend")).booleanValue();
259     params.queueMessageReadMax = ((Integer JavaDoc) h.get("queueMessageReadMax")).intValue();
260     params.topicAckBufferMax = ((Integer JavaDoc) h.get("topicAckBufferMax")).intValue();
261     params.multiThreadSync = ((Boolean JavaDoc) h.get("multiThreadSync")).booleanValue();
262     params.multiThreadSyncDelay = ((Integer JavaDoc) h.get("multiThreadSyncDelay")).intValue();
263     params.multiThreadSyncThreshold = ((Integer JavaDoc) h.get("multiThreadSyncThreshold")).intValue();
264     params.topicPassivationThreshold = ((Integer JavaDoc) h.get("topicPassivationThreshold")).intValue();
265     params.topicActivationThreshold = ((Integer JavaDoc) h.get("topicActivationThreshold")).intValue();
266
267     return params;
268   }
269
270   public String JavaDoc toString() {
271     return '(' + super.toString() +
272       ",host=" + host +
273       ",port=" + port +
274       ",connectingTimer=" + connectingTimer +
275       ",txPendingTimer=" + txPendingTimer +
276       ",cnxPendingTimer=" + cnxPendingTimer +
277       ",asyncSend=" + asyncSend +
278       ",topicAckBufferMax=" + topicAckBufferMax +
279       ",multiThreadSync=" + multiThreadSync +
280       ",multiThreadSyncDelay=" + multiThreadSyncDelay +
281       ",multiThreadSyncThreshold=" + multiThreadSyncThreshold +
282       ",topicPassivationThreshold=" + topicPassivationThreshold +
283       ",topicActivationThreshold=" + topicActivationThreshold + ')';
284   }
285 }
286
Popular Tags