Search in sources :

Example 11 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 12 with MessageImpl

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

the class HeuristicHandler method loadHeuristics.

public void loadHeuristics() throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/loadHeuristics");
    duringLoad = true;
    try {
        if (!ctx.queueManager.isQueueDefined(HEURISTIC_QUEUE))
            ctx.queueManager.createQueue(HEURISTIC_QUEUE, (ActiveLogin) null);
        QueueReceiver receiver = ctx.queueManager.createQueueReceiver(HEURISTIC_QUEUE, null, null);
        QueuePullTransaction t = receiver.createTransaction(false);
        MessageEntry entry = null;
        while ((entry = t.getMessage(0)) != null) {
            Entity entity = ctx.heuristicUsageList.createEntity();
            MessageImpl msg = entry.getMessage();
            maxId = Math.max(maxId, msg.getIntProperty(PROP_IID));
            messageToEntity(msg, entity);
            entity.createCommands();
            ctx.heuristicUsageList.addEntity(entity);
        }
        t.rollback();
        receiver.close();
    } finally {
        duringLoad = false;
    }
}
Also used : Entity(com.swiftmq.mgmt.Entity) ActiveLogin(com.swiftmq.swiftlet.auth.ActiveLogin) MessageImpl(com.swiftmq.jms.MessageImpl) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl)

Example 13 with MessageImpl

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

the class MessageSenderJob method getMessage.

private MessageImpl getMessage() throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.schedulerSwiftlet.getName(), toString() + "/getMessage ...");
    MessageSelector selector = new MessageSelector(ctx.PROP_SCHED_ID + " = '" + id + "'");
    selector.compile();
    QueueReceiver receiver = ctx.queueManager.createQueueReceiver(ctx.INTERNAL_QUEUE, null, selector);
    QueuePullTransaction t = receiver.createTransaction(false);
    MessageEntry entry = t.getMessage(0, selector);
    t.rollback();
    receiver.close();
    if (entry == null)
        throw new Exception("Schedule with ID '" + id + "' not found!");
    MessageImpl msg = copyMessage(entry.getMessage());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.schedulerSwiftlet.getName(), toString() + "/getMessage done");
    return msg;
}
Also used : MessageSelector(com.swiftmq.ms.MessageSelector) MessageImpl(com.swiftmq.jms.MessageImpl) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 14 with MessageImpl

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

the class FilePublishRequest method toMessage.

public Message toMessage() throws JMSException {
    Message message = new MessageImpl();
    fillMessage(message);
    message.setIntProperty(ProtocolFactory.DUMPID_PROP, ProtocolFactory.FILEPUBLISH_REQ);
    message.setStringProperty(REPLYQUEUE_PROP, replyQueue);
    message.setStringProperty(FILENAME_PROP, filename);
    if (username != null)
        message.setStringProperty(USERNAME_PROP, username);
    message.setLongProperty(SIZE_PROP, size);
    message.setLongProperty(EXPIRATION_PROP, expiration);
    message.setStringProperty(DIGESTTYPE_PROP, digestType);
    if (passwordHexDigest != null)
        message.setStringProperty(PWDHEXDIGEST_PROP, passwordHexDigest);
    message.setIntProperty(DELAFTERDL_PROP, deleteAfterNumberDownloads);
    message.setBooleanProperty(FILEISPRIVATE_PROP, fileIsPrivate);
    return message;
}
Also used : Message(javax.jms.Message) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 15 with MessageImpl

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

the class FileConsumeReply method toMessage.

public Message toMessage() throws JMSException {
    Message message = new MessageImpl();
    message.setIntProperty(ProtocolFactory.DUMPID_PROP, ProtocolFactory.FILECONSUME_REP);
    message.setStringProperty(FILENAME_PROP, filename);
    message.setIntProperty(CHUNKLENGTH_PROP, chunkLength);
    message.setLongProperty(SIZE_PROP, size);
    return fillMessage(message);
}
Also used : Message(javax.jms.Message) 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