public interface FunctionResolver
Function.
Client client = ClientFactory.getDefault().newClient();
RequestBuilder request = client.newRequestBuilder()
.method(Request.METHOD.GET)
.uri(targetUrl + "/suspend")
.decoder(new Decoder<String, POJO>() {
@Override
public POJO decode(String s) {
return new POJO(s);
}
})
.transport(Request.TRANSPORT.WEBSOCKET);
Socket socket = client.create();
socket.on(Event.MESSAGE, new Function<POJO>() {
@Override
public void on(POJO t) {
response.set(t);
}
})
or when a Decoder share the same type as the
defined Function. For example:
Client client = ClientFactory.getDefault().newClient();
RequestBuilder request = client.newRequestBuilder()
.method(Request.METHOD.GET)
.uri(targetUrl + "/suspend")
.decoder(new Decoder<String, POJO>() {
@Override
public POJO decode(String s) {
return new POJO(s);
}
})
.transport(Request.TRANSPORT.WEBSOCKET);
Socket socket = client.create();
socket.on(new Function<POJO>() {
@Override
public void on(POJO t) {
response.set(t);
}
})
An application can define its own Decoder to Function Mapper be writing the appropriate FunctionResolver.
By default, the DEFAULT is used.| Modifier and Type | Field and Description |
|---|---|
static FunctionResolver |
DEFAULT |
| Modifier and Type | Method and Description |
|---|---|
boolean |
resolve(String message,
Object functionName,
FunctionWrapper fn)
Resolve the current message
|
static final FunctionResolver DEFAULT
boolean resolve(String message, Object functionName, FunctionWrapper fn)
message - the original response's body receivedfunctionName - the default function name taken from Event or from a custom FunctionResolverfn - The current FunctionWrapperFunction can be invoked.Copyright © 2016. All Rights Reserved.