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)
Service
public Service remove(Dependency dependency)
Service
public List getDependencies()
Service
getDependencies
in interface Service
public org.osgi.framework.ServiceRegistration getServiceRegistration()
Service
null
if no service registration is
available.getServiceRegistration
in interface Service
public Object getService()
Service
null
if no service instance is available.getService
in interface Service
public void dependencyAvailable(Dependency dependency)
Service
dependencyAvailable
in interface Service
dependency
- the dependencypublic void dependencyChanged(Dependency dependency)
Service
dependencyChanged
in interface Service
dependency
- the dependencypublic void dependencyUnavailable(Dependency dependency)
Service
dependencyUnavailable
in interface Service
dependency
- the dependencypublic void start()
Service
public void stop()
Service
public Service setInterface(String serviceName, Dictionary properties)
Service
setInterface
in interface Service
serviceName
- the name of the service interfaceproperties
- the properties for this servicepublic Service setInterface(String[] serviceName, Dictionary properties)
Service
setInterface
in interface Service
serviceName
- the names of the service interfaceproperties
- the properties for this servicepublic Service setCallbacks(String init, String start, String stop, String destroy)
Service
setCallbacks
in interface Service
init
- 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)
Service
Class
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 Service
implementation
- the implementationServiceStateListener
public Service setFactory(Object factory, String createMethod)
Service
setComposition
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 Service
factory
- the factory instance or classcreateMethod
- the name of the create methodpublic Service setFactory(String createMethod)
Service
setComposition
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 Service
createMethod
- the name of the create methodpublic Service setComposition(Object instance, String getMethod)
Service
Object[]
.setComposition
in interface Service
instance
- the instance that has the methodgetMethod
- the method to invokepublic Service setComposition(String getMethod)
Service
Object[]
.setComposition
in interface Service
getMethod
- the method to invokepublic Dictionary getServiceProperties()
Service
getServiceProperties
in interface Service
null
if there are nonepublic void setServiceProperties(Dictionary serviceProperties)
Service
setServiceProperties
in interface Service
serviceProperties
- the propertiespublic void addStateListener(ServiceStateListener listener)
Service
addStateListener
in interface Service
listener
- the state listenerpublic void removeStateListener(ServiceStateListener listener)
Service
removeStateListener
in interface Service
listener
- the state listenerpublic void setAutoConfig(Class clazz, boolean autoConfig)
public ServiceComponentDependency[] getComponentDependencies()
ServiceComponent
getComponentDependencies
in interface ServiceComponent
public String getName()
ServiceComponent
getName
in interface ServiceComponent
public int getState()
ServiceComponent
getState
in interface ServiceComponent
Copyright © 2006–2013 The Apache Software Foundation. All rights reserved.