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     * Gets the pending extensions by component.
123     *
124     * @return the pending extensions
125     */
126    Collection<ComponentName> getActivatingRegistrations();
127
128
129    /**
130     * Gets the components that fail on applicationStarted notification
131     *
132     * @since 7.4
133     */
134    Collection<ComponentName> getStartFailureRegistrations();
135
136    /**
137     * Gets the number of registered objects in this registry.
138     *
139     * @return the number of registered objects
140     */
141    int size();
142
143    /**
144     * Shuts down the component registry.
145     * <p>
146     * This unregisters all objects registered in this registry.
147     */
148    void shutdown();
149
150    /**
151     * Gets the service of type serviceClass if such a service was declared by a resolved runtime component.
152     * <p>
153     * If the component is not yet activated it will be prior to return the service.
154     *
155     * @param <T> the service type
156     * @param serviceClass the service class
157     * @return the service object
158     */
159    <T> T getService(Class<T> serviceClass);
160
161    /**
162     * Get the list of all registered service names An empty array is returned if no registered services are found.
163     *
164     * @return an array of registered service.
165     */
166    String[] getServices();
167
168    /**
169     * Gets the component that provides the given service.
170     *
171     * @param serviceClass the service class
172     * @return the component or null if none
173     */
174    ComponentInstance getComponentProvidingService(Class<?> serviceClass);
175
176    Set<String> getBlacklist();
177
178    void setBlacklist(Set<String> blacklist);
179
180}