Search in sources :

Example 1 with Contextualizer

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);
        }
    };
}
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)

Example 2 with Contextualizer

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);
    });
}
Also used : ByteBufferMarshalledValueFactory(org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValueFactory) Contextualizer(org.jboss.as.clustering.context.Contextualizer) ByteBufferMarshaller(org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller)

Aggregations

Contextualizer (org.jboss.as.clustering.context.Contextualizer)2 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 Command (org.wildfly.clustering.dispatcher.Command)1 ByteBufferMarshalledValueFactory (org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValueFactory)1 ByteBufferMarshaller (org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller)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