Search in sources :

Example 56 with QueuePushTransaction

use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.

the class XADeliveryStage method processTransactionRequest.

private void processTransactionRequest(TransactionRequest request) throws Exception {
    XidImpl xid = request.getXid();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + " ...");
    Tx tx = new Tx(xid);
    inboundTransactions.put(xid, tx);
    List messageList = request.getMessageList();
    for (int i = 0; i < messageList.size(); i++) {
        boolean msgValid = true;
        MessageImpl msg = (MessageImpl) messageList.get(i);
        String queueName = null;
        if (msg.getDestRouter().equals(ctx.routerName))
            queueName = msg.getDestQueue();
        else
            queueName = SchedulerRegistry.QUEUE_PREFIX + msg.getDestRouter();
        QueueSender sender = (QueueSender) producers.get(queueName);
        if (sender == null) {
            try {
                sender = ctx.queueManager.createQueueSender(queueName, null);
                producers.put(queueName, sender);
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", exception creating sender, queue=" + queueName);
                if (ctx.queueManager.isTemporaryQueue(queueName)) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", temp queue, forget it");
                    msgValid = false;
                } else {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", using unroutable queue");
                    sender = (QueueSender) producers.get(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
                    msg.setStringProperty(MessageImpl.PROP_UNROUTABLE_REASON, e.toString());
                }
            }
        }
        if (msgValid) {
            try {
                QueuePushTransaction t = tx.getTransaction(queueName);
                if (t == null) {
                    t = sender.createTransaction();
                    tx.addTransaction(queueName, t);
                }
                t.putMessage(msg);
            } catch (Exception e) {
                try {
                    if (!sender.getQueueName().startsWith(RoutingSwiftletImpl.UNROUTABLE_QUEUE))
                        sender.close();
                } catch (Exception e1) {
                }
                producers.remove(queueName);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", exception put message, queue=" + queueName);
                if (ctx.queueManager.isTemporaryQueue(queueName)) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", temp queue, forget it");
                } else {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", using unroutable queue");
                    sender = (QueueSender) producers.get(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
                    msg.setStringProperty(MessageImpl.PROP_UNROUTABLE_REASON, e.toString());
                    QueuePushTransaction t = tx.getTransaction(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
                    if (t == null) {
                        t = sender.createTransaction();
                        tx.addTransaction(RoutingSwiftletImpl.UNROUTABLE_QUEUE, t);
                    }
                    t.putMessage(msg);
                }
            }
        }
    }
    try {
        tx.prepare();
    } catch (Exception e) {
        tx.rollback();
        inboundTransactions.remove(xid);
        throw e;
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + " done");
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) XidImpl(com.swiftmq.jms.XidImpl) QueueSender(com.swiftmq.swiftlet.queue.QueueSender) MessageImpl(com.swiftmq.jms.MessageImpl) JMSException(javax.jms.JMSException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 57 with QueuePushTransaction

use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.

the class TopicAnnounceSender method send.

// <-- Exposed Methods
private void send(String dest, QueueSender sender, VersionObject vo) throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.topicManager.getName(), toString() + "/send, dest: " + dest + ", vo: " + vo);
    dos.rewind();
    dos.writeInt(vo.getDumpId());
    vo.writeContent(dos);
    BytesMessageImpl msg = new BytesMessageImpl();
    msg.writeBytes(dos.getBuffer(), 0, dos.getCount());
    msg.setJMSPriority(MessageImpl.MAX_PRIORITY);
    msg.setJMSDestination(new QueueImpl(TopicManagerImpl.TOPIC_QUEUE + "@" + dest));
    QueuePushTransaction transaction = sender.createTransaction();
    transaction.putMessage(msg);
    transaction.commit();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl)

Aggregations

QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)57 JMSException (javax.jms.JMSException)44 InvalidSelectorException (javax.jms.InvalidSelectorException)43 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)42 MessageImpl (com.swiftmq.jms.MessageImpl)33 InvalidDestinationException (javax.jms.InvalidDestinationException)28 RingBuffer (com.swiftmq.tools.collection.RingBuffer)21 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)21 QueueImpl (com.swiftmq.jms.QueueImpl)16 List (java.util.List)16 EntityList (com.swiftmq.mgmt.EntityList)15 TopicImpl (com.swiftmq.jms.TopicImpl)14 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)7 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)5 com.swiftmq.jms (com.swiftmq.jms)4 QueueException (com.swiftmq.swiftlet.queue.QueueException)4 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)3 XidImpl (com.swiftmq.jms.XidImpl)2 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)2 Versionable (com.swiftmq.tools.versioning.Versionable)2