KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > MuleConfiguration


1 /*
2  * $Id: MuleConfiguration.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.config;
12
13 import org.apache.commons.beanutils.BeanUtils;
14 import org.apache.commons.lang.StringUtils;
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17 import org.mule.MuleRuntimeException;
18 import org.mule.config.i18n.Message;
19 import org.mule.config.i18n.Messages;
20 import org.mule.providers.ConnectionStrategy;
21 import org.mule.providers.SingleAttemptConnectionStrategy;
22 import org.mule.umo.manager.DefaultWorkListener;
23 import org.mule.util.queue.EventFilePersistenceStrategy;
24 import org.mule.util.queue.QueuePersistenceStrategy;
25
26 import javax.resource.spi.work.WorkListener JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.security.AccessController JavaDoc;
31 import java.security.PrivilegedAction JavaDoc;
32 import java.util.jar.Attributes JavaDoc;
33 import java.util.jar.Manifest JavaDoc;
34 import java.util.Enumeration JavaDoc;
35
36 /**
37  * <code>MuleConfiguration</code> holds the runtime configuration specific to the
38  * <code>MuleManager</code>. Once the <code>MuleManager</code> has been
39  * initialised this class is immutable.
40  *
41  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
42  * @version $Revision: 3798 $
43  */

44 public class MuleConfiguration
45 {
46     /**
47      * logger used by this class
48      */

49     protected transient Log logger = LogFactory.getLog(getClass());
50
51     /**
52      * The default serverUrl used to receive incoming requests from clients
53      */

54     public static final String JavaDoc DEFAULT_SERVER_URL = "tcp://localhost:60504";
55
56     /**
57      * Specifies that the transformer properties should be obtained from the Mule
58      * Manager properties
59      */

60     public static final String JavaDoc USE_MANAGER_PROPERTIES = "org.mule.useManagerProperties";
61
62     /**
63      * Specifies whether mule should process messages sysnchonously, i.e. that a
64      * mule-model can only processone message at a time, or asynchonously. The
65      * default value is 'false'.
66      */

67     public static final String JavaDoc SYNCHRONOUS_PROPERTY = "synchronous";
68
69     public static final String JavaDoc DEFAULT_ENCODING = "UTF-8";
70     /**
71      * Default encoding used in OS running Mule
72      */

73     public static final String JavaDoc DEFAULT_OS_ENCODING = System.getProperty("file.encoding");
74
75     // /**
76
// * Determines the default inboundProvider that Mule uses to communicate
77
// between MuelUMO's when an
78
// * inboundProvider is not specified on a mule.
79
// * If this value is not specifed, Mule will create a default VM connection
80
// * called 'muleVMInboundProvider' which will use a VMConnector.
81
// */
82
// public static final String DEFAULT_INBOUND_PROVIDER_PROPERTY =
83
// "defaultInboundProvider";
84
//
85
// /**
86
// * Determines the default outboundProvider that Mule uses to communicate
87
// between MuelUMO's when an
88
// * outboundProvider is not specified on a mule.
89
// * If this value is not specifed, Mule will create a default VM connection
90
// * called 'muleVMOutbound' which will use a VMConnector.
91
// */
92
// public static final String DEFAULT_OUTBOUND_PROVIDER_PROPERTY =
93
// "defaultOutboundProvider";
94

95     /**
96      * Default value for SYNCHRONOUS_PROPERTY
97      */

98     public static final boolean DEFAULT_SYNCHRONOUS = false;
99
100     /**
101      * Default value for MAX_OUTSTANDING_MESSAGES_PROPERTY
102      */

103     public static final int DEFAULT_MAX_OUTSTANDING_MESSAGES = 1000;
104
105     public static final int DEFAULT_TIMEOUT = 10000;
106
107     public static final int DEFAULT_TRANSACTION_TIMEOUT = 30000;
108
109     /**
110      * Where Mule stores any runtime files to disk
111      */

112     public static final String JavaDoc DEFAULT_WORKING_DIRECTORY = "./.mule";
113
114     /**
115      * The default queueStore directory for persistence
116      */

117     public static final String JavaDoc DEFAULT_QUEUE_STORE = "queuestore";
118
119     /**
120      * holds the value for SYNCHRONOUS
121      */

122     private boolean synchronous = DEFAULT_SYNCHRONOUS;
123
124     /**
125      * Whether Mule should fire message events for every message sent and received
126      */

127     private boolean enableMessageEvents = false;
128
129     /**
130      * Name of the model to use. If blank the first model will be used
131      */

132     private String JavaDoc model = null;
133
134     private String JavaDoc encoding = DEFAULT_ENCODING;
135
136     private String JavaDoc osEncoding = DEFAULT_OS_ENCODING;
137
138     private PoolingProfile poolingProfile = new PoolingProfile();
139
140     /**
141      * configuration for the threadpool used by message dispatchers
142      */

143     private ThreadingProfile messageDispatcherThreadingProfile = null;
144
145     /**
146      * configuration for the threadpool used by message receivers
147      */

148     private ThreadingProfile messageReceiverThreadingProfile = null;
149
150     /**
151      * configuration for the threadpool used by component pooling in mule
152      */

153     private ThreadingProfile componentPoolThreadingProfile = null;
154
155     private QueueProfile queueProfile = new QueueProfile(DEFAULT_MAX_OUTSTANDING_MESSAGES, false);
156
157     private QueuePersistenceStrategy persistenceStrategy = new EventFilePersistenceStrategy();
158
159     /**
160      * When running sychonously, return events can be received over transports that
161      * support ack or replyTo This property determines how long to wait for a receive
162      */

163     private int synchronousEventTimeout = DEFAULT_TIMEOUT;
164
165     /**
166      * The default transaction timeout value used if no specific transaction time out
167      * has been set on the transaction config
168      */

169     private int transactionTimeout = DEFAULT_TRANSACTION_TIMEOUT;
170
171     /**
172      * Determines whether when running synchronously, return events are received
173      * before returning the call. i.e. in jms wait for a replyTo. Vm queues do this
174      * automatically
175      */

176     private boolean remoteSync = false;
177
178     /**
179      * Determines whether internal vm queues are persistent. If they are, if the
180      * server dies unexpectedly it can resume it's current state and continue
181      * processing
182      */

183     private boolean recoverableMode = false;
184     /**
185      * A helper thread pool configuration that is used for all other thread pool
186      * configurations
187      */

188     private ThreadingProfile defaultThreadingProfile = new ThreadingProfile();
189
190     /**
191      * Where mule will store any runtime files to disk
192      */

193     private String JavaDoc workingDirectory = DEFAULT_WORKING_DIRECTORY;
194
195     /**
196      * The configuration resources used to configure the MuleManager instance
197      */

198     private String JavaDoc[] configResources = new String JavaDoc[]{};
199
200     /**
201      * This is the url used by the server itself to receive incomming requests. This
202      * enables clients such as the Mule Client to marshal remote requests to a
203      * MuleManager instance. The default value is tcp://localhost:61616
204      */

205     private String JavaDoc serverUrl = DEFAULT_SERVER_URL;
206
207     /**
208      * The Mule Jar manifest object
209      */

210     private Manifest JavaDoc manifest = null;
211
212     /**
213      * Whether the server instance is running in client mode, which means that some
214      * services will not be started
215      */

216     private boolean clientMode = false;
217
218     /**
219      * Whether the server is embedded by another framework and certain stand-alone
220      * features
221      */

222     private boolean embedded = false;
223
224     /**
225      * The model type to use for component invocations
226      */

227     private String JavaDoc modelType = "default";
228
229     /**
230      * The default connection Strategy used for a connector when one hasn't been
231      * defined for the connector
232      */

233     private ConnectionStrategy connectionStrategy = new SingleAttemptConnectionStrategy();
234
235     private WorkListener workListener = new DefaultWorkListener();
236
237     public MuleConfiguration()
238     {
239         super();
240     }
241
242     /**
243      * @return true if the model is running synchronously or false otherwise
244      */

245     public boolean isSynchronous()
246     {
247         return synchronous;
248     }
249
250     public void setSynchronous(boolean synchronous)
251     {
252         this.synchronous = synchronous;
253     }
254
255     public String JavaDoc getModel()
256     {
257         return model;
258     }
259
260     public void setModel(String JavaDoc model)
261     {
262         this.model = model;
263     }
264
265     public ThreadingProfile getMessageDispatcherThreadingProfile()
266     {
267         return getThreadingProfile(messageDispatcherThreadingProfile);
268     }
269
270     public void setMessageDispatcherThreadingProfile(ThreadingProfile messageDispatcherThreadingProfile)
271     {
272         this.messageDispatcherThreadingProfile = messageDispatcherThreadingProfile;
273     }
274
275     public ThreadingProfile getMessageReceiverThreadingProfile()
276     {
277         return getThreadingProfile(messageReceiverThreadingProfile);
278     }
279
280     public void setMessageReceiverThreadingProfile(ThreadingProfile messageReceiverThreadingProfile)
281     {
282         this.messageReceiverThreadingProfile = messageReceiverThreadingProfile;
283     }
284
285     public ThreadingProfile getComponentThreadingProfile()
286     {
287         return getThreadingProfile(componentPoolThreadingProfile);
288     }
289
290     public void setComponentThreadingProfile(ThreadingProfile componentPoolThreadingProfile)
291     {
292         this.componentPoolThreadingProfile = componentPoolThreadingProfile;
293     }
294
295     public ThreadingProfile getDefaultThreadingProfile()
296     {
297         return getThreadingProfile(defaultThreadingProfile);
298     }
299
300     public void setDefaultThreadingProfile(ThreadingProfile defaultThreadingProfile)
301     {
302         if (defaultThreadingProfile == null)
303         {
304             return;
305         }
306         this.defaultThreadingProfile = defaultThreadingProfile;
307     }
308
309     private ThreadingProfile getThreadingProfile(ThreadingProfile profile)
310     {
311         if (profile != null)
312         {
313             return new ThreadingProfile(profile);
314         }
315         return new ThreadingProfile(defaultThreadingProfile);
316     }
317
318     public PoolingProfile getPoolingProfile()
319     {
320         return new PoolingProfile(poolingProfile);
321     }
322
323     public void setPoolingProfile(PoolingProfile poolingProfile)
324     {
325         this.poolingProfile = poolingProfile;
326     }
327
328     public int getSynchronousEventTimeout()
329     {
330         return synchronousEventTimeout;
331     }
332
333     public void setSynchronousEventTimeout(int synchronousEventTimeout)
334     {
335         this.synchronousEventTimeout = synchronousEventTimeout;
336     }
337
338     public boolean isRemoteSync()
339     {
340         return remoteSync;
341     }
342
343     public void setRemoteSync(boolean remoteSync)
344     {
345         this.remoteSync = remoteSync;
346     }
347
348     public QueueProfile getQueueProfile()
349     {
350         return new QueueProfile(queueProfile);
351     }
352
353     public void setQueueProfile(QueueProfile queueProfile)
354     {
355         this.queueProfile = queueProfile;
356     }
357
358     public boolean isRecoverableMode()
359     {
360         return recoverableMode;
361     }
362
363     public void setRecoverableMode(boolean recoverableMode)
364     {
365         this.recoverableMode = recoverableMode;
366         if (recoverableMode)
367         {
368             queueProfile.setPersistent(true);
369         }
370     }
371
372     public String JavaDoc getWorkingDirectory()
373     {
374         return workingDirectory;
375     }
376
377     public void setWorkingDirectory(String JavaDoc workingDirectory)
378     {
379         this.workingDirectory = workingDirectory;
380     }
381
382     public String JavaDoc[] getConfigResources()
383     {
384         return configResources;
385     }
386
387     public void setConfigResources(String JavaDoc[] configResources)
388     {
389         if (configResources != null)
390         {
391             int current = this.configResources.length;
392             String JavaDoc[] newResources = new String JavaDoc[configResources.length + current];
393             System.arraycopy(this.configResources, 0, newResources, 0, current);
394             System.arraycopy(configResources, 0, newResources, current, configResources.length);
395             this.configResources = newResources;
396         }
397         else
398         {
399             this.configResources = configResources;
400         }
401     }
402
403     public String JavaDoc getServerUrl()
404     {
405         return serverUrl;
406     }
407
408     public void setServerUrl(String JavaDoc serverUrl)
409     {
410         if (embedded)
411         {
412             serverUrl = null;
413         }
414         else
415         {
416             this.serverUrl = serverUrl;
417         }
418     }
419
420     public String JavaDoc getProductVersion()
421     {
422         return getManifestProperty("Implementation-Version");
423     }
424
425     public String JavaDoc getVendorName()
426     {
427         return getManifestProperty("Specification-Vendor");
428     }
429
430     public String JavaDoc getVendorUrl()
431     {
432         return getManifestProperty("Vendor-Url");
433     }
434
435     public String JavaDoc getProductUrl()
436     {
437         return getManifestProperty("Product-Url");
438     }
439
440     public String JavaDoc getProductName()
441     {
442         return getManifestProperty("Implementation-Title");
443     }
444
445     public String JavaDoc getProductMoreInfo()
446     {
447         return getManifestProperty("More-Info");
448     }
449
450     public String JavaDoc getProductSupport()
451     {
452         return getManifestProperty("Support");
453     }
454
455     public String JavaDoc getProductLicenseInfo()
456     {
457         return getManifestProperty("License");
458     }
459
460     public String JavaDoc getProductDescription()
461     {
462         return getManifestProperty("Description");
463     }
464
465     public String JavaDoc getBuildDate()
466     {
467         return getManifestProperty("Build-Date");
468     }
469
470     public Manifest JavaDoc getManifest()
471     {
472         if (manifest == null)
473         {
474             manifest = new Manifest JavaDoc();
475
476             InputStream JavaDoc is = null;
477             try
478             {
479                 // We want to load the MANIFEST.MF from the mule-core jar. Sine we
480
// don't the version we're using
481
// we have to search for the jar on the classpath
482
URL JavaDoc url = (URL JavaDoc)AccessController.doPrivileged(new PrivilegedAction JavaDoc()
483                 {
484                     public Object JavaDoc run()
485                     {
486                         try
487                         {
488                             Enumeration JavaDoc e = MuleConfiguration.class.getClassLoader().getResources(
489                                 ("META-INF/MANIFEST.MF"));
490                             while (e.hasMoreElements())
491                             {
492                                 URL JavaDoc url = (URL JavaDoc)e.nextElement();
493                                 if (url.toExternalForm().indexOf("mule-core") > -1)
494                                 {
495                                     return url;
496                                 }
497                             }
498                         }
499                         catch (IOException JavaDoc e1)
500                         {
501                             e1.printStackTrace();
502                         }
503                         return null;
504                     }
505                 });
506
507                 if (url != null)
508                 {
509                     is = url.openStream();
510                 }
511
512                 if (is != null)
513                 {
514                     manifest.read(is);
515                 }
516
517             }
518             catch (IOException JavaDoc e)
519             {
520                 logger.warn("Failed to read manifest Info, Manifest information will not display correctly: "
521                             + e.getMessage());
522             }
523         }
524         return manifest;
525     }
526
527     protected String JavaDoc getManifestProperty(String JavaDoc name)
528     {
529         return getManifest().getMainAttributes().getValue(new Attributes.Name JavaDoc(name));
530     }
531
532     public int getTransactionTimeout()
533     {
534         return transactionTimeout;
535     }
536
537     public void setTransactionTimeout(int transactionTimeout)
538     {
539         this.transactionTimeout = transactionTimeout;
540     }
541
542     public boolean isClientMode()
543     {
544         return clientMode;
545     }
546
547     public void setClientMode(boolean clientMode)
548     {
549         this.clientMode = clientMode;
550         if (clientMode)
551         {
552             setServerUrl("");
553         }
554     }
555
556     public QueuePersistenceStrategy getPersistenceStrategy()
557     {
558         return persistenceStrategy;
559     }
560
561     public void setPersistenceStrategy(QueuePersistenceStrategy persistenceStrategy)
562     {
563         this.persistenceStrategy = persistenceStrategy;
564     }
565
566     /**
567      * Returns a clone of the default Connection strategy. The clone ensures that the
568      * connection strategy can be manipulated without affecting other connectors
569      * using the same strategy
570      *
571      * @return a clone of the default Connection strategy
572      */

573     public ConnectionStrategy getConnectionStrategy()
574     {
575         try
576         {
577             return (ConnectionStrategy)BeanUtils.cloneBean(connectionStrategy);
578         }
579         catch (Exception JavaDoc e)
580         {
581             throw new MuleRuntimeException(new Message(Messages.FAILED_TO_CLONE_X, "Connection Strategy"), e);
582         }
583     }
584
585     /**
586      * Sets the connection strategy used by all connectors managed in this Mule
587      * instance if the connector has no connection strategy specifically set on it.
588      *
589      * @param connectionStrategy the default strategy to use
590      */

591     public void setConnectionStrategy(ConnectionStrategy connectionStrategy)
592     {
593         this.connectionStrategy = connectionStrategy;
594     }
595
596     public boolean isEmbedded()
597     {
598         return embedded;
599     }
600
601     public void setEmbedded(boolean embedded)
602     {
603         this.embedded = embedded;
604         if (embedded)
605         {
606             serverUrl = null;
607         }
608     }
609
610     public String JavaDoc getModelType()
611     {
612         return modelType;
613     }
614
615     public void setModelType(String JavaDoc modelType)
616     {
617         this.modelType = modelType;
618     }
619
620     public String JavaDoc getEncoding()
621     {
622         return encoding;
623     }
624
625     public void setEncoding(String JavaDoc encoding)
626     {
627         if (StringUtils.isEmpty(encoding))
628         {
629             logger.warn("Cannot set encoding to null or empty String");
630             return;
631         }
632         this.encoding = encoding;
633     }
634
635     public String JavaDoc getOSEncoding()
636     {
637         return osEncoding;
638     }
639
640     public void setOSEncoding(String JavaDoc osEncoding)
641     {
642         this.osEncoding = osEncoding;
643     }
644
645     public boolean isEnableMessageEvents()
646     {
647         return enableMessageEvents;
648     }
649
650     public void setEnableMessageEvents(boolean enableMessageEvents)
651     {
652         this.enableMessageEvents = enableMessageEvents;
653     }
654
655     public WorkListener getWorkListener()
656     {
657         return workListener;
658     }
659
660     public void setWorkListener(WorkListener workListener)
661     {
662         if (workListener == null)
663         {
664             throw new NullPointerException JavaDoc("workListener");
665         }
666         this.workListener = workListener;
667     }
668 }
669
Popular Tags