Search in sources :

Example 16 with LargeServerMessage

use of org.apache.activemq.artemis.core.server.LargeServerMessage in project activemq-artemis by apache.

the class ServerSessionImpl method messageToLargeMessage.

private LargeServerMessage messageToLargeMessage(Message message) throws Exception {
    ICoreMessage coreMessage = message.toCore();
    LargeServerMessage lsm = getStorageManager().createLargeMessage(storageManager.generateID(), coreMessage);
    ActiveMQBuffer buffer = coreMessage.getReadOnlyBodyBuffer();
    byte[] body = new byte[buffer.readableBytes()];
    buffer.readBytes(body);
    lsm.addBytes(body);
    lsm.releaseResources();
    lsm.putLongProperty(Message.HDR_LARGE_BODY_SIZE, body.length);
    return lsm;
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 17 with LargeServerMessage

use of org.apache.activemq.artemis.core.server.LargeServerMessage in project activemq-artemis by apache.

the class ServerConsumerImpl method handle.

@Override
public HandleStatus handle(final MessageReference ref) throws Exception {
    if (callback != null && !callback.hasCredits(this) || availableCredits != null && availableCredits.get() <= 0) {
        if (logger.isDebugEnabled()) {
            logger.debug(this + " is busy for the lack of credits. Current credits = " + availableCredits + " Can't receive reference " + ref);
        }
        return HandleStatus.BUSY;
    }
    synchronized (lock) {
        // TCP-flow control has to be done first than everything else otherwise we may lose notifications
        if (!callback.isWritable(this, protocolContext) || !started || transferring) {
            return HandleStatus.BUSY;
        }
        // This has to be checked inside the lock as the set to null is done inside the lock
        if (largeMessageDeliverer != null) {
            if (logger.isDebugEnabled()) {
                logger.debug(this + " is busy delivering large message " + largeMessageDeliverer + ", can't deliver reference " + ref);
            }
            return HandleStatus.BUSY;
        }
        final Message message = ref.getMessage();
        if (!message.acceptsConsumer(sequentialID())) {
            return HandleStatus.NO_MATCH;
        }
        if (filter != null && !filter.match(message)) {
            if (logger.isTraceEnabled()) {
                logger.trace("Reference " + ref + " is a noMatch on consumer " + this);
            }
            return HandleStatus.NO_MATCH;
        }
        if (logger.isTraceEnabled()) {
            logger.trace("ServerConsumerImpl::" + this + " Handling reference " + ref);
        }
        if (!browseOnly) {
            if (!preAcknowledge) {
                deliveringRefs.add(ref);
            }
            ref.handled();
            ref.setConsumerId(this.id);
            ref.incrementDeliveryCount();
            // the updateDeliveryCountAfterCancel would still be updated after c
            if (strictUpdateDeliveryCount && !ref.isPaged()) {
                if (ref.getMessage().isDurable() && ref.getQueue().isDurableMessage() && !ref.getQueue().isInternalQueue() && !ref.isPaged()) {
                    storageManager.updateDeliveryCount(ref);
                }
            }
            if (preAcknowledge) {
                if (message.isLargeMessage()) {
                    // we must hold one reference, or the file will be deleted before it could be delivered
                    ((LargeServerMessage) message).incrementDelayDeletionCount();
                }
                // With pre-ack, we ack *before* sending to the client
                ref.getQueue().acknowledge(ref);
                acks++;
            }
            if (message.isLargeMessage() && this.supportLargeMessage) {
                largeMessageDeliverer = new LargeMessageDeliverer((LargeServerMessage) message, ref);
            }
        }
        lockDelivery.readLock().lock();
        return HandleStatus.HANDLED;
    }
}
Also used : LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage)

Aggregations

LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)17 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)6 Message (org.apache.activemq.artemis.api.core.Message)5 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)2 Pair (org.apache.activemq.artemis.api.core.Pair)2 JournalLoadInformation (org.apache.activemq.artemis.core.journal.JournalLoadInformation)2 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)2 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)2 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)2 PageTransactionInfoImpl (org.apache.activemq.artemis.core.paging.impl.PageTransactionInfoImpl)2 CursorAckRecordEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.CursorAckRecordEncoding)2 DeliveryCountUpdateEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.DeliveryCountUpdateEncoding)2 DuplicateIDEncoding (org.apache.activemq.artemis.core.persistence.impl.journal.codec.DuplicateIDEncoding)2