KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > busimpl > CeltixBus


1 package org.objectweb.celtix.bus.busimpl;
2
3
4 import java.util.Map JavaDoc;
5
6 import org.objectweb.celtix.Bus;
7 import org.objectweb.celtix.BusEvent;
8 import org.objectweb.celtix.BusEventCache;
9 import org.objectweb.celtix.BusEventFilter;
10 import org.objectweb.celtix.BusEventListener;
11 import org.objectweb.celtix.BusException;
12 import org.objectweb.celtix.bindings.BindingManager;
13 import org.objectweb.celtix.bus.bindings.BindingManagerImpl;
14 import org.objectweb.celtix.bus.configuration.ConfigurationEvent;
15 import org.objectweb.celtix.bus.configuration.ConfigurationEventFilter;
16 import org.objectweb.celtix.bus.jaxws.EndpointRegistryImpl;
17 import org.objectweb.celtix.bus.management.InstrumentationManagerImpl;
18 import org.objectweb.celtix.bus.resource.ResourceManagerImpl;
19 import org.objectweb.celtix.bus.transports.TransportFactoryManagerImpl;
20 import org.objectweb.celtix.bus.workqueue.WorkQueueManagerImpl;
21 import org.objectweb.celtix.bus.wsdl.WSDLManagerImpl;
22 import org.objectweb.celtix.buslifecycle.BusLifeCycleManager;
23 import org.objectweb.celtix.configuration.Configuration;
24 import org.objectweb.celtix.jaxws.EndpointRegistry;
25 import org.objectweb.celtix.management.InstrumentationManager;
26 import org.objectweb.celtix.plugins.PluginManager;
27 import org.objectweb.celtix.resource.ResourceManager;
28 import org.objectweb.celtix.transports.TransportFactoryManager;
29 import org.objectweb.celtix.workqueue.WorkQueueManager;
30 import org.objectweb.celtix.wsdl.WSDLManager;
31
32
33 public class CeltixBus extends Bus implements BusEventListener {
34
35     public static final String JavaDoc CELTIX_WSDLMANAGER = "celtix.WSDLManager";
36     public static final String JavaDoc CELTIX_TRANSPORTFACTORYMANAGER = "celtix.TRANSPORTFACTORYMANAGER";
37
38     private Configuration configuration;
39     private BindingManager bindingManager;
40     private Object JavaDoc clientRegistry;
41     private EndpointRegistryImpl endpointRegistry;
42     private TransportFactoryManager transportFactoryManager;
43     private WSDLManager wsdlManager;
44     private PluginManager pluginManager;
45     private CeltixBusLifeCycleManager lifeCycleManager;
46     private WorkQueueManager workQueueManager;
47     private ResourceManager resourceManager;
48     private InstrumentationManager instrumentationManager;
49     private BusEventCache eventCache;
50     private BusEventProcessor eventProcessor;
51     private String JavaDoc busID;
52     private boolean servicesMonitoring;
53
54
55     /**
56      * Used by the <code>BusFactory</code> to initialize a new bus.
57      *
58      * @param args the command line configuration of this <code>Bus</code>.
59      */

60     public void initialize(String JavaDoc[] args, Map JavaDoc<String JavaDoc, Object JavaDoc> properties)
61         throws BusException {
62
63
64         lifeCycleManager = new CeltixBusLifeCycleManager();
65
66         // register a event cache for all bus events
67
eventCache = new BusEventCacheImpl(this);
68         //TODO: shall we add BusEventProcessor to a celtix bus registry?
69
eventProcessor = new BusEventProcessor(this, eventCache);
70
71         configuration = new BusConfigurationBuilder().build(args, properties);
72         //Register bus on bus configuration to receive ConfigurationEvent
73
ConfigurationEventFilter configurationEventFilter = new ConfigurationEventFilter();
74         addListener((BusEventListener)this, configurationEventFilter);
75
76         busID = (String JavaDoc)configuration.getId();
77         servicesMonitoring = configuration.getBoolean("servicesMonitoring");
78
79         instrumentationManager = new InstrumentationManagerImpl(this);
80
81         if (properties.get(CELTIX_WSDLMANAGER) != null) {
82             wsdlManager = (WSDLManager)properties.get(CELTIX_WSDLMANAGER);
83         } else {
84             wsdlManager = new WSDLManagerImpl(this);
85         }
86
87         if (properties.get(CELTIX_TRANSPORTFACTORYMANAGER) != null) {
88             transportFactoryManager = (TransportFactoryManager)properties.get(CELTIX_TRANSPORTFACTORYMANAGER);
89         } else {
90             transportFactoryManager = new TransportFactoryManagerImpl(this);
91         }
92
93         bindingManager = new BindingManagerImpl(this);
94         workQueueManager = new WorkQueueManagerImpl(this);
95         resourceManager = new ResourceManagerImpl(this);
96
97         // create and initialise the remaining objects:
98
// clientRegistry = new ClientRegistry(this);
99

100         endpointRegistry = new EndpointRegistryImpl(this);
101
102         Bus.setCurrent(this);
103
104         lifeCycleManager.initComplete();
105         //send bus component created event
106
this.sendEvent(new ComponentCreatedEvent(this));
107     }
108
109     /**
110      * Create and initialize a <code>Bus</code> object.
111      *
112      * @param args Any args, such as domain name, configuration scope,
113      * that may be needed to identify and initialize this <code>Bus</code>.
114      * @return Bus If a <code>Bus</code> has already been created using the same args,
115      * it will return the existing <code>Bus</code> object. Otherwise,
116      * it creates a new <code>Bus</code>.
117      * @throws BusException If there is an error initializing <code>Bus</code>.
118      */

119     public static synchronized Bus init(String JavaDoc[] args)
120         throws BusException {
121         return null;
122     }
123
124     /**
125      * Shuts down the <code>Bus</code>.
126      *
127      * @param wait If <code>true</code>, waits for the <code>Bus</code>
128      * to shutdown before returning, otherwise returns immediately.
129      * @throws BusException
130      */

131     public void shutdown(boolean wait) throws BusException {
132         //System.out.println("===Shutdown the bus===");
133
lifeCycleManager.preShutdown();
134
135         // shutdown in inverse order of construction
136

137         endpointRegistry.shutdown();
138
139         transportFactoryManager.shutdown();
140         bindingManager.shutdown();
141         wsdlManager.shutdown();
142         this.sendEvent(new ComponentRemovedEvent(this));
143         // handlerRegistry.shutdown(wait);
144
// clientRegistry.shutdown(wait);
145
// bindingManager.shutdown(wait);
146
// configuration.shutdown();
147

148         workQueueManager.shutdown(wait);
149         instrumentationManager.shutdown();
150         lifeCycleManager.postShutdown();
151         super.removeByID(getBusID());
152     }
153
154     /* (non-Javadoc)
155      * @see org.objectweb.celtix.Bus#run()
156      */

157     @Override JavaDoc
158     public void run() {
159         workQueueManager.run();
160     }
161
162     /**
163      * Returns the <code>Configuration</code> of this <code>Bus</code>.
164      *
165      * @return Configuration the configuration of this <code>bus</code>.
166      */

167     public Configuration getConfiguration() {
168         return configuration;
169     }
170
171     /**
172      * Returns the <code>BindingManager</code> of this <code>Bus</code>.
173      *
174      * @return BindingManager of this <code>Bus</code>.
175      */

176     public BindingManager getBindingManager() {
177         return bindingManager;
178     }
179
180     /**
181      * Returns the <code>TransportFactoryManager</code> of this <code>Bus</code>.
182      *
183      * @return TransportFactoryManager the transport factory manager of this <code>Bus</code>.
184      */

185     public TransportFactoryManager getTransportFactoryManager() {
186         return transportFactoryManager;
187     }
188
189     /**
190      * Returns the <code>ClientRegistry</code> of this <code>Bus</code>.
191      *
192      * @return ClientRegistry the client registry of this <code>Bus</code>.
193      */

194     public Object JavaDoc getClientRegistry() {
195         return clientRegistry;
196     }
197
198
199     public WSDLManager getWSDLManager() {
200         return wsdlManager;
201     }
202
203     /* (non-Javadoc)
204      * @see org.objectweb.celtix.Bus#getPluginManager()
205      */

206     @Override JavaDoc
207     public PluginManager getPluginManager() {
208         return pluginManager;
209     }
210
211     /**
212      * Returns the <code>EndpointRegistry</code> of this <code>Bus</code>.
213      *
214      * @return EndpointRegistry the endpoint registry of this <code>Bus</code>.
215      */

216     public EndpointRegistry getEndpointRegistry() {
217         return endpointRegistry;
218     }
219
220     /* (non-Javadoc)
221      * @see org.objectweb.celtix.Bus#getLifeCycleManager()
222      */

223     @Override JavaDoc
224     public BusLifeCycleManager getLifeCycleManager() {
225         return lifeCycleManager;
226     }
227
228     /* (non-Javadoc)
229      * @see org.objectweb.celtix.Bus#getWorkQueueManager()
230      */

231     @Override JavaDoc
232     public WorkQueueManager getWorkQueueManager() {
233         return workQueueManager;
234     }
235
236
237     /* (non-Javadoc)
238      * @see org.objectweb.celtix.Bus#getResourceManager()
239      */

240     @Override JavaDoc
241     public ResourceManager getResourceManager() {
242         return resourceManager;
243     }
244
245     @Override JavaDoc
246     public InstrumentationManager getInstrumentationManager() {
247         return instrumentationManager;
248     }
249
250     @Override JavaDoc
251     public void sendEvent(BusEvent event) {
252         eventProcessor.processEvent(event);
253     }
254
255     @Override JavaDoc
256     public void addListener(BusEventListener l, BusEventFilter filter) throws BusException {
257         eventProcessor.addListener(l, filter);
258     }
259
260     @Override JavaDoc
261     public void removeListener(BusEventListener l) throws BusException {
262         eventProcessor.removeListener(l);
263     }
264
265     @Override JavaDoc
266     public BusEventCache getEventCache() {
267         return eventCache;
268     }
269
270     @Override JavaDoc
271     public String JavaDoc getBusID() {
272         return busID;
273     }
274
275     public boolean isServicesMonitoring() {
276         return servicesMonitoring;
277     }
278
279     public void setServicesMonitoring(boolean pServicesMonitoring) {
280         servicesMonitoring = pServicesMonitoring;
281     }
282
283     // The notification between runtime components and corresponding
284
// configurations to support dynamic configuration
285
public void processEvent(BusEvent e) throws BusException {
286         if (e.getID().equals(ConfigurationEvent.RECONFIGURED)) {
287             String JavaDoc configName = (String JavaDoc)e.getSource();
288             /*
289             if (LOG.isLoggable(Level.INFO)) {
290                 LOG.info("CeltixBus processEvent " + configName + ": reconfigured.");
291             }
292             */

293             reConfigure(configName);
294         }
295     }
296
297     private void reConfigure(String JavaDoc configName) {
298         if ("servicesMonitoring".equals(configName)) {
299             servicesMonitoring = configuration.getBoolean("servicesMonitoring");
300         }
301
302     }
303 }
304
Popular Tags