
org.jsimpledb.cli.cmd.AbstractRaftCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsimpledb-cli Show documentation
Show all versions of jsimpledb-cli Show documentation
JSimpleDB classes supporting command line interfaces.
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package org.jsimpledb.cli.cmd;
import org.jsimpledb.cli.CliSession;
import org.jsimpledb.kv.KVDatabase;
import org.jsimpledb.kv.raft.RaftKVDatabase;
import org.jsimpledb.kv.raft.fallback.FallbackKVDatabase;
public abstract class AbstractRaftCommand extends AbstractCommand {
protected AbstractRaftCommand(String spec) {
super(spec);
}
protected abstract class RaftAction implements CliSession.Action {
@Override
public final void run(CliSession session) throws Exception {
final KVDatabase db = session.getKVDatabase();
final RaftKVDatabase raftKV;
if (db instanceof RaftKVDatabase)
raftKV = (RaftKVDatabase)db;
else if (db instanceof FallbackKVDatabase)
raftKV = ((FallbackKVDatabase)db).getFallbackTarget().getRaftKVDatabase();
else
throw new Exception("key/value store is not Raft or Raft fallback");
this.run(session, raftKV);
}
protected abstract void run(CliSession session, RaftKVDatabase db) throws Exception;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy