Package ej.ecom
Class DeviceManager
- java.lang.Object
-
- ej.ecom.DeviceManager
-
public class DeviceManager extends Object
TheDeviceManagerholds theDeviceregistry. It allows to register, unregister, list devices. RegisteredRegistrationListenerare notified when a device is registered or unregistered.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <D extends Device>
voidaddRegistrationListener(RegistrationListener<D> listener, Class<D> deviceType)Adds the givenRegistrationListenerto 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>
Iterator<D>list(Class<D> deviceType)List all registered devices such as the given type is assignable from the device class.static <D extends Device>
voidregister(Class<D> deviceType, D device)Registers a new device with the given type.static <D extends Device>
voidremoveRegistrationListener(RegistrationListener<D> listener)Removes the givenRegistrationListenerfrom the list of listeners that are notified when a device is registered or unregistered.static voidunregister(Device device)Unregisters the given device.
-
-
-
Method Detail
-
addRegistrationListener
public static <D extends Device> void addRegistrationListener(RegistrationListener<D> listener, Class<D> deviceType)
Adds the givenRegistrationListenerto be notified when a device of the given type is registered or unregistered. If there is a security manager, itsSecurityManager.checkPermission(java.security.Permission)method is called with theDeviceManagerPermission.READname and the device type. The listener may be registered multiple times on different device types.- Type Parameters:
D- the type of the devices to be listened for- Parameters:
listener- the registration listenerdeviceType- the type of the devices to be listened for- Throws:
SecurityException- if a security manager exists and it does not allow the caller to listen to devices registered with the given type
-
removeRegistrationListener
public static <D extends Device> void removeRegistrationListener(RegistrationListener<D> listener)
Removes the givenRegistrationListenerfrom 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.- Type Parameters:
D- the type of the device listened for- Parameters:
listener- the registration listener
-
register
public static <D extends Device> void register(Class<D> deviceType, D device)
Registers a new device with the given type. If there is a security manager, itsSecurityManager.checkPermission(java.security.Permission)method is called withDeviceManagerPermission.MODIFYname and the device type.- Type Parameters:
D- the type of the device to be registered- Parameters:
deviceType- the type of the device to be registereddevice- the device to be registered- Throws:
SecurityException- 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 registered
-
unregister
public static void unregister(Device device)
Unregisters the given device. If there is a security manager, itsSecurityManager.checkPermission(java.security.Permission)method is called withDeviceManagerPermission.MODIFYname and the device type on which it has been registered. Some devices are registered by the underlying platform and cannot be unregistered.- Parameters:
device- the device to be unregistered- Throws:
SecurityException- if a security manager exists and it does not allow the caller to unregister a device
-
list
public static Iterator<Device> list()
List all registered devices. If there is a security manager, itsSecurityManager.checkPermission(java.security.Permission)method is called withDeviceManagerPermission.READname and theDeviceclass. This is equivalent to:list(Device.class)
- Returns:
- an iterator of all registered devices.
- Throws:
SecurityException- if a security manager exists and it doesn't allow the caller to list devices
-
list
public static <D extends Device> Iterator<D> list(Class<D> deviceType)
List all registered devices such as the given type is assignable from the device class. If there is a security manager, itsSecurityManager.checkPermission(java.security.Permission)method is called withDeviceManagerPermission.READaction and the device type.- Type Parameters:
D- the type of devices to list- Parameters:
deviceType- the type of the device to be registered- Returns:
- an iterator of all registered devices of the given type
- Throws:
SecurityException- if a security manager exists and it doesn't allow the caller to list devices of the given type
-
-