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