Search in sources :

Example 36 with MessageImpl

use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.

the class NontransactedQueueSession method visit.

public void visit(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();
    int producerId = req.getQueueProducerId();
    Producer producer = null;
    try {
        MessageImpl msg = SMQPUtil.getMessage(req);
        long ttl = msg.getJMSExpiration();
        if (ttl > 0)
            msg.setJMSExpiration(System.currentTimeMillis() + ttl);
        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);
        }
    }
    if (req.isReplyRequired())
        reply.send();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageImpl(com.swiftmq.jms.MessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException)

Example 37 with MessageImpl

use of com.swiftmq.jms.MessageImpl in project swiftmq-client by iitsoftware.

the class WireTap method copyMessage.

private MessageImpl copyMessage(MessageImpl msg) {
    try {
        DataByteArrayOutputStream dbos = new DataByteArrayOutputStream();
        DataByteArrayInputStream dbis = new DataByteArrayInputStream();
        msg.writeContent(dbos);
        dbis.reset();
        dbis.setBuffer(dbos.getBuffer(), 0, dbos.getCount());
        MessageImpl msgCopy = MessageImpl.createInstance(dbis.readInt());
        msgCopy.readContent(dbis);
        return msgCopy;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : DataByteArrayOutputStream(com.swiftmq.tools.util.DataByteArrayOutputStream) IOException(java.io.IOException) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 38 with MessageImpl

use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.

the class MessageInterfaceListener method run.

public void run() {
    try {
        pullTransaction.commit();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception committing tx: " + e + ", exiting");
        return;
    }
    try {
        MessageImpl request = entry.getMessage();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, new message: " + request);
        String result = null;
        boolean showCommands = !request.propertyExists(PROP_SHOW_CMD_RESULT) || request.getBooleanProperty(PROP_SHOW_CMD_RESULT);
        if (request instanceof TextMessageImpl)
            result = executeCommands(((TextMessageImpl) request).getText(), showCommands);
        else
            result = "Invalid message type (" + request.getClass().getName() + "). Expect TextMessage!";
        QueueImpl queue = getReplyQueue(request);
        if (queue != null)
            sendReply(queue, request, result);
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
        ctx.logSwiftlet.logError(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
    }
    if (closed)
        return;
    try {
        pullTransaction = receiver.createTransaction(false);
        pullTransaction.registerMessageProcessor(this);
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception creating new tx: " + e + ", exiting");
        return;
    }
}
Also used : TextMessageImpl(com.swiftmq.jms.TextMessageImpl) TextMessageImpl(com.swiftmq.jms.TextMessageImpl) MessageImpl(com.swiftmq.jms.MessageImpl) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl)

Example 39 with MessageImpl

use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.

the class SessionStore method remove.

public synchronized void remove(String clientid) throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", remove, clientid=" + clientid);
    QueueReceiver receiver = ctx.queueManager.createQueueReceiver(STORE_QUEUE, null, null);
    QueuePullTransaction t = receiver.createTransaction(false);
    MessageEntry entry = null;
    while ((entry = t.getMessage(0)) != null) {
        MessageImpl msg = entry.getMessage();
        String cid = msg.getStringProperty(PROP_CLIENTID);
        if (cid.equals(clientid)) {
            QueuePullTransaction t2 = receiver.createTransaction(false);
            t2.moveToTransaction(entry.getMessageIndex(), t);
            t2.commit();
            break;
        }
    }
    t.rollback();
    receiver.close();
}
Also used : MessageImpl(com.swiftmq.jms.MessageImpl) TextMessageImpl(com.swiftmq.jms.TextMessageImpl)

Example 40 with MessageImpl

use of com.swiftmq.jms.MessageImpl in project swiftmq-client by iitsoftware.

the class MessageConsumerImpl method invokeMessageListener.

private void invokeMessageListener() {
    if (isClosed())
        return;
    AsyncMessageDeliveryRequest request = (AsyncMessageDeliveryRequest) messageCache.remove();
    MessageEntry messageEntry = request.getMessageEntry();
    MessageImpl msg = messageEntry.getMessage();
    messageEntry.moveMessageAttributes();
    MessageIndex msgIndex = msg.getMessageIndex();
    msg.setMessageConsumerImpl(this);
    try {
        msg.reset();
    } catch (JMSException e) {
        e.printStackTrace();
    }
    msg.setReadOnly(true);
    msg.setUseThreadContextCL(useThreadContextCL);
    if (reportDelivered)
        reportDelivered(msg);
    try {
        messageListener.onMessage(msg);
    } catch (RuntimeException e) {
        System.err.println("ERROR! MessageListener throws RuntimeException, shutting down consumer!");
        e.printStackTrace();
        try {
            close(e.toString());
        } catch (JMSException e1) {
        }
        return;
    }
    if (!wasRecovered) {
        if (request.isRequiresRestart())
            fillCache();
        if (doAck) {
            try {
                acknowledgeMessage(msgIndex, false);
            } catch (JMSException e) {
            }
        }
    } else
        wasRecovered = false;
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) MessageEntry(com.swiftmq.swiftlet.queue.MessageEntry) MessageImpl(com.swiftmq.jms.MessageImpl)

Aggregations

MessageImpl (com.swiftmq.jms.MessageImpl)106 JMSException (javax.jms.JMSException)42 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)33 InvalidSelectorException (javax.jms.InvalidSelectorException)31 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)28 QueueImpl (com.swiftmq.jms.QueueImpl)21 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)20 TopicImpl (com.swiftmq.jms.TopicImpl)17 MessageEntry (com.swiftmq.swiftlet.queue.MessageEntry)15 MessageIndex (com.swiftmq.swiftlet.queue.MessageIndex)15 RingBuffer (com.swiftmq.tools.collection.RingBuffer)14 InvalidDestinationException (javax.jms.InvalidDestinationException)14 List (java.util.List)13 EntityList (com.swiftmq.mgmt.EntityList)10 Message (javax.jms.Message)10 XidImpl (com.swiftmq.jms.XidImpl)6 DataByteArrayOutputStream (com.swiftmq.tools.util.DataByteArrayOutputStream)6 MessageSelector (com.swiftmq.ms.MessageSelector)5 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)4 ArrayList (java.util.ArrayList)4