org.fourthline.cling.controlpoint
Class ActionCallback
java.lang.Object
org.fourthline.cling.controlpoint.ActionCallback
- All Implemented Interfaces:
- Runnable
- Direct Known Subclasses:
- ActionCallback.Default
public abstract class ActionCallback
- extends Object
- implements Runnable
Execute actions on any service.
Usage example for asynchronous execution in a background thread:
Service service = device.findService(new UDAServiceId("SwitchPower"));
Action getStatusAction = service.getAction("GetStatus");
ActionInvocation getStatusInvocation = new ActionInvocation(getStatusAction);
ActionCallback getStatusCallback = new ActionCallback(getStatusInvocation) {
public void success(ActionInvocation invocation) {
ActionArgumentValue status = invocation.getOutput("ResultStatus");
assertEquals((Boolean) status.getValue(), Boolean.valueOf(false));
}
public void failure(ActionInvocation invocation, UpnpResponse res) {
System.err.println(
createDefaultFailureMessage(invocation, res)
);
}
};
upnpService.getControlPoint().execute(getStatusCallback)
You can also execute the action synchronously in the same thread using the
ActionCallback.Default
implementation:
myActionInvocation.setInput("foo", bar);
new ActionCallback.Default(myActionInvocation, upnpService.getControlPoint()).run();
myActionInvocation.getOutput("baz");
- Author:
- Christian Bauer
actionInvocation
protected final ActionInvocation actionInvocation
controlPoint
protected ControlPoint controlPoint
ActionCallback
protected ActionCallback(ActionInvocation actionInvocation,
ControlPoint controlPoint)
ActionCallback
protected ActionCallback(ActionInvocation actionInvocation)
getActionInvocation
public ActionInvocation getActionInvocation()
getControlPoint
public ControlPoint getControlPoint()
setControlPoint
public ActionCallback setControlPoint(ControlPoint controlPoint)
run
public void run()
- Specified by:
run
in interface Runnable
createDefaultFailureMessage
protected String createDefaultFailureMessage(ActionInvocation invocation,
UpnpResponse operation)
failure
protected void failure(ActionInvocation invocation,
UpnpResponse operation)
success
public abstract void success(ActionInvocation invocation)
- Called when the action invocation succeeded.
- Parameters:
invocation
- The successful invocation, call its getOutput()
method for results.
failure
public abstract void failure(ActionInvocation invocation,
UpnpResponse operation,
String defaultMsg)
- Called when the action invocation failed.
- Parameters:
invocation
- The failed invocation, call its getFailure()
method for more details.operation
- If the invocation was on a remote service, the response message, otherwise null.defaultMsg
- A user-friendly error message generated from the invocation exception and response.- See Also:
createDefaultFailureMessage(org.fourthline.cling.model.action.ActionInvocation, org.fourthline.cling.model.message.UpnpResponse)
toString
public String toString()
- Overrides:
toString
in class Object
Copyright © 2013 4th Line GmbH, Switzerland. All Rights Reserved.