1 /* 2 * $Id: MuleContext.java 22816 2011-09-01 22:02:55Z 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 package org.mule.api; 11 12 import org.mule.api.client.LocalMuleClient; 13 import org.mule.api.config.MuleConfiguration; 14 import org.mule.api.config.ThreadingProfile; 15 import org.mule.api.context.WorkManager; 16 import org.mule.api.context.notification.ServerNotification; 17 import org.mule.api.context.notification.ServerNotificationListener; 18 import org.mule.api.endpoint.EndpointFactory; 19 import org.mule.api.exception.RollbackSourceCallback; 20 import org.mule.api.exception.SystemExceptionHandler; 21 import org.mule.api.expression.ExpressionManager; 22 import org.mule.api.lifecycle.InitialisationException; 23 import org.mule.api.lifecycle.Lifecycle; 24 import org.mule.api.lifecycle.LifecycleManager; 25 import org.mule.api.registry.MuleRegistry; 26 import org.mule.api.registry.RegistrationException; 27 import org.mule.api.registry.Registry; 28 import org.mule.api.security.SecurityManager; 29 import org.mule.api.store.ListableObjectStore; 30 import org.mule.context.notification.NotificationException; 31 import org.mule.context.notification.ServerNotificationManager; 32 import org.mule.management.stats.AllStatistics; 33 import org.mule.util.queue.QueueManager; 34 35 import java.io.Serializable; 36 import java.util.Map; 37 import java.util.Set; 38 39 import javax.resource.spi.work.WorkListener; 40 import javax.transaction.TransactionManager; 41 import javax.xml.namespace.QName; 42 43 public interface MuleContext extends Lifecycle 44 { 45 /** 46 * Sets the Jta Transaction Manager to use with this Mule server instance 47 * 48 * @param manager the manager to use 49 * @throws Exception 50 */ 51 void setTransactionManager(TransactionManager manager) throws Exception; 52 53 /** 54 * Returns the Jta transaction manager used by this Mule server instance. or 55 * null if a transaction manager has not been set 56 * 57 * @return the Jta transaction manager used by this Mule server instance. or 58 * null if a transaction manager has not been set 59 */ 60 TransactionManager getTransactionManager(); 61 62 ServerNotificationManager getNotificationManager(); 63 64 /** 65 * Determines if the server has been started 66 * 67 * @return true if the server has been started 68 */ 69 boolean isStarted(); 70 71 /** 72 * Determines if the server has been initialised 73 * 74 * @return true if the server has been initialised 75 */ 76 boolean isInitialised(); 77 78 /** 79 * Determines if the server is being initialised 80 * 81 * @return true if the server is beening initialised 82 */ 83 boolean isInitialising(); 84 85 boolean isDisposed(); 86 87 boolean isDisposing(); 88 89 /** 90 * Registers an intenal server event listener. The listener will be notified 91 * when a particular event happens within the server. Typically this is not 92 * an event in the same sense as an MuleEvent (although there is nothing 93 * stopping the implementation of this class triggering listeners when a 94 * MuleEvent is received). 95 * <p/> 96 * The types of notifications fired is entirely defined by the implementation of 97 * this class 98 * 99 * @param l the listener to register 100 */ 101 void registerListener(ServerNotificationListener l) throws NotificationException; 102 103 /** 104 * Registers an intenal server event listener. The listener will be notified 105 * when a particular event happens within the server. Typically this is not 106 * an event in the same sense as an MuleEvent (although there is nothing 107 * stopping the implementation of this class triggering listeners when a 108 * MuleEvent is received). 109 * <p/> 110 * The types of notifications fired is entirely defined by the implementation of 111 * this class 112 * 113 * @param l the listener to register 114 * @param resourceIdentifier a particular resource name for the given type 115 * of listener For example, the resourceName could be the name of 116 * a service if the listener was a ServiceNotificationListener 117 */ 118 void registerListener(ServerNotificationListener l, String resourceIdentifier) throws NotificationException; 119 120 /** 121 * Unregisters a previously registered listener. If the listener has not 122 * already been registered, this method should return without exception 123 * 124 * @param l the listener to unregister 125 */ 126 void unregisterListener(ServerNotificationListener l); 127 128 /** 129 * Fires a server notification to all regiistered listeners 130 * 131 * @param notification the notification to fire 132 */ 133 void fireNotification(ServerNotification notification); 134 135 /** 136 * Sets the security manager used by this Mule instance to authenticate and 137 * authorise incoming and outgoing event traffic and service invocations 138 * 139 * @param securityManager the security manager used by this Mule instance to 140 * authenticate and authorise incoming and outgoing event traffic 141 * and service invocations 142 * @throws RegistrationException 143 */ 144 void setSecurityManager(SecurityManager securityManager) throws InitialisationException, RegistrationException; 145 146 /** 147 * Gets the security manager used by this Mule instance to authenticate and 148 * authorise incoming and outgoing event traffic and service invocations 149 * 150 * @return he security manager used by this Mule instance to authenticate 151 * and authorise incoming and outgoing event traffic and service 152 * invocations 153 */ 154 SecurityManager getSecurityManager(); 155 156 /** 157 * Obtains a workManager instance that can be used to schedule work in a 158 * thread pool. This will be used primarially by Agents wanting to 159 * schedule work. This work Manager must <b>never</b> be used by provider 160 * implementations as they have their own workManager accible on the 161 * connector. 162 * 163 * @return a workManager instance used by the current MuleManager 164 */ 165 WorkManager getWorkManager(); 166 167 WorkListener getWorkListener(); 168 169 /** 170 * Sets the queue manager used by mule for queuing events. This is used for 171 * service queues 172 * 173 * @param queueManager 174 * @throws RegistrationException 175 * 176 */ 177 void setQueueManager(QueueManager queueManager) throws RegistrationException; 178 179 /** 180 * Gets the queue manager used by mule for queuing events. This is used for 181 * service queues. 182 */ 183 QueueManager getQueueManager(); 184 185 AllStatistics getStatistics(); 186 187 LifecycleManager getLifecycleManager(); 188 189 MuleRegistry getRegistry(); 190 191 MuleConfiguration getConfiguration(); 192 193 ThreadingProfile getDefaultMessageDispatcherThreadingProfile(); 194 195 ThreadingProfile getDefaultMessageRequesterThreadingProfile(); 196 197 ThreadingProfile getDefaultMessageReceiverThreadingProfile(); 198 199 ThreadingProfile getDefaultServiceThreadingProfile(); 200 201 ThreadingProfile getDefaultThreadingProfile(); 202 203 // TODO This should ideally only be available via an Admin interface 204 void addRegistry(Registry registry); 205 206 // TODO This should ideally only be available via an Admin interface 207 void removeRegistry(Registry registry); 208 209 /** 210 * Returns the date when the server was started. 211 * @return the date when the server was started. 212 */ 213 long getStartDate(); 214 215 /** 216 * Returns the Expression Manager configured for this instance of Mule 217 * @return the Expression Manager configured for this instance of Mule 218 * @see org.mule.api.expression.ExpressionManager 219 */ 220 ExpressionManager getExpressionManager(); 221 222 /** 223 * Returns the EndpointFactory configured for this instance of Mule 224 * @return the EndpointFactory configured for this instance of Mule 225 * @see EndpointFactory 226 */ 227 EndpointFactory getEndpointFactory(); 228 229 void setExecutionClassLoader(ClassLoader cl); 230 231 ClassLoader getExecutionClassLoader(); 232 233 boolean isStopped(); 234 235 boolean isStopping(); 236 237 boolean isStarting(); 238 239 LocalMuleClient getClient(); 240 241 SystemExceptionHandler getExceptionListener(); 242 243 void setExceptionListener(SystemExceptionHandler exceptionListener); 244 245 void setObjectStore(String name, ListableObjectStore<Serializable> store) throws RegistrationException; 246 247 void handleException(Exception e, RollbackSourceCallback rollbackMethod); 248 249 void handleException(Exception e); 250 251 /** 252 * @return the ID of the cluster the current instance belongs to. Returns the empty string if this instance 253 * isn't part of a cluster. 254 */ 255 String getClusterId(); 256 257 /** 258 * @return the cluster node ID for the current instance belongs to. Returns 0 if this instance 259 * isn't part of a cluster. 260 */ 261 int getClusterNodeId(); 262 263 /** 264 * @return true if this instance in the designated poller. This will always be true unless the instance is part of 265 * a cluster. 266 */ 267 boolean isPrimaryPollingInstance(); 268 269 /** 270 * Generate a unique ID string; this will begin with the cluster node ID followed by a 271 * dash, e.g. "3-XXXYYY" 272 */ 273 String getUniqueIdString(); 274 275 /** 276 * Return all annotations seen in the configuration 277 */ 278 Map<QName, Set<Object>> getConfigurationAnnotations(); 279 } 280