View Javadoc

1   /*
2    * $Id: DefaultsConfigurationBuilder.java 23211 2011-10-18 17:23:03Z mike.schilling $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
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.builders;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.MuleException;
15  import org.mule.api.config.MuleProperties;
16  import org.mule.api.config.ThreadingProfile;
17  import org.mule.api.model.Model;
18  import org.mule.api.registry.MuleRegistry;
19  import org.mule.api.registry.RegistrationException;
20  import org.mule.api.store.ObjectStore;
21  import org.mule.config.ChainedThreadingProfile;
22  import org.mule.config.bootstrap.SimpleRegistryBootstrap;
23  import org.mule.endpoint.DefaultEndpointFactory;
24  import org.mule.model.seda.SedaModel;
25  import org.mule.retry.policies.NoRetryPolicyTemplate;
26  import org.mule.security.MuleSecurityManager;
27  import org.mule.util.DefaultStreamCloserService;
28  import org.mule.util.queue.QueueManager;
29  import org.mule.util.queue.TransactionalQueueManager;
30  import org.mule.util.store.DefaultObjectStoreFactoryBean;
31  import org.mule.util.store.MuleObjectStoreManager;
32  
33  /**
34   * Configures defaults required by Mule. This configuration builder is used to
35   * configure mule with these defaults when no other ConfigurationBuilder that sets
36   * these is being used. This is used by both AbstractMuleTestCase and MuleClient.
37   * <br>
38   * <br>
39   * Default instances of the following are configured:
40   * <ul>
41   * <li> {@link SimpleRegistryBootstrap}
42   * <li> {@link QueueManager}
43   * <li> {@link SecurityManager}
44   * <li> {@link ObjectStore}
45   * <li> {@link DefaultEndpointFactory}
46   * <li> {@link Model} systemModel
47   * <li> {@link ThreadingProfile} defaultThreadingProfile
48   * <li> {@link ThreadingProfile} defaultMessageDispatcherThreadingProfile
49   * <li> {@link ThreadingProfile} defaultMessageRequesterThreadingProfile
50   * <li> {@link ThreadingProfile} defaultMessageReceiverThreadingProfile
51   * <li> {@link ThreadingProfile} defaultComponentThreadingProfile
52   * </ul>
53   */
54  public class DefaultsConfigurationBuilder extends AbstractConfigurationBuilder
55  {
56      @Override
57      protected void doConfigure(MuleContext muleContext) throws Exception
58      {
59          MuleRegistry registry = muleContext.getRegistry();
60  
61          registry.registerObject(MuleProperties.OBJECT_MULE_SIMPLE_REGISTRY_BOOTSTRAP,
62              new SimpleRegistryBootstrap());
63  
64          configureQueueManager(muleContext);
65  
66          registry.registerObject(MuleProperties.OBJECT_SECURITY_MANAGER, new MuleSecurityManager());
67  
68          registry.registerObject(MuleProperties.OBJECT_STORE_DEFAULT_IN_MEMORY_NAME, DefaultObjectStoreFactoryBean.createDefaultInMemoryObjectStore());
69          registry.registerObject(MuleProperties.OBJECT_STORE_DEFAULT_PERSISTENT_NAME, DefaultObjectStoreFactoryBean.createDefaultPersistentObjectStore());
70          registry.registerObject(MuleProperties.OBJECT_STORE_MANAGER, new MuleObjectStoreManager());
71  
72          registry.registerObject(MuleProperties.OBJECT_MULE_ENDPOINT_FACTORY, new DefaultEndpointFactory());
73          registry.registerObject(MuleProperties.OBJECT_MULE_STREAM_CLOSER_SERVICE, new DefaultStreamCloserService());
74  
75          configureThreadingProfiles(registry);
76  
77          registry.registerObject(MuleProperties.OBJECT_DEFAULT_RETRY_POLICY_TEMPLATE, new NoRetryPolicyTemplate());
78  
79          configureSystemModel(registry);
80      }
81  
82      protected void configureQueueManager(MuleContext muleContext) throws RegistrationException
83      {
84          QueueManager queueManager = new TransactionalQueueManager();
85          muleContext.getRegistry().registerObject(MuleProperties.OBJECT_QUEUE_MANAGER, queueManager);
86      }
87  
88      protected void configureThreadingProfiles(MuleRegistry registry) throws RegistrationException
89      {
90          ThreadingProfile defaultThreadingProfile = new ChainedThreadingProfile();
91          registry.registerObject(MuleProperties.OBJECT_DEFAULT_THREADING_PROFILE, defaultThreadingProfile);
92  
93          registry.registerObject(MuleProperties.OBJECT_DEFAULT_MESSAGE_RECEIVER_THREADING_PROFILE,
94              new ChainedThreadingProfile(defaultThreadingProfile));
95          registry.registerObject(MuleProperties.OBJECT_DEFAULT_MESSAGE_REQUESTER_THREADING_PROFILE,
96              new ChainedThreadingProfile(defaultThreadingProfile));
97          registry.registerObject(MuleProperties.OBJECT_DEFAULT_MESSAGE_DISPATCHER_THREADING_PROFILE,
98              new ChainedThreadingProfile(defaultThreadingProfile));
99          registry.registerObject(MuleProperties.OBJECT_DEFAULT_SERVICE_THREADING_PROFILE,
100             new ChainedThreadingProfile(defaultThreadingProfile));
101     }
102 
103     protected void configureSystemModel(MuleRegistry registry) throws MuleException
104     {
105         Model systemModel = new SedaModel();
106         systemModel.setName(MuleProperties.OBJECT_SYSTEM_MODEL);
107 
108         registry.registerModel(systemModel);
109     }
110 }