/** * @see TransactionContext#beginTransaction() */ public void beginTransaction() { transactionContext.beginTransaction(); transactionActive = true; }
/** * @see TransactionContext#beginTransaction() */ public void beginTransaction() { transactionContext.beginTransaction(); transactionActive = true; }
/** * @see TransactionContext#beginTransaction() */ public void beginTransaction() { transactionContext.beginTransaction(); transactionActive = true; }
public HazelCastTransaction(TransactionContext context, StoreTxConfig txConfig) { super(txConfig); this.context = context; this.context.beginTransaction(); }
private void begin() { transactionContext = hazelcastInstance.newTransactionContext(); transactionContext.beginTransaction(); transactionalMap = transactionContext.getMap(name); }
private void begin() { transactionContext = hazelcastInstance.newTransactionContext(); transactionContext.beginTransaction(); transactionalMap = transactionContext.getMap(name); }
/** * Constructs the context which may be transacted. The context is a child of * the given HazelcastMQ instance. * * @param transacted true to create a transacted context, false otherwise * @param hazelcastMQInstance the parent MQ instance */ public DefaultLocalTxHazelcastMQContext(boolean transacted, DefaultHazelcastMQInstance hazelcastMQInstance) { super(hazelcastMQInstance); if (transacted) { HazelcastInstance hazelcast = this.config.getHazelcastInstance(); txnContext = hazelcast.newTransactionContext(); txnContext.beginTransaction(); } }
@Override public void commit() { if (isTransacted()) { contextLock.lock(); try { txnContext.commitTransaction(); // It appears that Hazelcast doesn't allow a transaction context // to be reused so we'll recreate the context after commit. txnContext = config.getHazelcastInstance().newTransactionContext(); txnContext.beginTransaction(); } finally { contextLock.unlock(); } } }
@Override public void rollback() { if (isTransacted()) { contextLock.lock(); try { txnContext.rollbackTransaction(); // It appears that Hazelcast doesn't allow a transaction context // to be reused so we'll recreate the context after commit. txnContext = config.getHazelcastInstance().newTransactionContext(); txnContext.beginTransaction(); } finally { contextLock.unlock(); } } }
@Override public <T> T executeTransaction(TransactionOptions options, TransactionalTask<T> task) throws TransactionException { final TransactionContext context = newTransactionContext(options); context.beginTransaction(); try { final T value = task.execute(context); context.commitTransaction(); return value; } catch (Throwable e) { context.rollbackTransaction(); if (e instanceof TransactionException) { throw (TransactionException) e; } if (e.getCause() instanceof TransactionException) { throw (TransactionException) e.getCause(); } if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new TransactionException(e); } }
@Override public <T> T executeTransaction(TransactionOptions options, TransactionalTask<T> task) throws TransactionException { final TransactionContext context = newTransactionContext(options); context.beginTransaction(); try { final T value = task.execute(context); context.commitTransaction(); return value; } catch (Throwable e) { context.rollbackTransaction(); if (e instanceof TransactionException) { throw (TransactionException) e; } if (e.getCause() instanceof TransactionException) { throw (TransactionException) e.getCause(); } if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new TransactionException(e); } }
@Override public void begin() { // start a transaction if (this.transaction != null) { // the transaction context this.transaction = this.hazelcastInstance.newTransactionContext(new TransactionOptions().setTransactionType(TransactionType.ONE_PHASE)); this.transaction.beginTransaction(); // get the map this.transactionCache = this.transaction.getMap(HazelcastCacheProvider.MAP_PREFIX + this.name); } }
@Override public <T> T executeTransaction(TransactionOptions options, TransactionalTask<T> task) throws TransactionException { checkNotNull(task, "TransactionalTask is required!"); TransactionContext context = newTransactionContext(options); context.beginTransaction(); try { T value = task.execute(context); context.commitTransaction(); return value; } catch (Throwable e) { context.rollbackTransaction(); if (e instanceof TransactionException) { throw (TransactionException) e; } if (e.getCause() instanceof TransactionException) { throw (TransactionException) e.getCause(); } if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new TransactionException(e); } }
@Override public <T> T executeTransaction(TransactionOptions options, TransactionalTask<T> task) throws TransactionException { checkNotNull(task, "TransactionalTask is required!"); TransactionContext context = newTransactionContext(options); context.beginTransaction(); try { T value = task.execute(context); context.commitTransaction(); return value; } catch (Throwable e) { context.rollbackTransaction(); if (e instanceof TransactionException) { throw (TransactionException) e; } if (e.getCause() instanceof TransactionException) { throw (TransactionException) e.getCause(); } if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new TransactionException(e); } }
public void begin() throws ResourceException { if (null == txContext) { factory.logHzConnectionEvent(this, HzConnectionEvent.TX_START); txContext = getHazelcastInstance().newTransactionContext(); log(Level.FINEST, "begin"); txContext.beginTransaction(); fireConnectionEvent(ConnectionEvent.LOCAL_TRANSACTION_STARTED); } else { log(Level.INFO, "Ignoring duplicate TX begin event"); } }
public static void main(String[] args) throws Exception { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); TransactionOptions txOptions = new TransactionOptions().setTimeout(10, TimeUnit.SECONDS); TransactionContext txCxt = hz.newTransactionContext(txOptions); txCxt.beginTransaction(); TransactionalMap<String, String> map = txCxt.getMap("map"); try { map.put("1", "1"); map.put("2", "2"); txCxt.commitTransaction(); } catch (RuntimeException t) { txCxt.rollbackTransaction(); throw t; } System.out.println("Finished"); Hazelcast.shutdownAll(); } }
TransactionContext context = targetInstance.newTransactionContext(); try{ context.beginTransaction(); final TransactionalMap<Integer, Long> map = context.getMap(basename); final int key = random.nextInt(keyCount);
@Override protected Object innerCall() throws Exception { TransactionOptions options = new TransactionOptions(); options.setDurability(parameters.durability); options.setTimeout(parameters.timeout, TimeUnit.MILLISECONDS); options.setTransactionType(TransactionOptions.TransactionType.getByValue(parameters.transactionType)); TransactionManagerServiceImpl transactionManager = (TransactionManagerServiceImpl) clientEngine.getTransactionManagerService(); TransactionContext context = transactionManager.newClientTransactionContext(options, endpoint.getUuid()); context.beginTransaction(); endpoint.setTransactionContext(context); return context.getTxnId(); }
@Override protected Object innerCall() throws Exception { TransactionOptions options = new TransactionOptions(); options.setDurability(parameters.durability); options.setTimeout(parameters.timeout, TimeUnit.MILLISECONDS); options.setTransactionType(TransactionOptions.TransactionType.getByValue(parameters.transactionType)); TransactionManagerServiceImpl transactionManager = (TransactionManagerServiceImpl) clientEngine.getTransactionManagerService(); TransactionContext context = transactionManager.newClientTransactionContext(options, endpoint.getUuid()); context.beginTransaction(); endpoint.setTransactionContext(context); return context.getTxnId(); }
@TimeStep public void timestep(ThreadState state) { int key = state.nextRandom(0, range / 2); TransactionOptions transactionOptions = new TransactionOptions() .setTransactionType(transactionType) .setDurability(durability); TransactionContext transactionContext = targetInstance.newTransactionContext(transactionOptions); transactionContext.beginTransaction(); TransactionalMap<Object, Object> txMap = transactionContext.getMap("map"); try { Object val = txMap.getForUpdate(key); if (val != null) { key = state.nextRandom(range / 2, range); } txMap.put(key, (long) key); transactionContext.commitTransaction(); } catch (Exception e) { logger.severe("----------------------tx exception -------------------------", e); if (failOnException) { throw rethrow(e); } transactionContext.rollbackTransaction(); } }