Package org.jupnp.controlpoint
Klasse SubscriptionCallback
java.lang.Object
org.jupnp.controlpoint.SubscriptionCallback
- Alle implementierten Schnittstellen:
Runnable
Subscribe and receive events from a service through GENA.
Usage example, establishing a subscription with a Service:
SubscriptionCallback callback = new SubscriptionCallback(service, 600) { // Timeout in seconds
public void established(GENASubscription sub) {
System.out.println("Established: " + sub.getSubscriptionId());
}
public void failed(GENASubscription sub, UpnpResponse response, Exception e) {
System.err.println(createDefaultFailureMessage(response, e));
}
public void ended(GENASubscription sub, CancelReason reason, UpnpResponse response) {
// Reason should be null, or it didn't end regularly
}
public void eventReceived(GENASubscription sub) {
System.out.println("Event: " + sub.getCurrentSequence().getValue());
Map<String, StateVariableValue> values = sub.getCurrentValues();
StateVariableValue status = values.get("Status");
System.out.println("Status is: " + status.toString());
}
public void eventsMissed(GENASubscription sub, int numberOfMissedEvents) {
System.out.println("Missed events: " + numberOfMissedEvents);
}
};
upnpService.getControlPoint().execute(callback);
- Autor:
- Christian Bauer
-
Feldübersicht
Felder -
Konstruktorübersicht
KonstruktorenModifiziererKonstruktorBeschreibungprotectedSubscriptionCallback(Service service) protectedSubscriptionCallback(Service service, int requestedDurationSeconds) -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic StringcreateDefaultFailureMessage(UpnpResponse responseStatus, Exception exception) voidend()protected abstract voidended(GENASubscription subscription, CancelReason reason, UpnpResponse responseStatus) Called when a local or remote subscription ended, either on user request or because of a failure.protected abstract voidestablished(GENASubscription subscription) Called when a local or remote subscription was successfully established.protected abstract voideventReceived(GENASubscription subscription) Called when an event for an established subscription has been received.protected abstract voideventsMissed(GENASubscription subscription, int numberOfMissedEvents) Called when a received event was out of sequence, indicating that events have been missed.protected voidfailed(GENASubscription subscription, UpnpResponse responseStatus, Exception exception) protected abstract voidfailed(GENASubscription subscription, UpnpResponse responseStatus, Exception exception, String defaultMsg) Called when establishing a local or remote subscription failed.protected voidinvalidMessage(RemoteGENASubscription remoteGENASubscription, UnsupportedDataException e) Called when a received event message could not be parsed successfully.voidrun()voidsetControlPoint(ControlPoint controlPoint) voidsetSubscription(GENASubscription subscription) toString()
-
Felddetails
-
logger
protected org.slf4j.Logger logger -
service
-
requestedDurationSeconds
-
-
Konstruktordetails
-
SubscriptionCallback
-
SubscriptionCallback
-
-
Methodendetails
-
getService
-
getControlPoint
-
setControlPoint
-
getSubscription
-
setSubscription
-
run
public void run() -
end
public void end() -
failed
protected void failed(GENASubscription subscription, UpnpResponse responseStatus, Exception exception) -
failed
protected abstract void failed(GENASubscription subscription, UpnpResponse responseStatus, Exception exception, String defaultMsg) Called when establishing a local or remote subscription failed. To get a nice error message that transparently detects local or remote errors use createDefaultFailureMessage().- Parameter:
subscription- The failed subscription object, not very useful at this point.responseStatus- For a remote subscription, if a response was received at all, this is it, otherwise null.exception- For a local subscription and failed creation of a remote subscription protocol (before sending the subscribe request), any exception that caused the failure, otherwise null.defaultMsg- A user-friendly error message.- Siehe auch:
-
established
Called when a local or remote subscription was successfully established.- Parameter:
subscription- The successful subscription.
-
ended
protected abstract void ended(GENASubscription subscription, CancelReason reason, UpnpResponse responseStatus) Called when a local or remote subscription ended, either on user request or because of a failure.- Parameter:
subscription- The ended subscription instance.reason- If the subscription ended regularly (through end()), this is null.responseStatus- For a remote subscription, if the cause implies a remopte response and it was received, this is it (e.g. renewal failure response).
-
eventReceived
Called when an event for an established subscription has been received.Use the
GENASubscription.getCurrentValues()method to obtain the evented state variable values.- Parameter:
subscription- The established subscription with fresh state variable values.
-
eventsMissed
Called when a received event was out of sequence, indicating that events have been missed.It's up to you if you want to react to missed events or if you (can) silently ignore them.
- Parameter:
subscription- The established subscription.numberOfMissedEvents- The number of missed events.
-
createDefaultFailureMessage
- Parameter:
responseStatus- The (HTTP) response ornullif there was no response.exception- The exception ornullif there was no exception.- Gibt zurück:
- A human-friendly error message.
-
invalidMessage
protected void invalidMessage(RemoteGENASubscription remoteGENASubscription, UnsupportedDataException e) Called when a received event message could not be parsed successfully.This typically indicates a broken device which is not UPnP compliant. You can react to this failure in any way you like, for example, you could terminate the subscription or simply create an error report/log.
The default implementation will log the exception at
INFOlevel, and the invalid XML atTRACElevel.- Parameter:
remoteGENASubscription- The established subscription.e- CallUnsupportedDataException.getData()to access the invalid XML.
-
toString
-