com.linkedin.parseq.batching.BatchingSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of parseq-batching Show documentation
Show all versions of parseq-batching Show documentation
Provides convenient API for creating automatically batched tasks
package com.linkedin.parseq.batching;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import com.linkedin.parseq.EngineBuilder;
import com.linkedin.parseq.internal.PlanContext;
import com.linkedin.parseq.internal.PlanDeactivationListener;
/**
* This class allows registering instances of {@link BatchingStrategy}.
*
* Please note that BatchingSupport must be registered with an {@link EngineBuilder} e.g.
*
* BatchingSupport batchingSupport = new BatchingSupport();
* engineBuilder.setPlanDeactivationListener(batchingSupport);
* (...)
* batchingSupport.registerStrategy(batchingStrategy);
*
*
* @author Jaroslaw Odzga ([email protected])
*/
public class BatchingSupport implements PlanDeactivationListener {
private final List> _strategies =
new CopyOnWriteArrayList<>();
/**
* Register an instance of {@link BatchingStrategy}.
* @param strategy strategy to be registered
*/
public void registerStrategy(BatchingStrategy, ?, ?> strategy) {
_strategies.add(strategy);
}
@Override
public void onPlanDeactivated(final PlanContext planContext) {
_strategies.forEach(strategy -> strategy.handleBatch(planContext));
}
}