All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalar.db.sql.springdata.twopc.RemotePrepareCommitOperationsProcessor Maven / Gradle / Ivy

package com.scalar.db.sql.springdata.twopc;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collection;
import java.util.function.Consumer;
import javax.annotation.Nonnull;

interface RemotePrepareCommitOperationsProcessor {

  void exec(Consumer task);

  @Nonnull
  static  RemotePrepareCommitOperationsProcessor create(
      boolean parallel, Collection targets) {
    return parallel ? new ParallelProcessor<>(targets) : new SequentialProcessor<>(targets);
  }

  // This is a simple parallel processing implementation. Maybe it should support ExecutorService
  // based processing in the future.
  @SuppressFBWarnings("EI_EXPOSE_REP2")
  class ParallelProcessor implements RemotePrepareCommitOperationsProcessor {

    private final Collection targets;

    public ParallelProcessor(Collection targets) {
      this.targets = targets;
    }

    @Override
    public void exec(Consumer task) {
      targets.parallelStream().forEach(task);
    }
  }

  @SuppressFBWarnings("EI_EXPOSE_REP2")
  class SequentialProcessor implements RemotePrepareCommitOperationsProcessor {

    private final Collection targets;

    public SequentialProcessor(Collection targets) {
      this.targets = targets;
    }

    @Override
    public void exec(Consumer task) {
      targets.forEach(task);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy