/** * Refreshes the transaction context by obtaining a new one from the * {@link HazelcastInstance}. Refreshing the context is required because * Hazelcast only supports a single transaction per TransactionContext * instance so after a commit or rollback a new context must be fetched. */ private void refreshTransactionContext() { HazelcastInstance hazelcast = DefaultXaHazelcastMQContext.this.config.getHazelcastInstance(); txnContext = hazelcast.newTransactionContext(); }
@Override public String createTemporaryQueue() { IdGenerator idGenerator = config.getHazelcastInstance().getIdGenerator( "hzmqcontext-temporary-destination"); long tempDestId = idGenerator.newId(); String destination = Headers.DESTINATION_TEMPORARY_QUEUE_PREFIX + tempDestId; temporaryQueues.add(destination); return destination; }
@Override public String createTemporaryTopic() { IdGenerator idGenerator = config.getHazelcastInstance().getIdGenerator( "hzmqcontext-temporary-destination"); long tempDestId = idGenerator.newId(); String destination = Headers.DESTINATION_TEMPORARY_TOPIC_PREFIX + tempDestId; temporaryTopics.add(destination); return destination; }
/** * 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(); } }
return config.getHazelcastInstance().getQueue(queueName);
@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(); } } }
ITopic<Object> topic = config.getHazelcastInstance().getTopic(topicName); if (txnContext != null) {
@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(); } } }
/** * Constructs the producer. * * @param destination the destination to use for send operations that don't * specify a destination * @param hazelcastMQContext the context that this producer belongs to */ public DefaultHazelcastMQProducer(String destination, DefaultHazelcastMQContext hazelcastMQContext) { this.destination = destination; this.hazelcastMQContext = hazelcastMQContext; this.config = hazelcastMQContext.getHazelcastMQInstance().getConfig(); this.idGenerator = config.getHazelcastInstance().getIdGenerator( "hazelcastmqproducer"); }
queue = config.getHazelcastInstance().getQueue(queue.getName()); queueListener = new HzQueueListener(queue);