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;
}
Aggregations