use of org.jboss.as.clustering.context.Contextualizer 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);
}
};
}
use of org.jboss.as.clustering.context.Contextualizer in project wildfly by wildfly.
the class ChannelCommandDispatcherFactory method createCommandDispatcher.
@Override
public <C> CommandDispatcher<C> createCommandDispatcher(Object id, C commandContext, ClassLoader loader) {
ByteBufferMarshaller dispatcherMarshaller = this.marshallerFactory.apply(loader);
MarshalledValueFactory<ByteBufferMarshaller> factory = new ByteBufferMarshalledValueFactory(dispatcherMarshaller);
Contextualizer contextualizer = this.contextualizerFactory.apply(loader);
CommandDispatcherContext<C, ByteBufferMarshaller> context = new CommandDispatcherContext<C, ByteBufferMarshaller>() {
@Override
public C getCommandContext() {
return commandContext;
}
@Override
public Contextualizer getContextualizer() {
return contextualizer;
}
@Override
public MarshalledValueFactory<ByteBufferMarshaller> getMarshalledValueFactory() {
return factory;
}
};
if (this.contexts.putIfAbsent(id, context) != null) {
throw ClusteringServerLogger.ROOT_LOGGER.commandDispatcherAlreadyExists(id);
}
CommandMarshaller<C> marshaller = new CommandDispatcherMarshaller<>(this.marshaller, id, factory);
CommandDispatcher<C> localDispatcher = new LocalCommandDispatcher<>(this.getLocalMember(), commandContext);
return new ChannelCommandDispatcher<>(this.dispatcher, marshaller, dispatcherMarshaller, this, this.timeout, localDispatcher, () -> {
localDispatcher.close();
this.contexts.remove(id);
});
}
Aggregations