View Javadoc

1   /*
2    * $Id: Registry.java 19392 2010-09-07 14:26:44Z dirk.olmes $
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.api.registry;
12  
13  import org.mule.api.lifecycle.Disposable;
14  import org.mule.api.lifecycle.Initialisable;
15  import org.mule.api.lifecycle.LifecycleException;
16  
17  import java.util.Collection;
18  import java.util.Map;
19  
20  public interface Registry extends Initialisable, Disposable
21  {
22      // /////////////////////////////////////////////////////////////////////////
23      // Lookup methods - these should NOT create a new object, only return existing ones
24      // /////////////////////////////////////////////////////////////////////////
25  
26      /**
27       * Alias method performing the lookup, here to simplify syntax when called from dynamic languages.
28       */
29      <T> T get(String key);
30  
31      /** 
32       * Look up a single object by name. 
33       * @return object or null if not found
34       */
35      <T> T lookupObject(String key);
36  
37      /**
38       * Look up all objects of a given type.
39       *
40       * @return collection of objects or empty collection if none found
41       */
42      <T> Collection<T> lookupObjects(Class<T> type);
43  
44      /**
45       * Look up a single object by type.
46       *
47       * @return object or null if not found
48       * @throws RegistrationException if more than one object is found.
49       */
50      <T> T lookupObject(Class<T> clazz) throws RegistrationException;
51  
52      /**
53       * @return key/object pairs
54       */
55      <T> Map<String, T> lookupByType(Class<T> type);
56  
57      // /////////////////////////////////////////////////////////////////////////
58      // Registration methods
59      // /////////////////////////////////////////////////////////////////////////
60  
61      /**
62       * Registers an object in the registry with a key.
63       * @param key the key to store the value against.  This is a non-null value
64       * @param value the object to store in the registry. This is a non-null value
65       * @throws RegistrationException if an object with the same key already exists
66       */
67      void registerObject(String key, Object value) throws RegistrationException;
68  
69      /**
70       * Registers an object in the registry with a key.
71       * @param key the key to store the value against.  This is a non-null value
72       * @param value the object to store in the registry. This is a non-null value
73       * @param metadata an implementation specific argument that can be passed into the method
74       * @throws RegistrationException if an object with the same key already exists
75       */
76      void registerObject(String key, Object value, Object metadata) throws RegistrationException;
77  
78      /**
79       * Registers a Map of objects into the registry
80       * @param objects a map of key value pairs, each will individually be registered in the registry
81       * @throws RegistrationException if an object with the same key already exists
82       */
83      void registerObjects(Map<String, Object> objects) throws RegistrationException;
84  
85      /**
86       * Will remove an object by name from the registry. By default the registry must apply all remaining lifecycle phases
87       * to the object when it is removed.
88       *
89       * @param key the name or key of the object to remove from the registry
90       * @throws RegistrationException if there is a problem unregistering the object. Typically this will be because 
91       * the object's lifecycle threw an exception
92       */
93      void unregisterObject(String key) throws RegistrationException;
94  
95      /**
96       * Will remove an object by name from the registry. By default the registry must apply all remaining lifecycle phases
97       * to the object when it is removed.
98       *
99       * @param key the name or key of the object to remove from the registry
100      * @param metadata an implementation specific argument that can be passed into the method
101      * @throws RegistrationException if there is a problem unregistering the object. Typically this will be because
102      * the object's lifecycle threw an exception
103      */
104     void unregisterObject(String key, Object metadata) throws RegistrationException;
105 
106     // /////////////////////////////////////////////////////////////////////////
107     // Registry Metadata
108     // /////////////////////////////////////////////////////////////////////////
109 
110     String getRegistryId();
111 
112     //TODO should this really be here
113     void fireLifecycle(String phase) throws LifecycleException;
114 
115     boolean isReadOnly();
116 
117     boolean isRemote();
118 }