KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ActiveMQConnectionFactory


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;
19
20 import java.net.URI JavaDoc;
21 import java.net.URISyntaxException JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Properties JavaDoc;
24 import java.util.concurrent.Executor JavaDoc;
25 import java.util.concurrent.ScheduledThreadPoolExecutor JavaDoc;
26 import java.util.concurrent.ThreadFactory JavaDoc;
27
28 import javax.jms.Connection JavaDoc;
29 import javax.jms.ConnectionFactory JavaDoc;
30 import javax.jms.JMSException JavaDoc;
31 import javax.jms.QueueConnection JavaDoc;
32 import javax.jms.QueueConnectionFactory JavaDoc;
33 import javax.jms.TopicConnection JavaDoc;
34 import javax.jms.TopicConnectionFactory JavaDoc;
35 import javax.naming.Context JavaDoc;
36
37 import org.apache.activemq.blob.BlobTransferPolicy;
38 import org.apache.activemq.jndi.JNDIBaseStorable;
39 import org.apache.activemq.management.JMSStatsImpl;
40 import org.apache.activemq.management.StatsCapable;
41 import org.apache.activemq.management.StatsImpl;
42 import org.apache.activemq.transport.Transport;
43 import org.apache.activemq.transport.TransportFactory;
44 import org.apache.activemq.util.IdGenerator;
45 import org.apache.activemq.util.IntrospectionSupport;
46 import org.apache.activemq.util.JMSExceptionSupport;
47 import org.apache.activemq.util.URISupport;
48 import org.apache.activemq.util.URISupport.CompositeData;
49
50 /**
51  * A ConnectionFactory is an an Administered object, and is used for creating
52  * Connections. <p/> This class also implements QueueConnectionFactory and
53  * TopicConnectionFactory. You can use this connection to create both
54  * QueueConnections and TopicConnections.
55  *
56  * @version $Revision: 1.9 $
57  * @see javax.jms.ConnectionFactory
58  */

59 public class ActiveMQConnectionFactory extends JNDIBaseStorable implements ConnectionFactory JavaDoc, QueueConnectionFactory JavaDoc, TopicConnectionFactory JavaDoc, StatsCapable, Cloneable JavaDoc {
60
61     public static final String JavaDoc DEFAULT_BROKER_URL = "tcp://localhost:61616";
62     public static final String JavaDoc DEFAULT_USER = null;
63     public static final String JavaDoc DEFAULT_PASSWORD = null;
64     public static final int DEFAULT_PRODUCER_WINDOW_SIZE = 0;
65
66     private IdGenerator clientIdGenerator;
67     private String JavaDoc clientIDPrefix;
68     protected URI JavaDoc brokerURL;
69     protected String JavaDoc userName;
70     protected String JavaDoc password;
71     protected String JavaDoc clientID;
72
73     // client policies
74
private ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
75     private RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
76     private BlobTransferPolicy blobTransferPolicy = new BlobTransferPolicy();
77     private MessageTransformer transformer;
78
79     private boolean disableTimeStampsByDefault = false;
80     private boolean optimizedMessageDispatch = true;
81     private boolean copyMessageOnSend = true;
82     private boolean useCompression = false;
83     private boolean objectMessageSerializationDefered = false;
84     protected boolean dispatchAsync = false;
85     protected boolean alwaysSessionAsync=true;
86     private boolean useAsyncSend = false;
87     private boolean optimizeAcknowledge = false;
88     private int closeTimeout = 15000;
89     private boolean useRetroactiveConsumer;
90     private boolean nestedMapAndListEnabled = true;
91     JMSStatsImpl factoryStats = new JMSStatsImpl();
92     private boolean alwaysSyncSend;
93     private boolean watchTopicAdvisories=true;
94     private int producerWindowSize=DEFAULT_PRODUCER_WINDOW_SIZE;
95
96     static protected final Executor JavaDoc DEFAULT_CONNECTION_EXECUTOR = new ScheduledThreadPoolExecutor JavaDoc(5, new ThreadFactory JavaDoc() {
97             public Thread JavaDoc newThread(Runnable JavaDoc run) {
98                 Thread JavaDoc thread = new Thread JavaDoc(run);
99                 thread.setPriority(ThreadPriorities.INBOUND_CLIENT_CONNECTION);
100                 return thread;
101             }
102         });
103
104     // /////////////////////////////////////////////
105
//
106
// ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory Methods
107
//
108
// /////////////////////////////////////////////
109

110     public ActiveMQConnectionFactory() {
111         this(DEFAULT_BROKER_URL);
112     }
113
114     public ActiveMQConnectionFactory(String JavaDoc brokerURL) {
115         this(createURI(brokerURL));
116     }
117
118     /**
119      * Returns a copy of the given connection factory
120      */

121     public ActiveMQConnectionFactory copy() {
122         try {
123             return (ActiveMQConnectionFactory) super.clone();
124         }
125         catch (CloneNotSupportedException JavaDoc e) {
126             throw new RuntimeException JavaDoc("This should never happen: " + e, e);
127         }
128     }
129
130     /**
131      * @param brokerURL
132      * @return
133      * @throws URISyntaxException
134      */

135     private static URI JavaDoc createURI(String JavaDoc brokerURL) {
136         try {
137             return new URI JavaDoc(brokerURL);
138         }
139         catch (URISyntaxException JavaDoc e) {
140             throw (IllegalArgumentException JavaDoc) new IllegalArgumentException JavaDoc("Invalid broker URI: " + brokerURL).initCause(e);
141         }
142     }
143
144     public ActiveMQConnectionFactory(URI JavaDoc brokerURL) {
145         setBrokerURL(brokerURL.toString());
146     }
147
148     public ActiveMQConnectionFactory(String JavaDoc userName, String JavaDoc password, URI JavaDoc brokerURL) {
149         setUserName(userName);
150         setPassword(password);
151         setBrokerURL(brokerURL.toString());
152     }
153
154     public ActiveMQConnectionFactory(String JavaDoc userName, String JavaDoc password, String JavaDoc brokerURL) {
155         setUserName(userName);
156         setPassword(password);
157         setBrokerURL(brokerURL);
158     }
159
160     /**
161      * @return Returns the Connection.
162      */

163     public Connection JavaDoc createConnection() throws JMSException JavaDoc {
164         return createActiveMQConnection();
165     }
166
167     /**
168      * @return Returns the Connection.
169      */

170     public Connection JavaDoc createConnection(String JavaDoc userName, String JavaDoc password) throws JMSException JavaDoc {
171         return createActiveMQConnection(userName, password);
172     }
173
174     /**
175      * @return Returns the QueueConnection.
176      * @throws JMSException
177      */

178     public QueueConnection JavaDoc createQueueConnection() throws JMSException JavaDoc {
179         return createActiveMQConnection();
180     }
181
182     /**
183      * @return Returns the QueueConnection.
184      */

185     public QueueConnection JavaDoc createQueueConnection(String JavaDoc userName, String JavaDoc password) throws JMSException JavaDoc {
186         return createActiveMQConnection(userName, password);
187     }
188
189     /**
190      * @return Returns the TopicConnection.
191      * @throws JMSException
192      */

193     public TopicConnection JavaDoc createTopicConnection() throws JMSException JavaDoc {
194         return createActiveMQConnection();
195     }
196
197     /**
198      * @return Returns the TopicConnection.
199      */

200     public TopicConnection JavaDoc createTopicConnection(String JavaDoc userName, String JavaDoc password) throws JMSException JavaDoc {
201         return createActiveMQConnection(userName, password);
202     }
203
204     public StatsImpl getStats() {
205         // TODO
206
return null;
207     }
208
209     // /////////////////////////////////////////////
210
//
211
// Implementation methods.
212
//
213
// /////////////////////////////////////////////
214

215
216     protected ActiveMQConnection createActiveMQConnection() throws JMSException JavaDoc {
217         return createActiveMQConnection(userName, password);
218     }
219     
220     /**
221      * Creates a Transport based on this object's connection settings.
222      *
223      * Separated from createActiveMQConnection to allow for subclasses to
224      * override.
225      *
226      * @return The newly created Transport.
227      * @throws JMSException If unable to create trasnport.
228      *
229      * @author sepandm@gmail.com
230      */

231     protected Transport createTransport() throws JMSException JavaDoc {
232         try {
233             return TransportFactory.connect(brokerURL,DEFAULT_CONNECTION_EXECUTOR);
234         } catch (Exception JavaDoc e) {
235             throw JMSExceptionSupport.create("Could not create Transport. Reason: " + e, e);
236         }
237     }
238
239     /**
240      * @return Returns the Connection.
241      */

242     protected ActiveMQConnection createActiveMQConnection(String JavaDoc userName, String JavaDoc password) throws JMSException JavaDoc {
243         if (brokerURL == null) {
244             throw new ConfigurationException("brokerURL not set.");
245         }
246         ActiveMQConnection connection=null;
247         try {
248             Transport transport = createTransport();
249             connection = createActiveMQConnection(transport, factoryStats);
250             
251             connection.setUserName(userName);
252             connection.setPassword(password);
253             connection.setPrefetchPolicy(getPrefetchPolicy());
254             connection.setDisableTimeStampsByDefault(isDisableTimeStampsByDefault());
255             connection.setOptimizedMessageDispatch(isOptimizedMessageDispatch());
256             connection.setCopyMessageOnSend(isCopyMessageOnSend());
257             connection.setUseCompression(isUseCompression());
258             connection.setObjectMessageSerializationDefered(isObjectMessageSerializationDefered());
259             connection.setDispatchAsync(isDispatchAsync());
260             connection.setUseAsyncSend(isUseAsyncSend());
261             connection.setAlwaysSyncSend(isAlwaysSyncSend());
262             connection.setAlwaysSessionAsync(isAlwaysSessionAsync());
263             connection.setOptimizeAcknowledge(isOptimizeAcknowledge());
264             connection.setUseRetroactiveConsumer(isUseRetroactiveConsumer());
265             connection.setRedeliveryPolicy(getRedeliveryPolicy());
266             connection.setTransformer(getTransformer());
267             connection.setBlobTransferPolicy(getBlobTransferPolicy().copy());
268             connection.setWatchTopicAdvisories(watchTopicAdvisories);
269             connection.setProducerWindowSize(producerWindowSize);
270             transport.start();
271
272             if( clientID !=null )
273                 connection.setDefaultClientID(clientID);
274
275             return connection;
276         }
277         catch (JMSException JavaDoc e) {
278             // Clean up!
279
try { connection.close(); } catch ( Throwable JavaDoc ignore ) {}
280             throw e;
281         }
282         catch (Exception JavaDoc e) {
283             // Clean up!
284
try { connection.close(); } catch ( Throwable JavaDoc ignore ) {}
285             throw JMSExceptionSupport.create("Could not connect to broker URL: " + brokerURL + ". Reason: " + e, e);
286         }
287     }
288
289     protected ActiveMQConnection createActiveMQConnection(Transport transport, JMSStatsImpl stats) throws Exception JavaDoc {
290         ActiveMQConnection connection = new ActiveMQConnection(transport, getClientIdGenerator(), stats);
291         return connection;
292     }
293
294     // /////////////////////////////////////////////
295
//
296
// Property Accessors
297
//
298
// /////////////////////////////////////////////
299

300     public String JavaDoc getBrokerURL() {
301         return brokerURL==null?null:brokerURL.toString();
302     }
303     
304     /**
305      * Sets the <a
306      * HREF="http://activemq.apache.org/configuring-transports.html">connection
307      * URL</a> used to connect to the ActiveMQ broker.
308      */

309     public void setBrokerURL(String JavaDoc brokerURL) {
310         this.brokerURL = createURI(brokerURL);
311
312         // Use all the properties prefixed with 'jms.' to set the connection factory
313
// options.
314
if( this.brokerURL.getQuery() !=null ) {
315             // It might be a standard URI or...
316
try {
317
318                 Map JavaDoc map = URISupport.parseQuery(this.brokerURL.getQuery());
319                 if( buildFromMap(IntrospectionSupport.extractProperties(map, "jms.")) ) {
320                     this.brokerURL = URISupport.createRemainingURI(this.brokerURL, map);
321                 }
322
323             } catch (URISyntaxException JavaDoc e) {
324             }
325
326         } else {
327
328             // It might be a composite URI.
329
try {
330                 CompositeData data = URISupport.parseComposite(this.brokerURL);
331                 if( buildFromMap(IntrospectionSupport.extractProperties(data.getParameters(), "jms.")) ) {
332                     this.brokerURL = data.toURI();
333                 }
334             } catch (URISyntaxException JavaDoc e) {
335             }
336         }
337     }
338
339     public String JavaDoc getClientID() {
340         return clientID;
341     }
342
343     /**
344      * Sets the JMS clientID to use for the created connection. Note that this can only be used by one connection at once so generally its a better idea
345      * to set the clientID on a Connection
346      */

347     public void setClientID(String JavaDoc clientID) {
348         this.clientID = clientID;
349     }
350
351     public boolean isCopyMessageOnSend() {
352         return copyMessageOnSend;
353     }
354
355     /**
356      * Should a JMS message be copied to a new JMS Message object as part of the
357      * send() method in JMS. This is enabled by default to be compliant with the
358      * JMS specification. You can disable it if you do not mutate JMS messages
359      * after they are sent for a performance boost
360      */

361     public void setCopyMessageOnSend(boolean copyMessageOnSend) {
362         this.copyMessageOnSend = copyMessageOnSend;
363     }
364
365     public boolean isDisableTimeStampsByDefault() {
366         return disableTimeStampsByDefault;
367     }
368
369     /**
370      * Sets whether or not timestamps on messages should be disabled or not. If
371      * you disable them it adds a small performance boost.
372      */

373     public void setDisableTimeStampsByDefault(boolean disableTimeStampsByDefault) {
374         this.disableTimeStampsByDefault = disableTimeStampsByDefault;
375     }
376
377     public boolean isOptimizedMessageDispatch() {
378         return optimizedMessageDispatch;
379     }
380
381     /**
382      * If this flag is set then an larger prefetch limit is used - only
383      * applicable for durable topic subscribers.
384      */

385     public void setOptimizedMessageDispatch(boolean optimizedMessageDispatch) {
386         this.optimizedMessageDispatch = optimizedMessageDispatch;
387     }
388
389     public String JavaDoc getPassword() {
390         return password;
391     }
392
393     /**
394      * Sets the JMS password used for connections created from this factory
395      */

396     public void setPassword(String JavaDoc password) {
397         this.password = password;
398     }
399
400     public ActiveMQPrefetchPolicy getPrefetchPolicy() {
401         return prefetchPolicy;
402     }
403
404     /**
405      * Sets the <a
406      * HREF="http://activemq.apache.org/what-is-the-prefetch-limit-for.html">prefetch
407      * policy</a> for consumers created by this connection.
408      */

409     public void setPrefetchPolicy(ActiveMQPrefetchPolicy prefetchPolicy) {
410         this.prefetchPolicy = prefetchPolicy;
411     }
412
413     public boolean isUseAsyncSend() {
414         return useAsyncSend;
415     }
416
417     public BlobTransferPolicy getBlobTransferPolicy() {
418         return blobTransferPolicy;
419     }
420
421     /**
422      * Sets the policy used to describe how out-of-band BLOBs (Binary Large OBjects)
423      * are transferred from producers to brokers to consumers
424      */

425     public void setBlobTransferPolicy(BlobTransferPolicy blobTransferPolicy) {
426         this.blobTransferPolicy = blobTransferPolicy;
427     }
428
429     /**
430      * Forces the use of <a
431      * HREF="http://activemq.apache.org/async-sends.html">Async Sends</a>
432      * which adds a massive performance boost; but means that the send() method
433      * will return immediately whether the message has been sent or not which
434      * could lead to message loss.
435      */

436     public void setUseAsyncSend(boolean useAsyncSend) {
437         this.useAsyncSend = useAsyncSend;
438     }
439     
440     public synchronized boolean isWatchTopicAdvisories() {
441         return watchTopicAdvisories;
442     }
443
444     public synchronized void setWatchTopicAdvisories(boolean watchTopicAdvisories) {
445         this.watchTopicAdvisories = watchTopicAdvisories;
446     }
447     
448     /**
449      * @return true if always sync send messages
450      */

451     public boolean isAlwaysSyncSend(){
452         return this.alwaysSyncSend;
453     }
454
455     /**
456      * Set true if always require messages to be sync sent
457      * @param alwaysSyncSend
458      */

459     public void setAlwaysSyncSend(boolean alwaysSyncSend){
460         this.alwaysSyncSend=alwaysSyncSend;
461     }
462
463     public String JavaDoc getUserName() {
464         return userName;
465     }
466
467     /**
468      * Sets the JMS userName used by connections created by this factory
469      */

470     public void setUserName(String JavaDoc userName) {
471         this.userName = userName;
472     }
473
474     public boolean isUseRetroactiveConsumer() {
475         return useRetroactiveConsumer;
476     }
477
478     /**
479      * Sets whether or not retroactive consumers are enabled. Retroactive consumers allow
480      * non-durable topic subscribers to receive old messages that were published before the
481      * non-durable subscriber started.
482      */

483     public void setUseRetroactiveConsumer(boolean useRetroactiveConsumer) {
484         this.useRetroactiveConsumer = useRetroactiveConsumer;
485     }
486
487     public RedeliveryPolicy getRedeliveryPolicy() {
488         return redeliveryPolicy;
489     }
490
491     /**
492      * Sets the global redelivery policy to be used when a message is delivered but the session is rolled back
493      */

494     public void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy) {
495         this.redeliveryPolicy = redeliveryPolicy;
496     }
497
498     public MessageTransformer getTransformer() {
499         return transformer;
500     }
501
502     /**
503      * Sets the transformer used to transform messages before they are sent on to the JMS bus
504      * or when they are received from the bus but before they are delivered to the JMS client
505      */

506     public void setTransformer(MessageTransformer transformer) {
507         this.transformer = transformer;
508     }
509
510     public void buildFromProperties(Properties JavaDoc properties) {
511         
512         if (properties == null) {
513             properties = new Properties JavaDoc();
514         }
515
516         String JavaDoc temp = properties.getProperty(Context.PROVIDER_URL);
517         if (temp == null || temp.length() == 0) {
518             temp = properties.getProperty("brokerURL");
519         }
520         if (temp != null && temp.length() > 0) {
521             setBrokerURL(temp);
522         }
523         
524         buildFromMap(properties);
525     }
526     
527     public boolean buildFromMap(Map JavaDoc properties) {
528         boolean rc=false;
529         
530         ActiveMQPrefetchPolicy p = new ActiveMQPrefetchPolicy();
531         if( IntrospectionSupport.setProperties(p, properties, "prefetchPolicy.") ) {
532             setPrefetchPolicy(p);
533             rc = true;
534         }
535
536         RedeliveryPolicy rp = new RedeliveryPolicy();
537         if ( IntrospectionSupport.setProperties(rp, properties, "redeliveryPolicy.") ) {
538             setRedeliveryPolicy(rp);
539             rc = true;
540         }
541
542         BlobTransferPolicy blobTransferPolicy = new BlobTransferPolicy();
543         if ( IntrospectionSupport.setProperties(blobTransferPolicy, properties, "blobTransferPolicy.") ) {
544             setBlobTransferPolicy(blobTransferPolicy);
545             rc = true;
546         }
547
548         rc |= IntrospectionSupport.setProperties(this, properties);
549
550         return rc;
551     }
552
553     public void populateProperties(Properties JavaDoc props) {
554         props.setProperty("dispatchAsync", Boolean.toString(isDispatchAsync()));
555
556         if (getBrokerURL() != null) {
557             props.setProperty(Context.PROVIDER_URL, getBrokerURL());
558             props.setProperty("brokerURL", getBrokerURL());
559         }
560
561         if (getClientID() != null) {
562             props.setProperty("clientID", getClientID());
563         }
564
565         IntrospectionSupport.getProperties(getPrefetchPolicy(), props, "prefetchPolicy.");
566         IntrospectionSupport.getProperties(getRedeliveryPolicy(), props, "redeliveryPolicy.");
567         IntrospectionSupport.getProperties(getBlobTransferPolicy(), props, "blobTransferPolicy.");
568
569         props.setProperty("copyMessageOnSend", Boolean.toString(isCopyMessageOnSend()));
570         props.setProperty("disableTimeStampsByDefault", Boolean.toString(isDisableTimeStampsByDefault()));
571         props.setProperty("objectMessageSerializationDefered", Boolean.toString(isObjectMessageSerializationDefered()));
572         props.setProperty("optimizedMessageDispatch", Boolean.toString(isOptimizedMessageDispatch()));
573
574         if (getPassword() != null) {
575             props.setProperty("password", getPassword());
576         }
577
578         props.setProperty("useAsyncSend", Boolean.toString(isUseAsyncSend()));
579         props.setProperty("useCompression", Boolean.toString(isUseCompression()));
580         props.setProperty("useRetroactiveConsumer", Boolean.toString(isUseRetroactiveConsumer()));
581         props.setProperty("watchTopicAdvisories", Boolean.toString(isWatchTopicAdvisories()));
582         
583         if (getUserName() != null) {
584             props.setProperty("userName", getUserName());
585         }
586         
587         props.setProperty("closeTimeout", Integer.toString(getCloseTimeout()));
588         props.setProperty("alwaysSessionAsync", Boolean.toString(isAlwaysSessionAsync()));
589         props.setProperty("optimizeAcknowledge", Boolean.toString(isOptimizeAcknowledge()));
590         props.setProperty("statsEnabled",Boolean.toString(isStatsEnabled()));
591         props.setProperty("alwaysSyncSend",Boolean.toString(isAlwaysSyncSend()));
592         props.setProperty("producerWindowSize", Integer.toString(producerWindowSize));
593     }
594
595     public boolean isUseCompression() {
596         return useCompression;
597     }
598
599     /**
600      * Enables the use of compression of the message bodies
601      */

602     public void setUseCompression(boolean useCompression) {
603         this.useCompression = useCompression;
604     }
605
606     public boolean isObjectMessageSerializationDefered() {
607         return objectMessageSerializationDefered;
608     }
609
610     /**
611      * When an object is set on an ObjectMessage, the JMS spec requires the
612      * object to be serialized by that set method. Enabling this flag causes the
613      * object to not get serialized. The object may subsequently get serialized
614      * if the message needs to be sent over a socket or stored to disk.
615      */

616     public void setObjectMessageSerializationDefered(boolean objectMessageSerializationDefered) {
617         this.objectMessageSerializationDefered = objectMessageSerializationDefered;
618     }
619
620     public boolean isDispatchAsync() {
621         return dispatchAsync;
622     }
623
624     /**
625      * Enables or disables the default setting of whether or not consumers have
626      * their messages <a
627      * HREF="http://activemq.apache.org/consumer-dispatch-async.html">dispatched
628      * synchronously or asynchronously by the broker</a>.
629      *
630      * For non-durable topics for example we typically dispatch synchronously by
631      * default to minimize context switches which boost performance. However
632      * sometimes its better to go slower to ensure that a single blocked
633      * consumer socket does not block delivery to other consumers.
634      *
635      * @param asyncDispatch
636      * If true then consumers created on this connection will default
637      * to having their messages dispatched asynchronously. The
638      * default value is false.
639      */

640     public void setDispatchAsync(boolean asyncDispatch) {
641         this.dispatchAsync = asyncDispatch;
642     }
643
644     /**
645      * @return Returns the closeTimeout.
646      */

647     public int getCloseTimeout(){
648         return closeTimeout;
649     }
650
651     /**
652      * Sets the timeout before a close is considered complete. Normally a
653      * close() on a connection waits for confirmation from the broker; this
654      * allows that operation to timeout to save the client hanging if there is
655      * no broker
656      */

657     public void setCloseTimeout(int closeTimeout){
658         this.closeTimeout=closeTimeout;
659     }
660
661     /**
662      * @return Returns the alwaysSessionAsync.
663      */

664     public boolean isAlwaysSessionAsync(){
665         return alwaysSessionAsync;
666     }
667
668     /**
669      * If this flag is set then a separate thread is not used for dispatching
670      * messages for each Session in the Connection. However, a separate thread
671      * is always used if there is more than one session, or the session isn't in
672      * auto acknowledge or duplicates ok mode
673      */

674     public void setAlwaysSessionAsync(boolean alwaysSessionAsync){
675         this.alwaysSessionAsync=alwaysSessionAsync;
676     }
677
678     /**
679      * @return Returns the optimizeAcknowledge.
680      */

681     public boolean isOptimizeAcknowledge(){
682         return optimizeAcknowledge;
683     }
684
685     /**
686      * @param optimizeAcknowledge The optimizeAcknowledge to set.
687      */

688     public void setOptimizeAcknowledge(boolean optimizeAcknowledge){
689         this.optimizeAcknowledge=optimizeAcknowledge;
690     }
691     
692     public boolean isNestedMapAndListEnabled() {
693         return nestedMapAndListEnabled ;
694     }
695
696     /**
697      * Enables/disables whether or not Message properties and MapMessage entries
698      * support <a
699      * HREF="http://activemq.apache.org/structured-message-properties-and-mapmessages.html">Nested
700      * Structures</a> of Map and List objects
701      */

702     public void setNestedMapAndListEnabled(boolean structuredMapsEnabled) {
703         this.nestedMapAndListEnabled = structuredMapsEnabled;
704     }
705
706     public String JavaDoc getClientIDPrefix() {
707         return clientIDPrefix;
708     }
709
710     /**
711      * Sets the prefix used by autogenerated JMS Client ID values which are
712      * used if the JMS client does not explicitly specify on.
713      *
714      * @param clientIDPrefix
715      */

716     public void setClientIDPrefix(String JavaDoc clientIDPrefix) {
717         this.clientIDPrefix = clientIDPrefix;
718     }
719     
720     protected synchronized IdGenerator getClientIdGenerator() {
721         if (clientIdGenerator == null) {
722             if (clientIDPrefix != null) {
723                 clientIdGenerator = new IdGenerator(clientIDPrefix);
724             }
725             else {
726                 clientIdGenerator = new IdGenerator();
727             }
728         }
729         return clientIdGenerator;
730     }
731
732     protected void setClientIdGenerator(IdGenerator clientIdGenerator) {
733         this.clientIdGenerator = clientIdGenerator;
734     }
735
736     
737     /**
738      * @return the statsEnabled
739      */

740     public boolean isStatsEnabled(){
741         return this.factoryStats.isEnabled();
742     }
743
744     
745     /**
746      * @param statsEnabled the statsEnabled to set
747      */

748     public void setStatsEnabled(boolean statsEnabled){
749         this.factoryStats.setEnabled(statsEnabled);
750     }
751
752     synchronized public int getProducerWindowSize() {
753         return producerWindowSize;
754     }
755
756     synchronized public void setProducerWindowSize(int producerWindowSize) {
757         this.producerWindowSize = producerWindowSize;
758     }
759 }
760
Popular Tags