use of org.wildfly.clustering.service.concurrent.ServiceExecutor in project wildfly by wildfly.
the class ChannelCommandDispatcherFactory method read.
private ExceptionSupplier<Object, Exception> read(Message message) throws IOException {
ByteBuffer buffer = ByteBuffer.wrap(message.getRawBuffer(), message.getOffset(), message.getLength());
@SuppressWarnings("unchecked") Map.Entry<Object, MarshalledValue<Command<Object, Object>, Object>> entry = (Map.Entry<Object, MarshalledValue<Command<Object, Object>, Object>>) this.marshaller.read(buffer);
Object clientId = entry.getKey();
CommandDispatcherContext<?, ?> context = this.contexts.get(clientId);
if (context == null)
return NO_SUCH_SERVICE_SUPPLIER;
Object commandContext = context.getCommandContext();
Contextualizer contextualizer = context.getContextualizer();
MarshalledValue<Command<Object, Object>, Object> value = entry.getValue();
Command<Object, Object> command = value.get(context.getMarshalledValueFactory().getMarshallingContext());
ExceptionSupplier<Object, Exception> commandExecutionTask = new ExceptionSupplier<Object, Exception>() {
@Override
public Object get() throws Exception {
return context.getMarshalledValueFactory().createMarshalledValue(command.execute(commandContext));
}
};
ServiceExecutor executor = this.executor;
return new ExceptionSupplier<Object, Exception>() {
@Override
public Object get() throws Exception {
return executor.execute(contextualizer.contextualize(commandExecutionTask)).orElse(NO_SUCH_SERVICE);
}
};
}
Aggregations