Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.teleal.cling.model
Class DefaultServiceManager<T>

    java.lang.Object
      org.teleal.cling.model.DefaultServiceManager<T>

All Implemented Interfaces:
  ServiceManager<T>

    public class DefaultServiceManager<T>

extends Object
implements ServiceManager<T>

Default implementation, creates and manages a single instance of a plain Java bean.

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.

Author:
  Christian Bauer

Nested Class Summary
`protected class` | `DefaultServiceManager.DefaultPropertyChangeListener`

Field Summary
`protected ReentrantLock` | `lock`
`protected PropertyChangeSupport` | `propertyChangeSupport`
`protected LocalService<T>` | `service`
`protected Class<T>` | `serviceClass`
`protected T` | `serviceImpl`

Fields inherited from interface org.teleal.cling.model.ServiceManager
`EVENTED_STATE_VARIABLES`

Constructor Summary
`protected` | `DefaultServiceManager(LocalService<T> service)`
`` | `DefaultServiceManager(LocalService<T> service, Class<T> serviceClass)`

Method Summary
`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.
`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()`
`Collection<StateVariableValue>` | `readEventedStateVariableValues()` Reading the state of a service manually.
`String` | `toString()`
`protected void` | `unlock()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### service

    protected final LocalService<T> service

### serviceClass

    protected final Class<T> serviceClass

### lock

    protected final ReentrantLock lock

### serviceImpl

    protected T serviceImpl

### propertyChangeSupport

    protected PropertyChangeSupport propertyChangeSupport

Constructor Detail

### DefaultServiceManager

    protected DefaultServiceManager(LocalService<T> service)

### DefaultServiceManager

    public DefaultServiceManager(LocalService<T> service,
                                 Class<T> serviceClass)

Method Detail

### lock

    protected void lock()

### unlock

    protected void unlock()

### getLockTimeoutMillis

    protected int getLockTimeoutMillis()

### getService

    public LocalService<T> getService()

  Specified by:
    `getService` in interface `ServiceManager<T>`
  Returns:
    The metadata of the service to which this manager is assigned.

### getImplementation

    public T getImplementation()

  Specified by:
    `getImplementation` in interface `ServiceManager<T>`
  Returns:
    An instance with the interface expected by the bound `ActionExecutor`s and `StateVariableAccessor`s.

### getPropertyChangeSupport

    public PropertyChangeSupport getPropertyChangeSupport()

  Description copied from interface: `ServiceManager`
  Provides the capability to monitor the service for state changes.

  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:

  - The property name is the constant `ServiceManager.EVENTED_STATE_VARIABLES`.
  - The "old value" can be `null`, only the current state has to be included.
  - The "new value" is a `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).

  Specified by:
    `getPropertyChangeSupport` in interface `ServiceManager<T>`
  Returns:
    An adapter that will notify its listeners whenever any evented state variable changes.

### execute

    public void execute(Command<T> cmd)
                 throws Exception

  Description copied from interface: `ServiceManager`
  Double-dispatch of arbitrary commands, used by action executors and state variable accessors.

  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.

  Specified by:
    `execute` in interface `ServiceManager<T>`
  Parameters:
    `cmd` - The command to execute.
  Throws:
    `Exception` - Any exception, without wrapping, as thrown by `Command.execute(ServiceManager)`

### readEventedStateVariableValues

    public Collection<StateVariableValue> readEventedStateVariableValues()
                                                                  throws Exception

  Description copied from interface: `ServiceManager`
  Reading the state of a service manually.

  Specified by:
    `readEventedStateVariableValues` in interface `ServiceManager<T>`
  Returns:
    A `Collection` of `StateVariableValue`, representing the current state of the service.
  Throws:
    `Exception` - Any error that occured when the service's state was accessed.

### init

    protected void init()

### createServiceInstance

    protected T createServiceInstance()
                               throws Exception

  Throws:
    `Exception`

### createPropertyChangeSupport

    protected PropertyChangeSupport createPropertyChangeSupport(T serviceImpl)
                                                         throws Exception

  Throws:
    `Exception`

### createPropertyChangeListener

    protected PropertyChangeListener createPropertyChangeListener(T serviceImpl)
                                                           throws Exception

  Throws:
    `Exception`

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011 Teleal GmbH, Switzerland. All Rights Reserved.