public class AtomicServiceReference<T>
extends java.lang.Object
Use this to maintain a lazy-resolved reference of cardinality one (single service reference associated with a single, lazily-resolved service instance).
Usage (following OSGi DS naming conventions/patterns):
private final AtomicServiceReference<T> serviceRef = new AtomicServiceReference<T>("referenceName"); protected void activate(ComponentContext ctx) { serviceRef.activate(ctx); } protected void deactivate(ComponentContext ctx) { serviceRef.deactivate(ctx); } protected void setReferenceName(ServiceReference<T> ref) { serviceRef.setReference(ref); } protected void unsetReferenceName(ServiceReference<T> ref) { serviceRef.unsetReference(ref); } private T getReferenceName() { return serviceRef.getService(); }
Constructor and Description |
---|
AtomicServiceReference(java.lang.String name)
Create a new AtomicServiceReference for the named service.
|
Modifier and Type | Method and Description |
---|---|
void |
activate(org.osgi.service.component.ComponentContext context) |
void |
deactivate(org.osgi.service.component.ComponentContext context) |
org.osgi.framework.ServiceReference<T> |
getReference() |
T |
getService() |
T |
getServiceWithException() |
boolean |
setReference(org.osgi.framework.ServiceReference<T> reference)
Update service reference associated with this service.
|
java.lang.String |
toString() |
boolean |
unsetReference(org.osgi.framework.ServiceReference<T> reference)
Clear the service reference associated with this service.
|
public AtomicServiceReference(java.lang.String name)
name
- Name of DS referencepublic void activate(org.osgi.service.component.ComponentContext context)
public void deactivate(org.osgi.service.component.ComponentContext context)
public boolean setReference(org.osgi.framework.ServiceReference<T> reference)
referenceName
- ServiceReference for the target service. Service references are
equal if they point to the same service registration, and are ordered by
increasing service.ranking and decreasing service.id. ServiceReferences hold
no service properties: requests/queries for properties are forwarded onto
the backing service registration.public boolean unsetReference(org.osgi.framework.ServiceReference<T> reference)
reference
- ServiceReference associated with service to be unset.public org.osgi.framework.ServiceReference<T> getReference()
public T getService()
public T getServiceWithException()
java.lang.IllegalStateException
- if the internal state is such that
locating the service is not possible or if the service
is not retrievablepublic java.lang.String toString()
toString
in class java.lang.Object