public abstract class ActionCallback extends Object implements Runnable
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");
Modifier and Type | Class and Description |
---|---|
static class |
ActionCallback.Default
Empty implementation of callback methods, simplifies synchronous
execution of an
ActionInvocation . |
Modifier and Type | Field and Description |
---|---|
protected ActionInvocation |
actionInvocation |
protected ControlPoint |
controlPoint |
Modifier | Constructor and Description |
---|---|
protected |
ActionCallback(ActionInvocation actionInvocation) |
protected |
ActionCallback(ActionInvocation actionInvocation,
ControlPoint controlPoint) |
Modifier and Type | Method and Description |
---|---|
protected String |
createDefaultFailureMessage(ActionInvocation invocation,
UpnpResponse operation) |
protected void |
failure(ActionInvocation invocation,
UpnpResponse operation) |
abstract void |
failure(ActionInvocation invocation,
UpnpResponse operation,
String defaultMsg)
Called when the action invocation failed.
|
ActionInvocation |
getActionInvocation() |
ControlPoint |
getControlPoint() |
void |
run() |
ActionCallback |
setControlPoint(ControlPoint controlPoint) |
abstract void |
success(ActionInvocation invocation)
Called when the action invocation succeeded.
|
String |
toString() |
protected final ActionInvocation actionInvocation
protected ControlPoint controlPoint
protected ActionCallback(ActionInvocation actionInvocation, ControlPoint controlPoint)
protected ActionCallback(ActionInvocation actionInvocation)
public ActionInvocation getActionInvocation()
public ControlPoint getControlPoint()
public ActionCallback setControlPoint(ControlPoint controlPoint)
protected String createDefaultFailureMessage(ActionInvocation invocation, UpnpResponse operation)
protected void failure(ActionInvocation invocation, UpnpResponse operation)
public abstract void success(ActionInvocation invocation)
invocation
- The successful invocation, call its getOutput()
method for results.public abstract void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg)
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.createDefaultFailureMessage(org.fourthline.cling.model.action.ActionInvocation, org.fourthline.cling.model.message.UpnpResponse)
Copyright © 2016 4th Line GmbH, Switzerland. All rights reserved.