use of com.evolveum.midpoint.ninja.action.worker.ImportRepositoryConsumerWorker in project midpoint by Evolveum.
the class ImportRepositoryAction method execute.
@Override
public void execute() throws Exception {
OperationResult result = new OperationResult(OPERATION_IMPORT);
OperationStatus progress = new OperationStatus(context, result);
BlockingQueue<ObjectType> queue = new LinkedBlockingQueue<>(QUEUE_CAPACITY_PER_THREAD * options.getMultiThread());
// "+ 2" will be used for producer and progress reporter
ExecutorService executor = Executors.newFixedThreadPool(options.getMultiThread() + 2);
ImportProducerWorker<ObjectType> producer;
if (options.getOid() != null) {
InOidFilter filter = context.getPrismContext().queryFactory().createInOid(options.getOid());
producer = importByFilter(filter, true, queue, progress);
} else {
ObjectFilter filter = NinjaUtils.createObjectFilter(options.getFilter(), context, ObjectType.class);
producer = importByFilter(filter, false, queue, progress);
}
executor.execute(producer);
Thread.sleep(CONSUMERS_WAIT_FOR_START);
executor.execute(new ProgressReporterWorker<>(context, options, queue, progress));
List<ImportRepositoryConsumerWorker> consumers = createConsumers(queue, progress);
consumers.forEach(c -> executor.execute(c));
executor.shutdown();
boolean awaitResult = executor.awaitTermination(NinjaUtils.WAIT_FOR_EXECUTOR_FINISH, TimeUnit.DAYS);
if (!awaitResult) {
log.error("Executor did not finish before timeout");
}
handleResultOnFinish(progress, "Import finished");
}
Aggregations