use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.
the class NontransactedQueueSession method visitProduceMessageRequest.
public void visitProduceMessageRequest(ProduceMessageRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitProduceMessageRequest");
ctx.incMsgsSent(1);
ProduceMessageReply reply = null;
if (req.isReplyRequired())
reply = (ProduceMessageReply) req.createReply();
MessageImpl msg = req.getMessage();
int producerId = req.getQueueProducerId();
Producer producer = null;
try {
if (producerId == -1) {
String queueName = ((QueueImpl) msg.getJMSDestination()).getQueueName();
if (!ctx.queueManager.isQueueRunning(queueName))
throw new InvalidDestinationException("Invalid destination: " + queueName);
producer = new QueueProducer(ctx, queueName);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = (QueuePushTransaction) producer.createTransaction();
transaction.putMessage(msg);
transaction.commit();
if (req.isReplyRequired()) {
reply.setDelay(transaction.getFlowControlDelay());
reply.setOk(true);
}
if (producerId == -1)
producer.close();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/produce messages failed: " + e.getMessage());
if (req.isReplyRequired()) {
reply.setOk(false);
reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
}
}
if (req.isReplyRequired())
reply.send();
}
use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.
the class XALiveContextImpl method commit.
public synchronized long commit(boolean onePhase) throws XAContextException {
long fcDelay = 0;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/commit onePhase=" + onePhase + " ...");
if (wasTimeout)
throw new XAContextException(XAException.XA_RBTIMEOUT, "transaction timeout occured");
if (closed)
throw new XAContextException(XAException.XAER_PROTO, "XA transaction is in closed state");
if (rollbackOnly)
throw new XAContextException(XAException.XA_RBROLLBACK, "XA transaction is marked as rollback-only");
for (int i = 0; i < recoveryTransactions.size(); i++) {
Object[] wrapper = (Object[]) recoveryTransactions.get(i);
try {
((AbstractQueue) wrapper[0]).commit(wrapper[1], xid);
ctx.logSwiftlet.logInformation(ctx.xaSwiftlet.getName(), toString() + "commit xid=" + signature);
} catch (Exception e) {
if (!ctx.queueManager.isTemporaryQueue(((AbstractQueue) wrapper[0]).getQueueName()))
ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "commit (two phase) xid=" + signature + ", failed for queue: " + ((AbstractQueue) wrapper[0]).getQueueName());
}
}
if (onePhase) {
if (prepared)
throw new XAContextException(XAException.XAER_PROTO, "can't use one phase commit, XA transaction is in prepared state");
for (int i = 0; i < transactions.size(); i++) {
QueueTransaction t = (QueueTransaction) transactions.get(i);
try {
t.commit();
if (t instanceof QueuePushTransaction)
fcDelay = Math.max(fcDelay, ((QueuePushTransaction) t).getFlowControlDelay());
} catch (Exception e) {
if (!ctx.queueManager.isTemporaryQueue(t.getQueueName()))
ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "commit (one phase) xid=" + signature + ", failed for queue: " + t.getQueueName());
}
}
} else {
if (!prepared)
throw new XAContextException(XAException.XAER_PROTO, "can't use two phase commit, XA transaction is not in prepared state");
for (int i = 0; i < transactions.size(); i++) {
QueueTransaction t = (QueueTransaction) transactions.get(i);
try {
t.commit(xid);
if (t instanceof QueuePushTransaction)
fcDelay = Math.max(fcDelay, ((QueuePushTransaction) t).getFlowControlDelay());
} catch (Exception e) {
if (!ctx.queueManager.isTemporaryQueue(t.getQueueName()))
ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "commit (two phase) xid=" + signature + ", failed for queue: " + t.getQueueName() + ", exception: " + e);
}
}
if (registeredUsageList)
removeUsageEntity();
}
closed = true;
transactions.clear();
recoveryTransactions.clear();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/commit onePhase=" + onePhase + " done");
return fcDelay;
}
use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.
the class TransactedTopicSession method visit.
public void visit(CommitRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCommitRequest");
CommitReply reply = (CommitReply) req.createReply();
reply.setOk(true);
try {
// first: produce all messages
List ml = req.getMessages();
ctx.incMsgsSent(ml.size());
req.setMessages(null);
long fcDelay = 0;
RingBuffer tempProducers = null;
for (int i = 0; i < ml.size(); i++) {
DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) ml.get(i));
int producerId = dis.readInt();
int type = dis.readInt();
MessageImpl msg = MessageImpl.createInstance(type);
msg.readContent(dis);
dis.close();
long ttl = msg.getJMSExpiration();
if (ttl > 0)
msg.setJMSExpiration(System.currentTimeMillis() + ttl);
Producer producer = null;
if (producerId == -1) {
TopicImpl topic = (TopicImpl) msg.getJMSDestination();
if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
producer = new TopicProducer(ctx, topic);
if (tempProducers == null)
tempProducers = new RingBuffer(8);
tempProducers.add(producer);
transactionManager.addTransactionFactory(producer);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = producer.getTransaction();
transaction.putMessage(msg);
fcDelay = Math.max(fcDelay, transaction.getFlowControlDelay());
if (producerId == -1)
producer.markForClose();
}
// Next: do the commit
transactionManager.commit();
if (tempProducers != null) {
int size = tempProducers.getSize();
for (int i = 0; i < size; i++) {
((Producer) tempProducers.remove()).close();
}
}
reply.setDelay(fcDelay);
purgeMarkedProducers();
purgeMarkedConsumers();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/commit produced messages failed: " + e.getMessage());
reply.setOk(false);
reply.setException(e);
}
reply.send();
}
use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.
the class TransactedUnifiedSession method visit.
public void visit(CommitRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCommitRequest");
CommitReply reply = (CommitReply) req.createReply();
reply.setOk(true);
try {
// first: produce all messages
List ml = req.getMessages();
ctx.incMsgsSent(ml.size());
req.setMessages(null);
long fcDelay = 0;
RingBuffer tempProducers = null;
for (int i = 0; i < ml.size(); i++) {
DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) ml.get(i));
int producerId = dis.readInt();
int type = dis.readInt();
MessageImpl msg = MessageImpl.createInstance(type);
msg.readContent(dis);
dis.close();
long ttl = msg.getJMSExpiration();
if (ttl > 0)
msg.setJMSExpiration(System.currentTimeMillis() + ttl);
Producer producer = null;
if (producerId == -1) {
DestinationImpl destImpl = (DestinationImpl) msg.getJMSDestination();
switch(destImpl.getType()) {
case DestinationFactory.TYPE_QUEUE:
case DestinationFactory.TYPE_TEMPQUEUE:
String queueName = ((QueueImpl) destImpl).getQueueName();
if (!ctx.queueManager.isQueueRunning(queueName))
throw new InvalidDestinationException("Invalid destination: " + queueName);
producer = new QueueProducer(ctx, queueName);
break;
case DestinationFactory.TYPE_TOPIC:
case DestinationFactory.TYPE_TEMPTOPIC:
TopicImpl topic = (TopicImpl) msg.getJMSDestination();
if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
producer = new TopicProducer(ctx, topic);
break;
}
if (tempProducers == null)
tempProducers = new RingBuffer(8);
tempProducers.add(producer);
transactionManager.addTransactionFactory(producer);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = producer.getTransaction();
transaction.putMessage(msg);
fcDelay = Math.max(fcDelay, transaction.getFlowControlDelay());
if (producerId == -1)
producer.markForClose();
}
// Next: do the commit
transactionManager.commit();
if (tempProducers != null) {
int size = tempProducers.getSize();
for (int i = 0; i < size; i++) {
((Producer) tempProducers.remove()).close();
}
}
reply.setDelay(fcDelay);
purgeMarkedProducers();
purgeMarkedConsumers();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/commit produced messages failed: " + e.getMessage());
reply.setOk(false);
reply.setException(e);
}
reply.send();
}
use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.
the class TransactedQueueSession method visit.
public void visit(CommitRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCommitRequest");
CommitReply reply = (CommitReply) req.createReply();
reply.setOk(true);
try {
// first: produce all messages
List ml = req.getMessages();
ctx.incMsgsSent(ml.size());
long fcDelay = 0;
RingBuffer tempProducers = null;
for (int i = 0; i < ml.size(); i++) {
DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) ml.get(i));
int producerId = dis.readInt();
int type = dis.readInt();
MessageImpl msg = MessageImpl.createInstance(type);
msg.readContent(dis);
dis.close();
Producer producer = null;
if (producerId == -1) {
String queueName = ((QueueImpl) msg.getJMSDestination()).getQueueName();
if (!ctx.queueManager.isQueueRunning(queueName))
throw new InvalidDestinationException("Invalid destination: " + queueName);
producer = new QueueProducer(ctx, queueName);
if (tempProducers == null)
tempProducers = new RingBuffer(8);
tempProducers.add(producer);
transactionManager.addTransactionFactory(producer);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = producer.getTransaction();
transaction.putMessage(msg);
fcDelay = Math.max(fcDelay, transaction.getFlowControlDelay());
if (producerId == -1)
producer.markForClose();
}
// Next: do the commit
transactionManager.commit();
if (tempProducers != null) {
int size = tempProducers.getSize();
for (int i = 0; i < size; i++) {
((Producer) tempProducers.remove()).close();
}
}
reply.setDelay(fcDelay);
purgeMarkedProducers();
purgeMarkedConsumers();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/commit produced messages failed: " + e.getMessage());
reply.setOk(false);
reply.setException(e);
}
reply.send();
}
Aggregations