use of com.vaadin.flow.server.communication.rpc.RpcInvocationHandler in project flow by vaadin.
the class ServerRpcHandler method handleInvocations.
/**
* Processes invocations data received from the client.
* <p>
* The invocations data can contain any number of RPC calls.
*
* @param ui
* the UI receiving the invocations data
* @param invocationsData
* JSON containing all information needed to execute all
* requested RPC calls.
*/
private void handleInvocations(UI ui, JsonArray invocationsData) {
List<JsonObject> data = new ArrayList<>(invocationsData.length());
List<Runnable> pendingChangeEvents = new ArrayList<>();
RpcInvocationHandler mapSyncHandler = getInvocationHandlers().get(JsonConstants.RPC_TYPE_MAP_SYNC);
for (int i = 0; i < invocationsData.length(); i++) {
JsonObject invocationJson = invocationsData.getObject(i);
String type = invocationJson.getString(JsonConstants.RPC_TYPE);
assert type != null;
if (JsonConstants.RPC_TYPE_MAP_SYNC.equals(type)) {
// Handle these before any RPC invocations.
mapSyncHandler.handle(ui, invocationJson).ifPresent(pendingChangeEvents::add);
} else {
data.add(invocationJson);
}
}
pendingChangeEvents.forEach(runnable -> runMapSyncTask(ui, runnable));
data.forEach(json -> handleInvocationData(ui, json));
}
use of com.vaadin.flow.server.communication.rpc.RpcInvocationHandler in project flow by vaadin.
the class ServerRpcHandler method handleInvocationData.
private void handleInvocationData(UI ui, JsonObject invocationJson) {
String type = invocationJson.getString(JsonConstants.RPC_TYPE);
RpcInvocationHandler handler = getInvocationHandlers().get(type);
if (handler == null) {
throw new IllegalArgumentException("Unsupported event type: " + type);
}
try {
Optional<Runnable> handle = handler.handle(ui, invocationJson);
assert !handle.isPresent() : "RPC handler " + handler.getClass().getName() + " returned a Runnable even though it shouldn't";
} catch (Throwable throwable) {
ui.getSession().getErrorHandler().error(new ErrorEvent(throwable));
}
}
Aggregations