1 package org.objectweb.celtix; 2 3 4 import java.lang.ref.WeakReference ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 import java.util.concurrent.ConcurrentHashMap ; 8 9 import javax.xml.ws.WebServiceException; 10 11 import org.objectweb.celtix.bindings.BindingManager; 12 import org.objectweb.celtix.buslifecycle.BusLifeCycleManager; 13 import org.objectweb.celtix.configuration.Configuration; 14 import org.objectweb.celtix.jaxws.EndpointRegistry; 15 import org.objectweb.celtix.management.InstrumentationManager; 16 import org.objectweb.celtix.plugins.PluginManager; 17 import org.objectweb.celtix.resource.ResourceManager; 18 import org.objectweb.celtix.transports.TransportFactoryManager; 19 import org.objectweb.celtix.workqueue.WorkQueueManager; 20 import org.objectweb.celtix.wsdl.WSDLManager; 21 22 26 public abstract class Bus { 27 28 public static final String BUS_CLASS_PROPERTY = "org.objectweb.celtix.BusClass"; 29 30 private static ThreadLocal <Bus> current = new ThreadLocal <Bus>(); 31 private static Map <String , WeakReference <Bus>> nameMap = 32 new ConcurrentHashMap <String , WeakReference <Bus>>(); 33 private static Bus defaultBus; 34 35 41 public static synchronized Bus init() throws BusException { 42 return init(new String [0]); 43 } 44 45 53 public static synchronized Bus init(String [] args) throws BusException { 54 return init(args, new HashMap <String , Object >()); 55 } 56 57 69 public static synchronized Bus init(String [] args, Map <String , Object > properties) throws BusException { 70 return init(args, properties, null); 71 } 72 73 87 public static synchronized Bus init(String [] args, 88 Map <String , Object > properties, 89 ClassLoader classLoader) throws BusException { 90 91 BusFactory bf = BusFactory.getInstance(); 93 Bus b = bf.getBus(args, properties, classLoader); 94 nameMap.put(b.getBusID(), new WeakReference <Bus>(b)); 95 return b; 96 } 97 98 104 public static Bus getCurrent() { 105 Bus ret = current.get(); 106 if (ret == null) { 107 ret = getDefaultBus(); 108 } 109 return ret; 110 } 111 112 113 121 public static void setCurrent(Bus bus) { 122 current.set(bus); 123 setDefaultBus(bus); 124 } 125 126 138 public static Bus getByID(String id) { 139 WeakReference <Bus> bus = nameMap.get(id); 140 if (bus != null) { 141 if (bus.get() == null) { 142 nameMap.remove(id); 143 } 144 return bus.get(); 145 } 146 return null; 147 } 148 149 protected void removeByID(String id) { 150 if (nameMap.containsKey(id)) { 151 nameMap.remove(id); 152 } 153 } 154 155 159 public abstract void sendEvent(BusEvent event); 160 161 167 public abstract void addListener(BusEventListener l, BusEventFilter filter) 168 throws BusException; 169 170 175 public abstract void removeListener(BusEventListener l) throws BusException; 176 177 182 public abstract BusEventCache getEventCache(); 183 184 191 public abstract void shutdown(boolean wait) throws BusException; 192 193 198 public abstract Configuration getConfiguration(); 199 200 205 public abstract TransportFactoryManager getTransportFactoryManager(); 206 207 212 public abstract BindingManager getBindingManager(); 213 214 219 public abstract WSDLManager getWSDLManager(); 220 221 226 public abstract PluginManager getPluginManager(); 227 228 233 public abstract BusLifeCycleManager getLifeCycleManager(); 234 235 240 public abstract WorkQueueManager getWorkQueueManager(); 241 242 243 248 public abstract ResourceManager getResourceManager(); 249 250 255 public abstract InstrumentationManager getInstrumentationManager(); 256 257 262 public abstract String getBusID(); 263 264 265 270 public abstract void run(); 271 272 275 public abstract EndpointRegistry getEndpointRegistry(); 276 277 public abstract void initialize(String [] args, 278 Map <String , Object > properties) throws BusException; 279 280 281 282 static void clearDefault() { 283 defaultBus = null; 284 } 285 286 287 290 static void clearCurrent() { 291 current.remove(); 292 } 293 296 private static synchronized Bus getDefaultBus() { 297 try { 298 if (defaultBus == null) { 299 defaultBus = Bus.init(); 300 } 301 return defaultBus; 302 } catch (BusException ex) { 303 throw new WebServiceException("unable to initialize default bus", ex); 304 } 305 } 306 307 312 private static synchronized void setDefaultBus(Bus bus) { 313 if (defaultBus == null) { 314 defaultBus = bus; 315 } 316 } 317 318 } 319 | Popular Tags |