PooledClientProvider pooledClientProvider = new PooledClientProvider( config, zkDiscoveryService); TransactionServiceClient txClient = new TransactionServiceClient(config,pooledClientProvider); TephraTransactionClient client = new TephraTransactionClient(zkClientService, txClient); client.start();
@Override public boolean canCommit(final Transaction tx, final Collection<byte[]> changeIds) throws TransactionNotInProgressException { try { canCommitOrThrow(tx, changeIds); return true; } catch (TransactionFailureException e) { return false; } }
@Override public boolean commit(final Transaction tx) throws TransactionNotInProgressException { try { commitOrThrow(tx); return true; } catch (TransactionFailureException e) { return false; } }
TransactionServiceClient client = injector.getInstance(TransactionServiceClient.class); LOG.info("Starting tx..."); Transaction tx = client.startShort(); if (verbose) { LOG.info("Started tx details: " + tx.toString()); client.canCommitOrThrow(tx, Collections.<byte[]>emptyList()); LOG.info("canCommit: success"); LOG.info("Committing tx..."); client.commitOrThrow(tx); LOG.info("Committed tx: success"); } catch (TransactionConflictException e) { LOG.info("Aborting tx..."); client.abort(tx); LOG.info("Aborted tx...");
/** see execute(operation, client). */ private <T> T execute(Operation<T> operation) throws Exception { return execute(operation, null); }
/** * Utility to be used for basic verification of transaction system availability and functioning * @param args arguments list, accepts single option "-v" that makes it to print out more details about started tx */ public static void main(String[] args) throws Exception { if (args.length > 1 || (args.length == 1 && !"-v".equals(args[0]))) { System.out.println("USAGE: TransactionServiceClient [-v]"); } boolean verbose = false; if (args.length == 1 && "-v".equals(args[0])) { verbose = true; } doMain(verbose, new ConfigurationFactory().get()); }
@Override public String status() { try { return this.execute( new Operation<String>("status") { @Override public String execute(TransactionServiceThriftClient client) throws Exception { return client.status(); } }); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public Transaction startLong() { try { return execute( new Operation<Transaction>("startLong") { @Override public Transaction execute(TransactionServiceThriftClient client) throws TException { return client.startLong(clientId); } }); } catch (Exception e) { throw Throwables.propagate(e); } }
PooledClientProvider pooledClientProvider = new PooledClientProvider( config, zkDiscoveryService); TransactionServiceClient txClient = new TransactionServiceClient(config,pooledClientProvider); TephraTransactionClient client = new TephraTransactionClient(zkClientService, txClient); client.start();
@Override public void abort(final Transaction tx) { try { this.execute( new Operation<Boolean>("abort") { @Override public Boolean execute(TransactionServiceThriftClient client) throws TException { client.abort(tx); return true; } }); } catch (Exception e) { throw Throwables.propagate(e); } }
PooledClientProvider pooledClientProvider = new PooledClientProvider( config, zkDiscoveryService); TransactionServiceClient txClient = new TransactionServiceClient(config,pooledClientProvider); TephraTransactionClient client = new TephraTransactionClient(zkClientService, txClient); client.start();
@Override public Transaction startShort(final int timeout) { try { return execute( new Operation<Transaction>("startShort") { @Override public Transaction execute(TransactionServiceThriftClient client) throws TException { return client.startShort(clientId, timeout); } }); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public boolean truncateInvalidTx(final Set<Long> invalidTxIds) { try { return this.execute( new Operation<Boolean>("truncateInvalidTx") { @Override public Boolean execute(TransactionServiceThriftClient client) throws TException { return client.truncateInvalidTx(invalidTxIds); } }); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public int getInvalidSize() { try { return this.execute( new Operation<Integer>("getInvalidSize") { @Override public Integer execute(TransactionServiceThriftClient client) throws TException { return client.getInvalidSize(); } }); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void resetState() { try { this.execute( new Operation<Boolean>("resetState") { @Override public Boolean execute(TransactionServiceThriftClient client) throws TException { client.resetState(); return true; } }); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void pruneNow() { try { this.execute( new Operation<Void>("pruneNow") { @Override public Void execute(TransactionServiceThriftClient client) throws TException { client.pruneNow(); return null; } }); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public Transaction checkpoint(final Transaction tx) throws TransactionNotInProgressException { try { return this.execute( new Operation<Transaction>("checkpoint") { @Override Transaction execute(TransactionServiceThriftClient client) throws Exception { return client.checkpoint(tx); } } ); } catch (TransactionNotInProgressException e) { throw e; } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public Transaction startShort() { try { return execute( new Operation<Transaction>("startShort") { @Override public Transaction execute(TransactionServiceThriftClient client) throws TException { return client.startShort(clientId); } }); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public boolean invalidate(final long tx) { try { return this.execute( new Operation<Boolean>("invalidate") { @Override public Boolean execute(TransactionServiceThriftClient client) throws TException { return client.invalidate(tx); } }); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void commitOrThrow(final Transaction tx) throws TransactionFailureException { try { execute( new Operation<Void>("commit") { @Override public Void execute(TransactionServiceThriftClient client) throws Exception { client.commit(tx.getTransactionId(), tx.getWritePointer()); return null; } }); } catch (TransactionNotInProgressException | TransactionConflictException e) { throw e; } catch (Exception e) { throw Throwables.propagate(e); } }