BatcherFactory { public ThresholdBatcher<Batch<RequestT, ResponseT>> getPushingBatcher(PartitionKey partitionKey) { ThresholdBatcher<Batch<RequestT, ResponseT>> batcher = batchers.get(partitionKey); if (batcher == null) { synchronized (lock) { batcher = batchers.get(partitionKey); if (batcher == null) { batcher = createBatcher(partitionKey); batchers.put(partitionKey, batcher); } } } return batcher; } BatcherFactory(
      BatchingDescriptor<RequestT, ResponseT> batchingDescriptor,
      BatchingSettings batchingSettings,
      ScheduledExecutorService executor,
      FlowController flowController); ThresholdBatcher<Batch<RequestT, ResponseT>> getPushingBatcher(PartitionKey partitionKey); @InternalApi BatchingSettings getBatchingSettings();  }
@Test public void testGetPushingBatcher() { BatchingSettings batchingSettings = BatchingSettings.newBuilder() .setDelayThreshold(Duration.ofSeconds(1)) .setElementCountThreshold(2L) .setRequestByteThreshold(1000L) .build(); FlowControlSettings flowControlSettings = FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build(); FlowController flowController = new FlowController(flowControlSettings); BatcherFactory<LabeledIntList, List<Integer>> batcherFactory = new BatcherFactory<>( new SquarerBatchingDescriptor(), batchingSettings, batchingExecutor, flowController); Truth.assertThat(batcherFactory.getBatchingSettings()).isSameInstanceAs(batchingSettings); ThresholdBatcher<Batch<LabeledIntList, List<Integer>>> batcherFoo = batcherFactory.getPushingBatcher(new PartitionKey("foo")); ThresholdBatcher<Batch<LabeledIntList, List<Integer>>> batcherFoo2 = batcherFactory.getPushingBatcher(new PartitionKey("foo")); ThresholdBatcher<Batch<LabeledIntList, List<Integer>>> batcherBar = batcherFactory.getPushingBatcher(new PartitionKey("bar")); Truth.assertThat(batcherFoo).isSameInstanceAs(batcherFoo2); Truth.assertThat(batcherFoo).isNotSameInstanceAs(batcherBar); }