public class DefaultServiceManager<T> extends Object implements ServiceManager<T>
Creates instance of the defined service class when it is first needed (acts as a factory),
manages the instance in a field (it's shared), and synchronizes (locks) all
multi-threaded access. A locking attempt will timeout after 500 milliseconds with
a runtime exception if another operation is already in progress. Override
getLockTimeoutMillis()
to customize this behavior, e.g. if your service
bean is slow and requires more time for typical action executions or state
variable reading.
Modifier and Type | Class and Description |
---|---|
protected class |
DefaultServiceManager.DefaultPropertyChangeListener |
Modifier and Type | Field and Description |
---|---|
protected ReentrantLock |
lock |
protected PropertyChangeSupport |
propertyChangeSupport |
protected LocalService<T> |
service |
protected Class<T> |
serviceClass |
protected T |
serviceImpl |
EVENTED_STATE_VARIABLES
Modifier | Constructor and Description |
---|---|
protected |
DefaultServiceManager(LocalService<T> service) |
|
DefaultServiceManager(LocalService<T> service,
Class<T> serviceClass) |
Modifier and Type | Method and Description |
---|---|
protected PropertyChangeListener |
createPropertyChangeListener(T serviceImpl) |
protected PropertyChangeSupport |
createPropertyChangeSupport(T serviceImpl) |
protected T |
createServiceInstance() |
void |
execute(Command<T> cmd)
Double-dispatch of arbitrary commands, used by action executors and state variable accessors.
|
Collection<StateVariableValue> |
getCurrentState()
Reading the state of a service manually.
|
protected Collection<StateVariableValue> |
getCurrentState(String[] variableNames) |
T |
getImplementation() |
protected int |
getLockTimeoutMillis() |
PropertyChangeSupport |
getPropertyChangeSupport()
Provides the capability to monitor the service for state changes.
|
LocalService<T> |
getService() |
protected void |
init() |
protected void |
lock() |
protected Collection<StateVariableValue> |
readInitialEventedStateVariableValues() |
String |
toString() |
protected void |
unlock() |
protected final LocalService<T> service
protected final ReentrantLock lock
protected T serviceImpl
protected PropertyChangeSupport propertyChangeSupport
protected DefaultServiceManager(LocalService<T> service)
public DefaultServiceManager(LocalService<T> service, Class<T> serviceClass)
protected void lock()
protected void unlock()
protected int getLockTimeoutMillis()
public LocalService<T> getService()
getService
in interface ServiceManager<T>
public T getImplementation()
getImplementation
in interface ServiceManager<T>
ActionExecutor
s
and StateVariableAccessor
s.public PropertyChangeSupport getPropertyChangeSupport()
ServiceManager
The GENA subsystem expects that this adapter will notify its listeners whenever any evented UPnP state variable of the service has changed its state. The following change event is expected:
ServiceManager.EVENTED_STATE_VARIABLES
.null
, only the current state has to be included.Collection
of StateVariableValue
,
representing the current state of the service after the change.The collection has to include values for all state variables, no matter what state variable was updated. Any other event is ignored (e.g. individual property changes).
getPropertyChangeSupport
in interface ServiceManager<T>
public void execute(Command<T> cmd) throws Exception
ServiceManager
The service manager will execute the given Command
and it
might decorate the execution, for example, by locking/unlocking access to a shared service
implementation before and after the execution.
execute
in interface ServiceManager<T>
cmd
- The command to execute.Exception
- Any exception, without wrapping, as thrown by Command.execute(ServiceManager)
public Collection<StateVariableValue> getCurrentState() throws Exception
ServiceManager
getCurrentState
in interface ServiceManager<T>
Collection
of StateVariableValue
, representing
the current state of the service, that is, all evented state variable values.Exception
- Any error that occurred when the service's state was accessed.protected Collection<StateVariableValue> getCurrentState(String[] variableNames) throws Exception
Exception
protected void init()
protected PropertyChangeSupport createPropertyChangeSupport(T serviceImpl) throws Exception
Exception
protected PropertyChangeListener createPropertyChangeListener(T serviceImpl) throws Exception
Exception
protected Collection<StateVariableValue> readInitialEventedStateVariableValues() throws Exception
Exception
Copyright © 2016 4th Line GmbH, Switzerland. All rights reserved.