use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.
the class AsyncOperationImpl method checkForUpdates.
/**
* Called by subclasses to update incomplete state. Complete updates are handled inside of
* setResult to ensure that completion results fire exactly once.
*/
protected void checkForUpdates() {
if (listeners != null) {
Set<Pair<AsyncOperationListener, EnumSet<OperationState>>> _listeners;
OperationState opState;
opState = getState();
if (opState == OperationState.INCOMPLETE) {
_listeners = null;
lock.lock();
try {
if (listeners != null) {
_listeners = ImmutableSet.copyOf(listeners);
}
} finally {
lock.unlock();
}
if (_listeners != null) {
notificationWorker.fiterForUpdates(this, _listeners, opState);
}
}
}
}
use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.
the class MasterModeDependencyWatcher method readMasterRingTree.
private Pair<RingTree, Triple<String, Long, Long>> readMasterRingTree(com.ms.silverking.cloud.dht.meta.MetaClient dhtMC, DHTConfiguration dhtConfig) throws KeeperException, IOException {
DHTRingCurTargetZK dhtRingCurTargetZK;
Triple<String, Long, Long> masterRingAndVersionPair;
RingTree ringTree;
dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
masterRingAndVersionPair = dhtRingCurTargetZK.getMasterRingAndVersionPair();
if (masterRingAndVersionPair == null) {
throw new RuntimeException("Can't find master ring");
} else {
ringTree = SingleRingZK.readTree(mc, masterRingAndVersionPair.getV2(), masterRingAndVersionPair.getV3());
return new Pair<>(ringTree, masterRingAndVersionPair);
}
}
use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.
the class LZ4 method compressFile.
private static final Pair<Triple<Double, Double, Double>, Pair<Integer, Integer>> compressFile(File file) throws IOException {
Stopwatch readingSW;
Stopwatch compressionSW;
Stopwatch decompressionSW;
byte[] original;
byte[] compressed;
byte[] uncompressed;
readingSW = new SimpleStopwatch();
System.out.printf("Reading file: %s\n", file);
original = FileUtil.readFileAsBytes(file);
readingSW.stop();
System.out.printf("Reading elapsed: %f\n", readingSW.getElapsedSeconds());
compressionSW = new SimpleStopwatch();
compressed = new LZ4().compress(original, 0, original.length);
compressionSW.stop();
System.out.printf("Compression elapsed: %f\n", compressionSW.getElapsedSeconds());
decompressionSW = new SimpleStopwatch();
uncompressed = new LZ4().decompress(compressed, 0, compressed.length, original.length);
decompressionSW.stop();
System.out.printf("Decompression elapsed: %f\n", decompressionSW.getElapsedSeconds());
return new Pair<>(new Triple<>(readingSW.getElapsedSeconds(), compressionSW.getElapsedSeconds(), decompressionSW.getElapsedSeconds()), new Pair<Integer, Integer>(original.length, compressed.length));
}
use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.
the class Ping method ping.
public Pair<Boolean, String> ping(String dest, int count) throws IOException {
ProcessExecutor pe;
String[] cmd;
boolean ok;
String output;
cmd = new String[4];
cmd[0] = ping;
cmd[1] = "-c";
cmd[2] = Integer.toString(count);
cmd[3] = dest;
pe = new ProcessExecutor(cmd);
try {
pe.execute();
ok = pe.getExitCode() == 0;
output = pe.getOutput();
} catch (ExitCodeException ece) {
ok = false;
output = null;
}
return new Pair<>(ok, output);
}
use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.
the class SKAdmin method waitUntilRunning.
// /////////////////////////////////////////
public Pair<Set<IPAndPort>, Boolean> waitUntilRunning(Set<IPAndPort> activeNodes, int timeoutSeconds) {
DaemonStateZK daemonStateZK;
Map<IPAndPort, DaemonState> daemonState;
daemonStateZK = new DaemonStateZK(dhtMC);
daemonState = daemonStateZK.waitForQuorumState(activeNodes, DaemonState.RUNNING, timeoutSeconds, true);
Log.warningf("daemonState: %s", daemonState);
if (daemonState.isEmpty()) {
return new Pair<>(ImmutableSet.of(), true);
} else {
HashSet<IPAndPort> failedDaemons;
boolean running;
running = true;
failedDaemons = new HashSet<>();
for (IPAndPort activeNode : activeNodes) {
DaemonState ds;
ds = daemonState.get(activeNode);
System.out.printf("Node: %s\tstate: %s\n", activeNode, ds);
if (ds == null) {
failedDaemons.add(activeNode);
running = false;
} else {
if (ds != DaemonState.RUNNING) {
running = false;
}
}
}
return new Pair<>(failedDaemons, running);
}
}
Aggregations