use of com.swiftmq.swiftlet.queue.QueueTransactionClosedException in project swiftmq-ce by iitsoftware.
the class TopicTransaction method rollback.
protected void rollback() throws Exception {
if (subscriberTransactions == null)
return;
List durPersSubs = new ArrayList(subscriberTransactions.length);
for (int i = 0; i < subscriberTransactions.length; i++) {
TopicSubscriberTransaction sub = subscriberTransactions[i];
if (sub != null) {
TopicSubscription subscription = sub.getTopicSubscription();
if (subscription.isRemote() || !subscription.isDurable() || !sub.isPersistentMessageIncluded()) {
try {
sub.rollback();
} catch (QueueTransactionClosedException ignored) {
}
} else
durPersSubs.add(sub);
}
}
int size = durPersSubs.size();
if (size > 0) {
if (size == 1) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(0);
try {
sub.rollback();
} catch (QueueTransactionClosedException ignored) {
}
} else {
for (int i = 0; i < size; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
sub.getTransaction().lockQueue();
}
CompositeStoreTransaction compositeTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
for (int i = 0; i < size; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
try {
sub.getTransaction().setCompositeStoreTransaction(compositeTx);
sub.rollback();
sub.getTransaction().setCompositeStoreTransaction(null);
} catch (QueueTransactionClosedException ignored) {
}
}
compositeTx.commitTransaction();
for (int i = 0; i < size; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
sub.getTransaction().unlockQueue(false);
}
}
}
subscriberTransactions = null;
}
use of com.swiftmq.swiftlet.queue.QueueTransactionClosedException in project swiftmq-ce by iitsoftware.
the class TransactionManager method commitWithGlobalLock.
private void commitWithGlobalLock() throws Exception {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock, transactions.size=" + transactions.size());
CompositeStoreTransaction compTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
compTx.setReferencable(false);
ctx.queueManager.lockMultiQueue();
lock();
try {
for (Iterator iter = transactions.iterator(); iter.hasNext(); ) {
Pair p = (Pair) iter.next();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock, t=" + p.tx + ", closed=" + p.tx.isClosed());
try {
p.tx.setCompositeStoreTransaction(compTx);
p.tx.commit();
p.tx.setCompositeStoreTransaction(null);
} catch (QueueTransactionClosedException e) {
// Happens when temp queues have been deleted meanwhile
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock, t=" + p.tx + ", QueueTransactionClosedException, remove");
iter.remove();
p.tx.unlockQueue(false);
}
}
compTx.commitTransaction();
} finally {
unlock();
ctx.queueManager.unlockMultiQueue();
startTransactions();
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + "/commitWithGlobalLock done");
}
use of com.swiftmq.swiftlet.queue.QueueTransactionClosedException in project swiftmq-ce by iitsoftware.
the class NontransactedSession method visit.
public void visit(AcknowledgeMessageRequest req) {
if (closed)
return;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitAcknowledgeMessageRequest");
AcknowledgeMessageReply reply = null;
if (req.isReplyRequired()) {
reply = (AcknowledgeMessageReply) req.createReply();
reply.setOk(true);
}
if (ctx.ackMode == javax.jms.Session.CLIENT_ACKNOWLEDGE) {
Map ackConsumers = new HashMap();
for (Iterator iter = deliveredList.iterator(); iter.hasNext(); ) {
MessageDeliveredRequest request = (MessageDeliveredRequest) iter.next();
Consumer consumer = (Consumer) consumerList.get(request.getQueueConsumerId());
MessageIndex actIndex = request.getMessageIndex();
QueuePullTransaction t = consumer.getTransaction();
ConsumerAckEntry ackEntry = (ConsumerAckEntry) ackConsumers.get(consumer);
if (ackEntry == null) {
ackEntry = new ConsumerAckEntry(t);
ackConsumers.put(consumer, ackEntry);
}
ackEntry.ackList.add(actIndex);
}
deliveredList.clear();
boolean callbackRegistered = false;
MultiAckJoin join = new MultiAckJoin(reply);
for (Iterator iter = ackConsumers.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
Consumer consumer = (Consumer) entry.getKey();
ConsumerAckEntry ackEntry = (ConsumerAckEntry) entry.getValue();
try {
join.incNumberCallbacks();
ackEntry.transaction.acknowledgeMessages(ackEntry.ackList, new MultiAckCallback(join, consumer, ackEntry.ackList.size()));
callbackRegistered = true;
} catch (QueueTransactionClosedException e) {
}
}
join.setBlocked(false);
if (!callbackRegistered && reply != null)
reply.send();
} else {
MessageIndex ackIndex = req.getMessageIndex();
Consumer consumer = (Consumer) consumerList.get(req.getQueueConsumerId());
ackSingleMessage(reply, ackIndex, consumer);
}
}
use of com.swiftmq.swiftlet.queue.QueueTransactionClosedException in project swiftmq-ce by iitsoftware.
the class MQTTSession method visit.
@Override
public void visit(POSendMessage po) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
try {
BytesMessageImpl jmsMessage = (BytesMessageImpl) po.getJmsMessage();
jmsMessage.reset();
MqttQoS qos = po.getQos();
String topicName = topicNameTranslateReverse(po.getTopicName());
byte[] b = new byte[(int) jmsMessage.getBodyLength()];
jmsMessage.readBytes(b);
ByteBuf byteBuf = new ByteBuf(b);
byteBuf.reset();
int packetId = -1;
if (qos != MqttQoS.AT_MOST_ONCE) {
if (pid == 65535)
pid = 1;
packetId = pid++;
outboundPackets.put(packetId, po);
}
mqttConnection.getOutboundQueue().enqueue(new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, false, qos, false, 0), new MqttPublishVariableHeader(topicName, packetId), byteBuf));
if (qos == MqttQoS.AT_MOST_ONCE) {
po.getTransaction().commit();
po.getSubscription().restart();
} else
addReplay(packetId, new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, true, qos, false, 0), new MqttPublishVariableHeader(topicName, packetId), byteBuf));
incMsgsReceived(1);
} catch (QueueTransactionClosedException qtc) {
} catch (Exception e) {
mqttConnection.initiateClose("send message: exception=" + e);
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
use of com.swiftmq.swiftlet.queue.QueueTransactionClosedException in project swiftmq-ce by iitsoftware.
the class TopicSubscriberTransaction method commit.
protected void commit(AsyncCompletionCallback callback) {
if (!valid) {
callback.setException(new QueueTransactionClosedException("TopicSubscriberTransaction is invalid"));
callback.done(false);
return;
}
transaction.commit(new AsyncCompletionCallback(callback) {
public void done(boolean success) {
topicSubscription.removeTransaction(TopicSubscriberTransaction.this);
valid = false;
fcDelay = transaction.getFlowControlDelay();
if (success)
next.setResult(Long.valueOf(fcDelay));
else
next.setException(getException());
}
});
}
Aggregations