The UPnP Device Specification allows applications to listen for UPnP service events which are generated when the value of a state variable changes. The basic steps to do to subscribe for events are:
Providing an Event Listener
Interested in receiving events applications should implement the org.osgi.service.upnp.UPnPEventListener interface and register it as a service if the listener is in a bundle running on an OSGi framework.
You should provide a registration property UPnPEventListener.UPNP_FILTER with value a Filter object, which indicates the interesting UPnP devices and services. The input for creating such a Filter is a string composed of the following attributes used as LDAP search criteria:
One listener can listen for events from many services. For example, if you specify
"(&(" + UPnPDevice.TYPE + "=*Printer*)" + "(" + UPnPService.TYPE+ "=*PrinterService*))"
then you receive events from all UPnP services, containing "PrinterService" in their service type, which belong to all UPnP devices having "Printer" in their device type.
Processing Received Events
When the interesting UPnP service fires an event, the notifyUPnPEvent method of the subscribed event listeners is called. The subscriber receives a dictionary whose keys are the names of the interesting state variables (as UPnPStateVariable objects) and whose values are the variables' new values. A variable value is an instance of the class indicated by the getJavaDataType method of the corresponding UPnPStateVariable.
The notifyUPnPEvent is called in an asynchronous manner.