blob: b34a4ba70f0003dc3a9650192cad7534ba3b4d2a [file] [log] [blame]
David Jenckse165efc2014-06-15 01:09:26 +00001/*
2 * Copyright (c) OSGi Alliance (2013, 2014). All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.osgi.service.component.runtime;
18
19import java.util.Collection;
David Jencksbae44842014-06-21 20:15:24 +000020import org.osgi.annotation.versioning.ProviderType;
David Jenckse165efc2014-06-15 01:09:26 +000021import org.osgi.framework.Bundle;
22import org.osgi.service.component.ComponentContext;
23import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
24import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
David Jencksbae44842014-06-21 20:15:24 +000025import org.osgi.util.promise.Promise;
David Jenckse165efc2014-06-15 01:09:26 +000026
27/**
28 * The {@code ServiceComponentRuntime} service represents the Declarative
29 * Services main controller also known as the Service Component Runtime or SCR
30 * for short. It provides access to the components managed by the Service
31 * Component Runtime.
32 *
33 * <p>
34 * This service differentiates between a {@link ComponentDescriptionDTO} and a
35 * {@link ComponentConfigurationDTO}. A {@link ComponentDescriptionDTO} is a
36 * representation of a declared component description. A
37 * {@link ComponentConfigurationDTO} is a representation of an actual instance of a
38 * declared component description parameterized by component properties.
39 * <p>
40 *
41 * Access to this service requires the
42 * {@code ServicePermission[ServiceComponentRuntime, GET]} permission. It is
43 * intended that only administrative bundles should be granted this permission
44 * to limit access to the potentially intrusive methods provided by this
45 * service.
46 *
47 * @ThreadSafe
48 * @since 1.3
David Jencksbae44842014-06-21 20:15:24 +000049 * @author $Id: 2b9c69ef323cb6b4be2601f893bea8505c984980 $
David Jenckse165efc2014-06-15 01:09:26 +000050 */
David Jencksbae44842014-06-21 20:15:24 +000051@ProviderType
David Jenckse165efc2014-06-15 01:09:26 +000052public interface ServiceComponentRuntime {
53
54 /**
55 * Returns the component descriptions declared by the specified active
56 * bundles.
57 *
58 * <p>
59 * Only component descriptions from active bundles are returned. If the
60 * specified bundles have no declared components or are not active, an empty
61 * collection is returned.
62 *
63 * @param bundles The bundles whose declared component descriptions are to
64 * be returned. Specifying no bundles, or the equivalent of an empty
65 * {@code Bundle} array, will return the declared component
66 * descriptions from all active bundles.
67 * @return The declared component descriptions of the specified active
68 * {@code bundles}. An empty collection is returned if there are no
69 * component descriptions for the specified active bundles.
70 */
71 Collection<ComponentDescriptionDTO> getComponentDescriptionDTOs(Bundle... bundles);
72
73 /**
74 * Returns the {@link ComponentDescriptionDTO} declared with the specified name
75 * by the specified bundle.
76 *
77 * <p>
78 * Only component descriptions from active bundles are returned.
79 * {@code null} if no such component is declared by the given {@code bundle}
80 * or the bundle is not active.
81 *
82 * @param bundle The bundle declaring the component description. Must not be
83 * {@code null}.
84 * @param name The name of the component description. Must not be
85 * {@code null}.
86 * @return The declared component description or {@code null} if the
87 * specified bundle is not active or does not declare a component
88 * description with the specified name.
89 */
90 ComponentDescriptionDTO getComponentDescriptionDTO(Bundle bundle, String name);
91
92 /**
93 * Returns the component configurations for the specified component
94 * description.
95 *
96 * @param description The component description. Must not be {@code null}.
97 * @return A collection containing a snapshot of the current component
98 * configurations for the specified component description. An empty
99 * collection is returned if there are none.
100 */
101 Collection<ComponentConfigurationDTO> getComponentConfigurationDTOs(ComponentDescriptionDTO description);
102
103 /**
104 * Returns whether the specified component description is currently enabled.
105 *
106 * <p>
107 * The enabled state of a component description is initially set by the
108 * {@link ComponentDescriptionDTO#defaultEnabled enabled} attribute of the
109 * component description.
110 *
111 * @param description The component description. Must not be {@code null}.
112 * @return {@code true} if the specified component description is currently
113 * enabled. Otherwise, {@code false}.
114 * @see #enableComponent(ComponentDescriptionDTO)
115 * @see #disableComponent(ComponentDescriptionDTO)
116 * @see ComponentContext#disableComponent(String)
117 * @see ComponentContext#enableComponent(String)
118 */
119 boolean isComponentEnabled(ComponentDescriptionDTO description);
120
121 /**
122 * Enables the specified component description.
123 *
124 * <p>
125 * If the specified component description is currently enabled, this method
126 * has no effect.
127 *
David Jencksbae44842014-06-21 20:15:24 +0000128 * <p>
129 * This method must return after changing the enabled state of the specified
130 * component description. Any actions that result from this, such as
131 * activating or deactivating a component configuration, must occur
132 * asynchronously to this method call.
133 *
David Jenckse165efc2014-06-15 01:09:26 +0000134 * @param description The component description to enable. Must not be
135 * {@code null}.
David Jencksbae44842014-06-21 20:15:24 +0000136 * @return A promise that will be resolved when the actions that result from
137 * changing the enabled state of the specified component have
138 * completed.
David Jenckse165efc2014-06-15 01:09:26 +0000139 * @see #isComponentEnabled(ComponentDescriptionDTO)
140 */
David Jencksbae44842014-06-21 20:15:24 +0000141 Promise<Void> enableComponent(ComponentDescriptionDTO description);
David Jenckse165efc2014-06-15 01:09:26 +0000142
143 /**
144 * Disables the specified component description.
145 *
146 * <p>
147 * If the specified component description is currently disabled, this method
148 * has no effect.
149 *
David Jencksbae44842014-06-21 20:15:24 +0000150 * <p>
151 * This method must return after changing the enabled state of the specified
152 * component description. Any actions that result from this, such as
153 * activating or deactivating a component configuration, must occur
154 * asynchronously to this method call.
155 *
David Jenckse165efc2014-06-15 01:09:26 +0000156 * @param description The component description to disable. Must not be
157 * {@code null}.
David Jencksbae44842014-06-21 20:15:24 +0000158 * @return A promise that will be resolved when the actions that result from
159 * changing the enabled state of the specified component have
160 * completed.
David Jenckse165efc2014-06-15 01:09:26 +0000161 * @see #isComponentEnabled(ComponentDescriptionDTO)
162 */
David Jencksbae44842014-06-21 20:15:24 +0000163 Promise<Void> disableComponent(ComponentDescriptionDTO description);
David Jenckse165efc2014-06-15 01:09:26 +0000164}