subprojects/parseq-batching/src/main/java/com/linkedin/parseq/batching/BatchingStrategy.java
public Task<T> batchable(final String desc, final K key) {
    Task<T> batchableTask = Task.async(desc, ctx -> {
      final BatchPromise<T> result = new BatchPromise<>();
      final Long planId = ctx.getPlanId();
      final GroupBatchBuilder builder = _batches.computeIfAbsent(planId, k -> new GroupBatchBuilder());
      final G group = classify(key);
      Batch<K, T> fullBatch = builder.add(group, key, ctx.getShallowTraceBuilder(), result);
      if (fullBatch != null) {
        try {
          ctx.run(taskForBatch(group, fullBatch, true));
        } catch (Throwable t) {
          //we don't care if some of promises have already been completed
          //all we care is that all remaining promises have been failed
          fullBatch.failAll(t);
        }
      }
      return result;
    });
    batchableTask.getShallowTraceBuilder().setTaskType("batched");
    return batchableTask;
  }
public Task<T> batchable(final String desc, final K key) {
    Task<T> batchableTask = Task.async(desc, ctx -> {
      final BatchPromise<T> result = new BatchPromise<>();
      final Long planId = ctx.getPlanId();
      final GroupBatchBuilder builder = _batches.computeIfAbsent(planId, k -> new GroupBatchBuilder());
      final G group = classify(key);
      Batch<K, T> fullBatch = builder.add(group, key, ctx.getShallowTraceBuilder(), result);
      if (fullBatch != null) {
        try {
          ctx.run(taskForBatch(group, fullBatch, true));
        } catch (Throwable t) {
          //we don't care if some of promises have already been completed
          //all we care is that all remaining promises have been failed
          fullBatch.failAll(t);
        }
      }
      return result;
    });
    batchableTask.getShallowTraceBuilder().setTaskType("batched");
    return batchableTask;
  }
public Task < T > batchable ( final String desc , final K key ) { Task < T > batchableTask = Task . async ( desc , ctx -> { final BatchPromise < T > result = new BatchPromise <> ( ) ; final Long planId = ctx . getPlanId ( ) ; final GroupBatchBuilder builder = _batches . computeIfAbsent ( planId , k -> new GroupBatchBuilder ( ) ) ; final G group = classify ( key ) ; Batch < K , T > fullBatch = builder . add ( group , key , ctx . getShallowTraceBuilder ( ) , result ) ; if ( fullBatch != null ) { try { ctx . run ( taskForBatch ( group , fullBatch , true ) ) ; } catch ( Throwable t ) { //we don't care if some of promises have already been completed //all we care is that all remaining promises have been failed fullBatch . failAll ( t ) ; } } return result ; } ) ; batchableTask . getShallowTraceBuilder ( ) . setTaskType ( "batched" ) ; return batchableTask ; }
This method returns Task that returns value for a single key allowing this strategy to batch operations.
@param desc description of the task
@param key key
@return Task that returns value for a single key allowing this strategy to batch operations
This method returns Task that returns value for a single key allowing this strategy to batch operations .