Coverage Report - org.mule.api.registry.Registry
 
Classes in this File Line Coverage Branch Coverage Complexity
Registry
N/A
N/A
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.api.registry;
 8  
 
 9  
 import org.mule.api.lifecycle.Disposable;
 10  
 import org.mule.api.lifecycle.Initialisable;
 11  
 import org.mule.api.lifecycle.LifecycleException;
 12  
 
 13  
 import java.util.Collection;
 14  
 import java.util.Map;
 15  
 
 16  
 public interface Registry extends Initialisable, Disposable
 17  
 {
 18  
     // /////////////////////////////////////////////////////////////////////////
 19  
     // Lookup methods - these should NOT create a new object, only return existing ones
 20  
     // /////////////////////////////////////////////////////////////////////////
 21  
 
 22  
     /**
 23  
      * Alias method performing the lookup, here to simplify syntax when called from dynamic languages.
 24  
      */
 25  
     <T> T get(String key);
 26  
 
 27  
     /** 
 28  
      * Look up a single object by name. 
 29  
      * @return object or null if not found
 30  
      */
 31  
     <T> T lookupObject(String key);
 32  
 
 33  
     /**
 34  
      * Look up all objects of a given type.
 35  
      *
 36  
      * @return collection of objects or empty collection if none found
 37  
      */
 38  
     <T> Collection<T> lookupObjects(Class<T> type);
 39  
 
 40  
     /**
 41  
      * Look up all objects of a given type that lifecycle should be applied to. This
 42  
      * method differs from {@link #lookupObjects(Class)} in that it allows
 43  
      * implementations to provide an alternative implementation of lookup for
 44  
      * lifecycle. For example only returning pre-existing objects and not creating
 45  
      * new ones on the fly.
 46  
      * 
 47  
      * @return collection of objects or empty collection if none found
 48  
      */
 49  
     <T> Collection<T> lookupObjectsForLifecycle(Class<T> type);
 50  
     
 51  
     /**
 52  
      * Look up a single object by type.
 53  
      *
 54  
      * @return object or null if not found
 55  
      * @throws RegistrationException if more than one object is found.
 56  
      */
 57  
     <T> T lookupObject(Class<T> clazz) throws RegistrationException;
 58  
 
 59  
     /**
 60  
      * @return key/object pairs
 61  
      */
 62  
     <T> Map<String, T> lookupByType(Class<T> type);
 63  
 
 64  
     // /////////////////////////////////////////////////////////////////////////
 65  
     // Registration methods
 66  
     // /////////////////////////////////////////////////////////////////////////
 67  
 
 68  
     /**
 69  
      * Registers an object in the registry with a key.
 70  
      * @param key the key to store the value against.  This is a non-null value
 71  
      * @param value the object to store in the registry. This is a non-null value
 72  
      * @throws RegistrationException if an object with the same key already exists
 73  
      */
 74  
     void registerObject(String key, Object value) throws RegistrationException;
 75  
 
 76  
     /**
 77  
      * Registers an object in the registry with a key.
 78  
      * @param key the key to store the value against.  This is a non-null value
 79  
      * @param value the object to store in the registry. This is a non-null value
 80  
      * @param metadata an implementation specific argument that can be passed into the method
 81  
      * @throws RegistrationException if an object with the same key already exists
 82  
      */
 83  
     void registerObject(String key, Object value, Object metadata) throws RegistrationException;
 84  
 
 85  
     /**
 86  
      * Registers a Map of objects into the registry
 87  
      * @param objects a map of key value pairs, each will individually be registered in the registry
 88  
      * @throws RegistrationException if an object with the same key already exists
 89  
      */
 90  
     void registerObjects(Map<String, Object> objects) throws RegistrationException;
 91  
 
 92  
     /**
 93  
      * Will remove an object by name from the registry. By default the registry must apply all remaining lifecycle phases
 94  
      * to the object when it is removed.
 95  
      *
 96  
      * @param key the name or key of the object to remove from the registry
 97  
      * @throws RegistrationException if there is a problem unregistering the object. Typically this will be because 
 98  
      * the object's lifecycle threw an exception
 99  
      */
 100  
     void unregisterObject(String key) throws RegistrationException;
 101  
 
 102  
     /**
 103  
      * Will remove an object by name from the registry. By default the registry must apply all remaining lifecycle phases
 104  
      * to the object when it is removed.
 105  
      *
 106  
      * @param key the name or key of the object to remove from the registry
 107  
      * @param metadata an implementation specific argument that can be passed into the method
 108  
      * @throws RegistrationException if there is a problem unregistering the object. Typically this will be because
 109  
      * the object's lifecycle threw an exception
 110  
      */
 111  
     void unregisterObject(String key, Object metadata) throws RegistrationException;
 112  
 
 113  
     // /////////////////////////////////////////////////////////////////////////
 114  
     // Registry Metadata
 115  
     // /////////////////////////////////////////////////////////////////////////
 116  
 
 117  
     String getRegistryId();
 118  
 
 119  
     //TODO should this really be here
 120  
     void fireLifecycle(String phase) throws LifecycleException;
 121  
 
 122  
     boolean isReadOnly();
 123  
 
 124  
     boolean isRemote();
 125  
 }