View Javadoc

1   /*
2    * $Id: Registry.java 12269 2008-07-10 04:19:03Z dfeist $
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 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.api.registry;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.agent.Agent;
15  import org.mule.api.endpoint.EndpointBuilder;
16  import org.mule.api.endpoint.EndpointFactory;
17  import org.mule.api.endpoint.ImmutableEndpoint;
18  import org.mule.api.lifecycle.Disposable;
19  import org.mule.api.lifecycle.Initialisable;
20  import org.mule.api.model.Model;
21  import org.mule.api.service.Service;
22  import org.mule.api.transformer.Transformer;
23  import org.mule.api.transformer.TransformerException;
24  import org.mule.api.transport.Connector;
25  
26  import java.util.Collection;
27  import java.util.List;
28  import java.util.Map;
29  import java.util.Properties;
30  
31  public interface Registry extends Initialisable, Disposable
32  {
33      int SCOPE_IMMEDIATE = 0;
34      int SCOPE_LOCAL = 1;
35      int SCOPE_REMOTE = 2;
36  
37      int DEFAULT_SCOPE = SCOPE_REMOTE;
38  
39      // /////////////////////////////////////////////////////////////////////////
40      // Lookup methods - these should NOT create a new object, only return existing ones
41      // /////////////////////////////////////////////////////////////////////////
42  
43      /** Look up a single object by name. */
44      Object lookupObject(String key);
45  
46      /** Look up a single object by name. */
47      Object lookupObject(String key, int scope);
48  
49      /** Look up all objects of a given type. */
50      Collection lookupObjects(Class type);
51  
52      /** Look up all objects of a given type. */
53      Collection lookupObjects(Class type, int scope);
54  
55      /** Look up a single object by type. */
56      Object lookupObject(Class type) throws RegistrationException;
57  
58      /** Look up a single object by type. */
59      Object lookupObject(Class type, int scope) throws RegistrationException;
60      
61      // TODO Not sure these methods are needed since the generic ones above can be used.
62  
63      Connector lookupConnector(String name);
64  
65      /**
66       * Looks-up endpoint builders which can be used to repeatably create endpoints with the same configuration.
67       * These endpoint builder are either global endpoints or they are builders used to create named
68       * endpoints configured on routers and exception strategies.
69       */
70      EndpointBuilder lookupEndpointBuilder(String name);
71  
72      EndpointFactory lookupEndpointFactory();
73  
74      Transformer lookupTransformer(String name);
75  
76      Service lookupService(String component);
77  
78      /**
79       * This method will return a list of {@link org.mule.api.transformer.Transformer} objects that accept the given
80       * input and return the given output type of object
81       *
82       * @param input  The  desiered input type for the transformer
83       * @param output the desired output type for the transformer
84       * @return a list of matching transformers. If there were no matchers an empty list is returned.
85       */
86      List lookupTransformers(Class input, Class output);
87  
88      /**
89       * Will find a transformer that is the closest match to the desired input and output.
90       *
91       * @param input  The  desiered input type for the transformer
92       * @param output the desired output type for the transformer
93       * @return A transformer that exactly matches or the will accept the input and output parameters
94       * @throws TransformerException will be thrown if there is more than one match
95       */
96      Transformer lookupTransformer(Class input, Class output) throws TransformerException;
97  
98      Collection/*<Service>*/ lookupServices(String model);
99  
100     Collection/*<Service>*/ lookupServices();
101 
102     Model lookupModel(String name);
103 
104     Model lookupSystemModel();
105 
106     Agent lookupAgent(String agentName);
107 
108     /** @deprecated Use lookupModel() instead */
109     Collection getModels();
110 
111     /** @deprecated Use lookupConnector() instead */
112     Collection getConnectors();
113 
114     /** @deprecated Use lookupEndpoint() instead */
115     Collection getEndpoints();
116 
117     /** @deprecated Use lookupAgent() instead */
118     Collection getAgents();
119 
120     /** @deprecated Use lookupTransformer() instead */
121     Collection getTransformers();
122 
123     // /////////////////////////////////////////////////////////////////////////
124     // Registration methods
125     // /////////////////////////////////////////////////////////////////////////
126 
127     void registerObject(String key, Object value) throws RegistrationException;
128 
129     void registerObject(String key, Object value, Object metadata) throws RegistrationException;
130 
131     void registerObjects(Map objects) throws RegistrationException;
132 
133     void unregisterObject(String key) throws MuleException;
134 
135     // TODO MULE-2139 The following methods are Mule-specific and should be split out into a separate class;
136     // leave this one as a "pure" registry interface.
137 
138     void registerConnector(Connector connector) throws MuleException;
139 
140     void unregisterConnector(String connectorName) throws MuleException;
141 
142     //TODO MULE-2494
143     void registerEndpoint(ImmutableEndpoint endpoint) throws MuleException;
144 
145     //TODO MULE-2494
146     void unregisterEndpoint(String endpointName) throws MuleException;
147 
148     void registerEndpointBuilder(String name, EndpointBuilder builder) throws MuleException;
149     
150     void registerTransformer(Transformer transformer) throws MuleException;
151 
152     void unregisterTransformer(String transformerName) throws MuleException;
153 
154     void registerService(Service service) throws MuleException;
155 
156     void unregisterService(String serviceName) throws MuleException;
157 
158     void registerModel(Model model) throws MuleException;
159 
160     void unregisterModel(String modelName) throws MuleException;
161 
162     void registerAgent(Agent agent) throws MuleException;
163 
164     void unregisterAgent(String agentName) throws MuleException;
165 
166     // /////////////////////////////////////////////////////////////////////////
167     // Creation methods
168     // /////////////////////////////////////////////////////////////////////////
169 
170     // TODO These methods are a mess (they blur lookup with creation, uris with names). Need to clean this up.
171 
172     ServiceDescriptor lookupServiceDescriptor(String type, String name, Properties overrides)
173             throws ServiceException;
174 
175     // /////////////////////////////////////////////////////////////////////////
176     // Registry Metadata
177     // /////////////////////////////////////////////////////////////////////////
178 
179     Registry getParent();
180 
181     void setParent(Registry registry);
182 
183     String getRegistryId();
184 
185     boolean isReadOnly();
186 
187     boolean isRemote();
188 
189     void setDefaultScope(int scope);
190 
191     int getDefaultScope();
192 
193     boolean isInitialised();
194 
195     boolean isInitialising();
196 
197     boolean isDisposed();
198 
199     boolean isDisposing();
200 }