use of org.talend.sdk.component.runtime.di.AutoChunkProcessor in project component-runtime by Talend.
the class DIBatchSimulationTest method doDi.
private void doDi(final ComponentManager manager, final Collection<Object> sourceData, final Collection<Object> processorData, final Optional<Processor> proc, final Optional<Mapper> mapper) {
final Map<String, Object> globalMap = new HashMap<>();
try {
final Processor processor = proc.orElseThrow(() -> new IllegalStateException("scanning failed"));
JobStateAware.init(processor, globalMap);
final Jsonb jsonbProcessor = Jsonb.class.cast(manager.findPlugin(processor.plugin()).get().get(ComponentManager.AllServices.class).getServices().get(Jsonb.class));
final AutoChunkProcessor processorProcessor = new AutoChunkProcessor(100, processor);
processorProcessor.start();
globalMap.put("processorProcessor", processorProcessor);
final InputsHandler inputsHandlerProcessor = new InputsHandler(jsonbProcessor);
inputsHandlerProcessor.addConnection("FLOW", row1Struct.class);
final OutputsHandler outputHandlerProcessor = new OutputsHandler(jsonbProcessor);
final InputFactory inputsProcessor = inputsHandlerProcessor.asInputFactory();
final OutputFactory outputsProcessor = outputHandlerProcessor.asOutputFactory();
final Mapper tempMapperMapper = mapper.orElseThrow(() -> new IllegalStateException("scanning failed"));
JobStateAware.init(tempMapperMapper, globalMap);
doRun(manager, sourceData, processorData, globalMap, processorProcessor, inputsHandlerProcessor, outputHandlerProcessor, inputsProcessor, outputsProcessor, tempMapperMapper);
} finally {
doClose(globalMap);
}
}
use of org.talend.sdk.component.runtime.di.AutoChunkProcessor in project component-runtime by Talend.
the class DIBatchSimulationTest method doClose.
private void doClose(final Map<String, Object> globalMap) {
final Mapper mapperMapper = Mapper.class.cast(globalMap.remove("mapperMapper"));
final Input inputMapper = Input.class.cast(globalMap.remove("inputMapper"));
try {
if (inputMapper != null) {
inputMapper.stop();
}
} catch (final RuntimeException re) {
fail(re.getMessage());
} finally {
try {
if (mapperMapper != null) {
mapperMapper.stop();
}
} catch (final RuntimeException re) {
fail(re.getMessage());
}
}
final AutoChunkProcessor processorProcessor = AutoChunkProcessor.class.cast(globalMap.remove("processorProcessor"));
try {
if (processorProcessor != null) {
processorProcessor.stop();
}
} catch (final RuntimeException re) {
fail(re.getMessage());
}
}
Aggregations