Package com._1c.g5.wiring
Class ServiceSupplier<T>
- java.lang.Object
-
- com._1c.g5.wiring.ServiceSupplier<T>
-
- Type Parameters:
T
- the supplying service type
- All Implemented Interfaces:
AutoCloseable
,Supplier<T>
public class ServiceSupplier<T> extends Object implements AutoCloseable, Supplier<T>
Supplier of an instance of the single known service for the given type. Can be used to get and use service multiple times. Clients are responsible toclose
supplier when no longer needed. Try-with-resources usage is possible.Typical usage example:
public class MyClass { private ServiceSupplier<IPublicService> publicService = ServiceAccess.supplier(IPublicService.class, MyClassPlugin.getPlugin()); public void serviceUasageMethod(EObject modelObject) { ... // Use service, when needed getPublicService().method1(modelObject); ... getPublicService().method2(modelObject); ... } public void dispose() { // Close access, when no longer needed publicService.close(); } private IPublicService getPublicService() { return publicService.get(); } }
-
-
Constructor Summary
Constructors Constructor Description ServiceSupplier(Class<T> serviceType, org.osgi.framework.BundleContext context)
Creates service supplier with the given class.ServiceSupplier(Class<T> serviceType, org.osgi.framework.BundleContext context, Map<String,?> properties)
Creates service supplier with the given class and OSGi service properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
Closes supplier service access.protected void
finalize()
Deprecated, for removal: This API element is subject to removal in a future version.Thefinalize
method has been deprecated and will be removed.T
get()
Returns a supplied service.
-
-
-
Constructor Detail
-
ServiceSupplier
public ServiceSupplier(Class<T> serviceType, org.osgi.framework.BundleContext context)
Creates service supplier with the given class.- Parameters:
serviceType
- the type of service to get, cannot benull
context
- the caller bundle context to get service, cannot benull
-
ServiceSupplier
public ServiceSupplier(Class<T> serviceType, org.osgi.framework.BundleContext context, Map<String,?> properties)
Creates service supplier with the given class and OSGi service properties.- Parameters:
serviceType
- the type of service to get, cannot benull
context
- the caller bundle context to get service, cannot benull
properties
- the service properties map, cannot benull
-
-
Method Detail
-
get
public T get()
Returns a supplied service.If service is unavailable, supplier will wait for service for a certain time to prevent initialization issues (invoking thread will be blocked) and then
ServiceUnavailableException
will be thrown.- Specified by:
get
in interfaceSupplier<T>
- Throws:
ServiceUnavailableException
- if there is no such service available or get timeout reached
-
close
public void close()
Closes supplier service access.- Specified by:
close
in interfaceAutoCloseable
-
finalize
@Deprecated(forRemoval=true) protected void finalize() throws Throwable
Deprecated, for removal: This API element is subject to removal in a future version.Thefinalize
method has been deprecated and will be removed.Ensures that theclose()
method of this supplier is called when there are no more references to it.
-
-