public class ServiceImpl extends Object implements Service, ServiceComponent
STATE_NAMES, STATE_REGISTERED, STATE_UNREGISTERED| Constructor and Description |
|---|
ServiceImpl(org.osgi.framework.BundleContext context,
DependencyManager manager,
Logger logger) |
| Modifier and Type | Method and Description |
|---|---|
Service |
add(Dependency dependency)
Adds a new dependency to this service.
|
void |
addStateListener(ServiceStateListener listener)
Adds a service state listener to this service.
|
void |
dependencyAvailable(Dependency dependency)
Will be called when the dependency becomes available.
|
void |
dependencyChanged(Dependency dependency)
Will be called when the dependency becomes unavailable.
|
void |
dependencyUnavailable(Dependency dependency)
Will be called when the dependency changes.
|
ServiceComponentDependency[] |
getComponentDependencies()
Returns a list of dependencies associated with this service component.
|
List |
getDependencies()
Returns a list of dependencies.
|
String |
getName()
Returns the name of this service component.
|
Object |
getService()
Returns the service instance for this service.
|
Dictionary |
getServiceProperties()
Returns the service properties associated with the service.
|
org.osgi.framework.ServiceRegistration |
getServiceRegistration()
Returns the service registration for this service.
|
int |
getState()
Returns the state of this service component.
|
Service |
remove(Dependency dependency)
Removes a dependency from this service.
|
void |
removeStateListener(ServiceStateListener listener)
Removes a service state listener from this service.
|
void |
setAutoConfig(Class clazz,
boolean autoConfig) |
void |
setAutoConfig(Class clazz,
String instanceName) |
Service |
setCallbacks(String init,
String start,
String stop,
String destroy)
Sets the names of the methods used as callbacks.
|
Service |
setComposition(Object instance,
String getMethod)
Sets the instance and method to invoke to get back all instances that
are part of a composition and need dependencies injected.
|
Service |
setComposition(String getMethod)
Sets the method to invoke on the service implementation to get back all
instances that are part of a composition and need dependencies injected.
|
Service |
setFactory(Object factory,
String createMethod)
Sets the factory to use to create the implementation.
|
Service |
setFactory(String createMethod)
Sets the factory to use to create the implementation.
|
Service |
setImplementation(Object implementation)
Sets the implementation for this service.
|
Service |
setInterface(String[] serviceName,
Dictionary properties)
Sets the public interfaces under which this service should be registered
in the OSGi service registry.
|
Service |
setInterface(String serviceName,
Dictionary properties)
Sets the public interface under which this service should be registered
in the OSGi service registry.
|
void |
setServiceProperties(Dictionary serviceProperties)
Sets the service properties associated with the service.
|
void |
start()
Starts the service.
|
void |
stop()
Stops the service.
|
String |
toString() |
public ServiceImpl(org.osgi.framework.BundleContext context,
DependencyManager manager,
Logger logger)
public Service add(Dependency dependency)
Servicepublic Service remove(Dependency dependency)
Servicepublic List getDependencies()
ServicegetDependencies in interface Servicepublic org.osgi.framework.ServiceRegistration getServiceRegistration()
Servicenull if no service registration is
available.getServiceRegistration in interface Servicepublic Object getService()
Servicenull if no service instance is available.getService in interface Servicepublic void dependencyAvailable(Dependency dependency)
ServicedependencyAvailable in interface Servicedependency - the dependencypublic void dependencyChanged(Dependency dependency)
ServicedependencyChanged in interface Servicedependency - the dependencypublic void dependencyUnavailable(Dependency dependency)
ServicedependencyUnavailable in interface Servicedependency - the dependencypublic void start()
Servicepublic void stop()
Servicepublic Service setInterface(String serviceName, Dictionary properties)
ServicesetInterface in interface ServiceserviceName - the name of the service interfaceproperties - the properties for this servicepublic Service setInterface(String[] serviceName, Dictionary properties)
ServicesetInterface in interface ServiceserviceName - the names of the service interfaceproperties - the properties for this servicepublic Service setCallbacks(String init, String start, String stop, String destroy)
ServicesetCallbacks in interface Serviceinit - the name of the init methodstart - the name of the start methodstop - the name of the stop methoddestroy - the name of the destroy methodpublic Service setImplementation(Object implementation)
ServiceClass
that will be instantiated using its default constructor when the
required dependencies are resolved (effectively giving you a lazy
instantiation mechanism).
There are four special methods that are called when found through
reflection to give you some life-cycle management options:
init() is invoked right after the instance has been
created, and before any dependencies are resolved, and can be used to
initialize the internal state of the instancestart() is invoked after the required dependencies
are resolved and injected, and before the service is registeredstop() is invoked right after the service is
unregistereddestroy() is invoked after all dependencies are
removedsetImplementation in interface Serviceimplementation - the implementationServiceStateListenerpublic Service setFactory(Object factory, String createMethod)
ServicesetComposition to create a
composition of instances that work together to implement a service. The
factory itself can also be instantiated lazily by not specifying an
instance, but a Class.setFactory in interface Servicefactory - the factory instance or classcreateMethod - the name of the create methodpublic Service setFactory(String createMethod)
ServicesetComposition to create a composition of instances that
work together to implement a service.
Note that currently, there is no default for the factory, so please use
setFactory(factory, createMethod) instead.
setFactory in interface ServicecreateMethod - the name of the create methodpublic Service setComposition(Object instance, String getMethod)
ServiceObject[].setComposition in interface Serviceinstance - the instance that has the methodgetMethod - the method to invokepublic Service setComposition(String getMethod)
ServiceObject[].setComposition in interface ServicegetMethod - the method to invokepublic Dictionary getServiceProperties()
ServicegetServiceProperties in interface Servicenull if there are nonepublic void setServiceProperties(Dictionary serviceProperties)
ServicesetServiceProperties in interface ServiceserviceProperties - the propertiespublic void addStateListener(ServiceStateListener listener)
ServiceaddStateListener in interface Servicelistener - the state listenerpublic void removeStateListener(ServiceStateListener listener)
ServiceremoveStateListener in interface Servicelistener - the state listenerpublic void setAutoConfig(Class clazz, boolean autoConfig)
public ServiceComponentDependency[] getComponentDependencies()
ServiceComponentgetComponentDependencies in interface ServiceComponentpublic String getName()
ServiceComponentgetName in interface ServiceComponentpublic int getState()
ServiceComponentgetState in interface ServiceComponentCopyright © 2006-2013 The Apache Software Foundation. All Rights Reserved.