Search in sources :

Example 1 with MarshalledValue

use of org.wildfly.clustering.marshalling.spi.MarshalledValue 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);
        }
    };
}
Also used : ExceptionSupplier(org.wildfly.common.function.ExceptionSupplier) Contextualizer(org.jboss.as.clustering.context.Contextualizer) MarshalledValue(org.wildfly.clustering.marshalling.spi.MarshalledValue) ByteBuffer(java.nio.ByteBuffer) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) Command(org.wildfly.clustering.dispatcher.Command) StampedLockServiceExecutor(org.wildfly.clustering.service.concurrent.StampedLockServiceExecutor) ServiceExecutor(org.wildfly.clustering.service.concurrent.ServiceExecutor) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Contextualizer (org.jboss.as.clustering.context.Contextualizer)1 Command (org.wildfly.clustering.dispatcher.Command)1 MarshalledValue (org.wildfly.clustering.marshalling.spi.MarshalledValue)1 ServiceExecutor (org.wildfly.clustering.service.concurrent.ServiceExecutor)1 StampedLockServiceExecutor (org.wildfly.clustering.service.concurrent.StampedLockServiceExecutor)1 ExceptionSupplier (org.wildfly.common.function.ExceptionSupplier)1