Search in sources :

Example 1 with TransactionFinishListener

use of com.swiftmq.impl.streams.TransactionFinishListener in project swiftmq-ce by iitsoftware.

the class Output method send.

/**
 * Sends a Message.
 *
 * @param message Message
 * @return Output
 * @throws Exception
 */
public Output send(Message message) throws Exception {
    try {
        if (sender == null) {
            sender = createSender();
            dest = getDestination();
        }
        txSent++;
        MessageImpl impl = message.getImpl();
        impl.setJMSDestination(dest);
        impl.setJMSTimestamp(System.currentTimeMillis());
        impl.setJMSMessageID(ctx.nextId());
        QueuePushTransaction transaction = sender.createTransaction();
        transaction.putMessage(impl);
        ctx.addTransaction(transaction, new TransactionFinishListener() {

            @Override
            public void transactionFinished() {
                txSent--;
                if (closed) {
                    try {
                        if (sender != null) {
                            if (txSent == 0) {
                                sender.close();
                            }
                        }
                    } catch (QueueException e) {
                        ctx.logStackTrace(e);
                    }
                }
            }
        });
        if (sent + 1 == Integer.MAX_VALUE)
            sent = 1;
        else
            sent++;
    } catch (Exception e) {
        if (!getDestination().toString().startsWith("tmp$"))
            throw e;
    }
    dirty = true;
    return this;
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) TransactionFinishListener(com.swiftmq.impl.streams.TransactionFinishListener) QueueException(com.swiftmq.swiftlet.queue.QueueException) MessageImpl(com.swiftmq.jms.MessageImpl) QueueException(com.swiftmq.swiftlet.queue.QueueException)

Aggregations

TransactionFinishListener (com.swiftmq.impl.streams.TransactionFinishListener)1 MessageImpl (com.swiftmq.jms.MessageImpl)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)1