new DiscoveryModules().getDistributedModules(),
new TransactionModules().getDistributedModules(),
new TransactionClientModule()
);
ZKClientService zkClient = injector.getInstance(ZKClientService.class);
zkClient.startAndWait();
try {
TransactionServiceClient client = injector.getInstance(TransactionServiceClient.class);
LOG.info("Starting tx...");
Transaction tx = client.startShort();
if (verbose) {
LOG.info("Started tx details: " + tx.toString());
} else {
LOG.info("Started tx: " + tx.getWritePointer() +
", readPointer: " + tx.getReadPointer() +
", invalids: " + tx.getInvalids().length +
", inProgress: " + tx.getInProgress().length);
}
LOG.info("Checking if canCommit tx...");
boolean canCommit = client.canCommit(tx, Collections.<byte[]>emptyList());
LOG.info("canCommit: " + canCommit);
if (canCommit) {
LOG.info("Committing tx...");
boolean committed = client.commit(tx);
LOG.info("Committed tx: " + committed);
if (!committed) {
LOG.info("Aborting tx...");
client.abort(tx);
LOG.info("Aborted tx...");
}
} else {
LOG.info("Aborting tx...");
client.abort(tx);
LOG.info("Aborted tx...");
}
} finally {
zkClient.stopAndWait();
}
}