Replica(InstanceSpec spec, Map<Integer, ZooKeeperAddress> servers,
Function<Command<?>, CompletableFuture<?>> delegate, boolean start) throws Exception {
this.delegate = delegate;
dataDir = spec.getDataDirectory();
final int id = spec.getServerId();
final ZooKeeperReplicationConfig zkCfg = new ZooKeeperReplicationConfig(id, servers);
rm = new ZooKeeperCommandExecutor(zkCfg, dataDir, new AbstractCommandExecutor(null, null) {
@Override
public int replicaId() {
return id;
}
@Override
protected void doStart(@Nullable Runnable onTakeLeadership,
@Nullable Runnable onReleaseLeadership) {}
@Override
protected void doStop(@Nullable Runnable onReleaseLeadership) {}
@Override
@SuppressWarnings("unchecked")
protected <T> CompletableFuture<T> doExecute(Command<T> command) {
return (CompletableFuture<T>) delegate.apply(command);
}
}, null, null);
startFuture = start ? rm.start() : null;
}