public class DeviceManager extends Object
DeviceManager
holds the Device
registry. It allows to register, unregister, list devices.
Registered RegistrationListener
are notified when a device is registered or unregistered.Modifier and Type | Method and Description |
---|---|
static <D extends Device> |
addRegistrationListener(RegistrationListener<D> listener,
Class<D> deviceType)
Adds the given
RegistrationListener to be notified when a device of the given type is registered or unregistered. |
static Iterator<Device> |
list()
List all registered devices.
|
static <D extends Device> |
list(Class<D> deviceType)
List all registered devices such as the given type is assignable from the device class.
|
static <D extends Device> |
register(Class<D> deviceType,
D device)
Registers a new device with the given type.
|
static <D extends Device> |
removeRegistrationListener(RegistrationListener<D> listener)
Removes the given
RegistrationListener from the list of listeners that are notified when a device is registered or unregistered. |
static void |
unregister(Device device)
Unregisters the given device.
|
public static <D extends Device> void addRegistrationListener(RegistrationListener<D> listener, Class<D> deviceType)
RegistrationListener
to be notified when a device of the given type is registered or unregistered.
If there is a security manager, its SecurityManager.checkPermission(java.security.Permission)
method is called with the DeviceManagerPermission.READ
name and the device type.
The listener may be registered multiple times on different device types.D
- the type of the devices to be listened forlistener
- the registration listenerdeviceType
- the type of the devices to be listened forSecurityException
- if a security manager exists and it does not allow the caller to listen to devices registered with the given typepublic static Iterator<Device> list()
SecurityManager.checkPermission(java.security.Permission)
method is called with DeviceManagerPermission.READ
name and the Device
class.
This is equivalent to:
list(Device.class)
SecurityException
- if a security manager exists and it doesn't allow the caller to list devicespublic static <D extends Device> Iterator<D> list(Class<D> deviceType)
SecurityManager.checkPermission(java.security.Permission)
method is called with DeviceManagerPermission.READ
action and the device type.D
- the type of devices to listdeviceType
- the type of the device to be registeredSecurityException
- if a security manager exists and it doesn't allow the caller to list devices of the given typepublic static <D extends Device> void register(Class<D> deviceType, D device)
SecurityManager.checkPermission(java.security.Permission)
method is called with DeviceManagerPermission.MODIFY
name and the device type.D
- the type of the device to be registereddeviceType
- the type of the device to be registereddevice
- the device to be registeredSecurityException
- if a security manager exists and it does not allow the caller to register a device with the given type.IllegalArgumentException
- if the device has already been registeredpublic static <D extends Device> void removeRegistrationListener(RegistrationListener<D> listener)
RegistrationListener
from the list of listeners that are notified when a device is registered or unregistered.
The listener may have been registered multiple times on different device types.D
- the type of the device listened forlistener
- the registration listenerpublic static void unregister(Device device)
SecurityManager.checkPermission(java.security.Permission)
method is called with DeviceManagerPermission.MODIFY
name and the device type on which it has been registered.
Some devices are registered by the underlying platform and cannot be unregistered.device
- the device to be unregisteredSecurityException
- if a security manager exists and it does not allow the caller to unregister a device