001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Bogdan Stefanescu 018 * Florent Guillaume 019 */ 020 021package org.nuxeo.runtime.model; 022 023import java.util.Collection; 024import java.util.Map; 025import java.util.Set; 026 027import org.nuxeo.runtime.ComponentListener; 028 029/** 030 * @author Bogdan Stefanescu 031 * @author Florent Guillaume 032 */ 033public interface ComponentManager { 034 035 /** 036 * Adds a component listener. 037 * <p> 038 * Does nothing if the given listener is already registered. 039 * 040 * @param listener the component listener to add 041 */ 042 void addComponentListener(ComponentListener listener); 043 044 /** 045 * Removes a component listener. 046 * <p> 047 * Does nothing if the given listener is not registered. 048 * 049 * @param listener the component listener to remove 050 */ 051 void removeComponentListener(ComponentListener listener); 052 053 /** 054 * Handles the registration of the given registration info. 055 * <p> 056 * This is called by the main registry when all dependencies of this registration info were solved and the object 057 * can be registered. 058 * <p> 059 * If true is returned, the object will be added to the main registry under the name given in RegistrationInfo. 060 * 061 * @param ri the registration info 062 */ 063 void register(RegistrationInfo ri); 064 065 /** 066 * Handles the unregistration of the given registration info. 067 * <p> 068 * This is called by the main registry when the object is unregistered. 069 * <p> 070 * If true is returned, the object will be removed from the main registry. 071 * 072 * @param ri the registration info 073 */ 074 void unregister(RegistrationInfo ri); 075 076 /** 077 * Unregisters a component given its name. 078 * 079 * @param name the component name 080 */ 081 void unregister(ComponentName name); 082 083 /** 084 * Gets the component if there is one having the given name. 085 * 086 * @param name the component name 087 * @return the component if any was registered with that name, null otherwise 088 */ 089 RegistrationInfo getRegistrationInfo(ComponentName name); 090 091 /** 092 * Gets object instance managed by the named component. 093 * 094 * @param name the object name 095 * @return the object instance if any. may be null 096 */ 097 ComponentInstance getComponent(ComponentName name); 098 099 /** 100 * Checks whether or not a component with the given name was registered. 101 * 102 * @param name the object name 103 * @return true if an object with the given name was registered, false otherwise 104 */ 105 boolean isRegistered(ComponentName name); 106 107 /** 108 * Gets the registered components. 109 * 110 * @return a read-only collection of components 111 */ 112 Collection<RegistrationInfo> getRegistrations(); 113 114 /** 115 * Gets the pending registrations and their dependencies. 116 * 117 * @return the pending registrations 118 */ 119 Map<ComponentName, Set<ComponentName>> getPendingRegistrations(); 120 121 /** 122 * Returns the missing registrations, linked to missing target extension points. 123 * 124 * @since 8.10 125 */ 126 Map<ComponentName, Set<Extension>> getMissingRegistrations(); 127 128 /** 129 * Gets the pending extensions by component. 130 * 131 * @return the pending extensions 132 */ 133 Collection<ComponentName> getActivatingRegistrations(); 134 135 /** 136 * Gets the components that fail on applicationStarted notification 137 * 138 * @since 7.4 139 */ 140 Collection<ComponentName> getStartFailureRegistrations(); 141 142 /** 143 * Gets the number of registered objects in this registry. 144 * 145 * @return the number of registered objects 146 */ 147 int size(); 148 149 /** 150 * Shuts down the component registry. 151 * <p> 152 * This unregisters all objects registered in this registry. 153 */ 154 void shutdown(); 155 156 /** 157 * Gets the service of type serviceClass if such a service was declared by a resolved runtime component. 158 * <p> 159 * If the component is not yet activated it will be prior to return the service. 160 * 161 * @param <T> the service type 162 * @param serviceClass the service class 163 * @return the service object 164 */ 165 <T> T getService(Class<T> serviceClass); 166 167 /** 168 * Get the list of all registered service names An empty array is returned if no registered services are found. 169 * 170 * @return an array of registered service. 171 */ 172 String[] getServices(); 173 174 /** 175 * Gets the component that provides the given service. 176 * 177 * @param serviceClass the service class 178 * @return the component or null if none 179 */ 180 ComponentInstance getComponentProvidingService(Class<?> serviceClass); 181 182 Set<String> getBlacklist(); 183 184 void setBlacklist(Set<String> blacklist); 185 186}