David Jencks | 9c8e4b1 | 2014-11-21 22:13:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) OSGi Alliance (2012, 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 | |
| 17 | package org.osgi.service.component; |
| 18 | |
| 19 | import org.osgi.annotation.versioning.ProviderType; |
| 20 | import org.osgi.framework.Constants; |
| 21 | import org.osgi.framework.ServiceObjects; |
| 22 | import org.osgi.framework.ServiceReference; |
| 23 | |
| 24 | /** |
| 25 | * Allows multiple service objects for a service to be obtained. |
| 26 | * |
| 27 | * <p> |
| 28 | * A component instance can receive a {@code ComponentServiceObjects} object via |
| 29 | * a reference that is typed {@code ComponentServiceObjects}. |
| 30 | * |
| 31 | * <p> |
| 32 | * For services with {@link Constants#SCOPE_PROTOTYPE prototype} scope, multiple |
| 33 | * service objects for the service can be obtained. For services with |
| 34 | * {@link Constants#SCOPE_SINGLETON singleton} or {@link Constants#SCOPE_BUNDLE |
| 35 | * bundle} scope, only one, use-counted service object is available. |
| 36 | * |
| 37 | * <p> |
| 38 | * Any unreleased service objects obtained from this |
| 39 | * {@code ComponentServiceObjects} object are automatically released by Service |
| 40 | * Component Runtime when the service becomes unbound. |
| 41 | * |
| 42 | * @param <S> Type of Service |
| 43 | * @ThreadSafe |
| 44 | * @since 1.3 |
| 45 | * @see ServiceObjects |
| 46 | * @author $Id: 49fc5e86384324c73b412d8b733f715f8b55d4d6 $ |
| 47 | */ |
| 48 | @ProviderType |
| 49 | public interface ComponentServiceObjects<S> { |
| 50 | /** |
| 51 | * Returns a service object for the {@link #getServiceReference() |
| 52 | * associated} service. |
| 53 | * |
| 54 | * <p> |
| 55 | * This method will always return {@code null} when the associated service |
| 56 | * has been become unbound. |
| 57 | * |
| 58 | * @return A service object for the associated service or {@code null} if |
| 59 | * the service is unbound, the customized service object returned by |
| 60 | * a {@code ServiceFactory} does not implement the classes under |
| 61 | * which it was registered or the {@code ServiceFactory} threw an |
| 62 | * exception. |
| 63 | * @throws IllegalStateException If the associated service has been become |
| 64 | * unbound. |
| 65 | * @see #ungetService(Object) |
| 66 | */ |
| 67 | public S getService(); |
| 68 | |
| 69 | /** |
| 70 | * Releases a service object for the {@link #getServiceReference() |
| 71 | * associated} service. |
| 72 | * |
| 73 | * <p> |
| 74 | * The specified service object must no longer be used and all references to |
| 75 | * it should be destroyed after calling this method. |
| 76 | * |
| 77 | * @param service A service object previously provided by this |
| 78 | * {@code ComponentServiceObjects} object. |
| 79 | * @throws IllegalStateException If the associated service has been become |
| 80 | * unbound. |
| 81 | * @throws IllegalArgumentException If the specified service object was not |
| 82 | * provided by this {@code ComponentServiceObjects} object. |
| 83 | * @see #getService() |
| 84 | */ |
| 85 | public void ungetService(S service); |
| 86 | |
| 87 | /** |
| 88 | * Returns the {@link ServiceReference} for the service associated with this |
| 89 | * {@code ComponentServiceObjects} object. |
| 90 | * |
| 91 | * @return The {@link ServiceReference} for the service associated with this |
| 92 | * {@code ComponentServiceObjects} object. |
| 93 | */ |
| 94 | public ServiceReference<S> getServiceReference(); |
| 95 | } |