/** * Add configuration to the supplied {@link Config} to support the use of a {@link HazelcastCommandExecutor}. * @param config The {@link Config} to configure. * @return The updated {@link Config}. */ public Config addCommandExecutorConfiguration(Config config) { SerializerConfig serializerConfig = new SerializerConfig() .setImplementation(RemoteCommandSerialiser.using( objectMapper, CommandTypeMatcher.matchingAgainst(typeInfoMap))) .setTypeClass(RemoteCommand.class); ManagedContext managedContext = CommandProcessingManagedContext .processingCommandsWith(dispatchingCommandProcessor); config.getSerializationConfig().addSerializerConfig(serializerConfig); config.setManagedContext(config.getManagedContext() == null ? managedContext : CompositeManagedContext.of(managedContext, config.getManagedContext())); config.addExecutorConfig(new ExecutorConfig(executorName, threadsPerNode)); return config; }
@Override public Object initialize(Object o) { Object result = o; for (ManagedContext context : managedContexts) { result = context.initialize(result); } return result; }
@Override public final void beforeRun() throws Exception { callable = getCallable(); ManagedContext managedContext = getManagedContext(); if (callable instanceof RunnableAdapter) { RunnableAdapter adapter = (RunnableAdapter) callable; Runnable runnable = (Runnable) managedContext.initialize(adapter.getRunnable()); adapter.setRunnable(runnable); } else { callable = (Callable) managedContext.initialize(callable); } }
public Object readObject(final Data data) { if ((data == null) || (data.buffer == null) || (data.buffer.length == 0)) { return null; } byte[] byteArray = data.buffer; Object obj = toObject(byteArray); final ManagedContext managedContext = ThreadContext.get().getCurrentManagedContext(); if (managedContext != null) { obj = managedContext.initialize(obj); } return obj; }
private CompositeManagedContext(List<ManagedContext> managedContexts) { this.managedContexts = managedContexts; }
@Override public ManagedContext getManagedContext() { return o -> o; // initialize() will do nothing }
private ManagedContext getManagedContext() { HazelcastInstanceImpl hazelcastInstance = (HazelcastInstanceImpl) getNodeEngine().getHazelcastInstance(); SerializationServiceImpl serializationService = (SerializationServiceImpl) hazelcastInstance.getSerializationService(); return serializationService.getManagedContext(); }
public ManagedContext getManagedContext() { return managedContext; }
public Config setManagedContext(final ManagedContext managedContext) { this.managedContext = managedContext; return this; }
public HazelcastManagedContext(final FactoryImpl factory, final ManagedContext externalContext) { this.factory = factory; this.externalContext = externalContext; hasExternalContext = this.externalContext != null; }
public ManagedContext getCurrentManagedContext() { return currentFactory != null ? currentFactory.managedContext : null; }
/** * Create a {@link ManagedContext} that passes the supplied {@link CommandProcessor} to any deserialised objects * that implement {@link CommandProcessorAware}. * @param commandProcessor The {@link CommandProcessor} to use to process {@link Command}s. * @return The constructed {@link ManagedContext}. */ public static ManagedContext processingCommandsWith(CommandProcessor commandProcessor) { return new CommandProcessingManagedContext(commandProcessor); }
/** * Construct a new {@link ManagedContext} that composes together all of the supplied {@link ManagedContext}s. * @param managedContexts The {@link ManagedContext}s to compose. * @return The compose {@link ManagedContext}. */ public static ManagedContext of(ManagedContext...managedContexts) { return of(Arrays.asList(managedContexts)); }
/** * Construct a new {@link ManagedContext} that composes together all of the supplied {@link ManagedContext}s. * @param managedContexts The {@link ManagedContext}s to compose. * @return The compose {@link ManagedContext}. */ public static ManagedContext of(List<ManagedContext> managedContexts) { return new CompositeManagedContext(managedContexts); }