Search in sources :

Example 6 with Method

use of org.apache.qpid.server.protocol.v0_10.transport.Method in project qpid-broker-j by apache.

the class ConsumerTarget_0_10 method doSend.

@Override
public void doSend(final MessageInstanceConsumer consumer, final MessageInstance entry, boolean batch) {
    ServerMessage serverMsg = entry.getMessage();
    MessageTransfer xfr;
    DeliveryProperties deliveryProps;
    MessageProperties messageProps = null;
    MessageTransferMessage msg;
    MessageConverter<? super ServerMessage, MessageTransferMessage> converter = null;
    if (serverMsg instanceof MessageTransferMessage) {
        msg = (MessageTransferMessage) serverMsg;
    } else {
        if (!serverMsg.checkValid()) {
            throw new MessageConversionException(String.format("Cannot convert malformed message '%s'", serverMsg));
        }
        converter = (MessageConverter<? super ServerMessage, MessageTransferMessage>) MessageConverterRegistry.getConverter(serverMsg.getClass(), MessageTransferMessage.class);
        msg = converter.convert(serverMsg, _session.getAddressSpace());
    }
    DeliveryProperties origDeliveryProps = msg.getHeader() == null ? null : msg.getHeader().getDeliveryProperties();
    messageProps = msg.getHeader() == null ? null : msg.getHeader().getMessageProperties();
    deliveryProps = new DeliveryProperties();
    if (origDeliveryProps != null) {
        if (origDeliveryProps.hasDeliveryMode()) {
            deliveryProps.setDeliveryMode(origDeliveryProps.getDeliveryMode());
        }
        if (origDeliveryProps.hasExchange()) {
            deliveryProps.setExchange(origDeliveryProps.getExchange());
        }
        if (origDeliveryProps.hasExpiration()) {
            deliveryProps.setExpiration(origDeliveryProps.getExpiration());
        }
        if (origDeliveryProps.hasPriority()) {
            deliveryProps.setPriority(origDeliveryProps.getPriority());
        }
        if (origDeliveryProps.hasRoutingKey()) {
            deliveryProps.setRoutingKey(origDeliveryProps.getRoutingKey());
        }
        if (origDeliveryProps.hasTimestamp()) {
            deliveryProps.setTimestamp(origDeliveryProps.getTimestamp());
        }
        if (origDeliveryProps.hasTtl()) {
            deliveryProps.setTtl(origDeliveryProps.getTtl());
        }
    }
    deliveryProps.setRedelivered(entry.isRedelivered());
    boolean msgCompressed = messageProps != null && GZIPUtils.GZIP_CONTENT_ENCODING.equals(messageProps.getContentEncoding());
    QpidByteBuffer bodyBuffer = msg.getBody();
    boolean compressionSupported = _session.getConnection().getConnectionDelegate().isCompressionSupported();
    if (msgCompressed && !compressionSupported && bodyBuffer != null) {
        QpidByteBuffer uncompressedBuffer = inflateIfPossible(bodyBuffer);
        messageProps.setContentEncoding(null);
        bodyBuffer.dispose();
        bodyBuffer = uncompressedBuffer;
    } else if (!msgCompressed && compressionSupported && (messageProps == null || messageProps.getContentEncoding() == null) && bodyBuffer != null && bodyBuffer.remaining() > _session.getConnection().getMessageCompressionThreshold()) {
        QpidByteBuffer compressedBuffers = deflateIfPossible(bodyBuffer);
        if (messageProps == null) {
            messageProps = new MessageProperties();
        }
        messageProps.setContentEncoding(GZIPUtils.GZIP_CONTENT_ENCODING);
        bodyBuffer.dispose();
        bodyBuffer = compressedBuffers;
    }
    Header header = new Header(deliveryProps, messageProps, msg.getHeader() == null ? null : msg.getHeader().getNonStandardProperties());
    xfr = batch ? new MessageTransfer(_name, _acceptMode, _acquireMode, header, bodyBuffer, BATCHED) : new MessageTransfer(_name, _acceptMode, _acquireMode, header, bodyBuffer);
    if (bodyBuffer != null) {
        bodyBuffer.dispose();
        bodyBuffer = null;
    }
    if (_acceptMode == MessageAcceptMode.NONE && _acquireMode != MessageAcquireMode.PRE_ACQUIRED) {
        xfr.setCompletionListener(new MessageAcceptCompletionListener(this, consumer, _session, entry, _flowMode == MessageFlowMode.WINDOW));
    } else if (_flowMode == MessageFlowMode.WINDOW) {
        final long messageSize = entry.getMessage().getSize();
        xfr.setCompletionListener(new Method.CompletionListener() {

            @Override
            public void onComplete(Method method) {
                deferredAddCredit(1, messageSize);
            }
        });
    }
    _postIdSettingAction.setXfr(xfr);
    _postIdSettingAction.setAction(null);
    if (_acquireMode == MessageAcquireMode.PRE_ACQUIRED) {
        entry.incrementDeliveryCount();
    }
    if (_acceptMode == MessageAcceptMode.EXPLICIT) {
        _postIdSettingAction.setAction(new ExplicitAcceptDispositionChangeListener(entry, this, consumer));
    } else if (_acquireMode != MessageAcquireMode.PRE_ACQUIRED) {
        _postIdSettingAction.setAction(new ImplicitAcceptDispositionChangeListener(entry, this, consumer));
    }
    _session.sendMessage(xfr, _postIdSettingAction);
    xfr.dispose();
    if (converter != null) {
        converter.dispose(msg);
    }
    _postIdSettingAction.setAction(null);
    _postIdSettingAction.setXfr(null);
    if (_acceptMode == MessageAcceptMode.NONE && _acquireMode == MessageAcquireMode.PRE_ACQUIRED) {
        forceDequeue(entry, false);
    } else if (_acquireMode == MessageAcquireMode.PRE_ACQUIRED) {
        addUnacknowledgedMessage(entry);
    }
}
Also used : MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ServerMessage(org.apache.qpid.server.message.ServerMessage) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) Method(org.apache.qpid.server.protocol.v0_10.transport.Method) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)

Example 7 with Method

use of org.apache.qpid.server.protocol.v0_10.transport.Method in project qpid-broker-j by apache.

the class Interaction method copyPerformative.

private <T extends Method> T copyPerformative(final T src) {
    T dst = (T) Method.create(src.getStructType());
    final BBEncoder encoder = new BBEncoder(4096);
    encoder.init();
    src.write(encoder);
    ByteBuffer buffer = encoder.buffer();
    final BBDecoder decoder = new BBDecoder();
    decoder.init(buffer);
    dst.read(decoder);
    dst.setChannel(src.getChannel());
    if (src.getHeader() != null) {
        Header srcHeader = src.getHeader();
        MessageProperties dstMessageProperties = null;
        DeliveryProperties dstDeliveryProperties = null;
        if (srcHeader.getMessageProperties() != null) {
            MessageProperties properties = srcHeader.getMessageProperties();
            dstMessageProperties = new MessageProperties();
            encoder.init();
            properties.write(encoder);
            decoder.init(encoder.buffer());
            dstMessageProperties.read(decoder);
        }
        if (srcHeader.getDeliveryProperties() != null) {
            DeliveryProperties properties = srcHeader.getDeliveryProperties();
            dstDeliveryProperties = new DeliveryProperties();
            encoder.init();
            properties.write(encoder);
            decoder.init(encoder.buffer());
            dstDeliveryProperties.read(decoder);
        }
        if (dstMessageProperties != null || dstDeliveryProperties != null) {
            dst.setHeader(new Header(dstDeliveryProperties, dstMessageProperties));
        }
    }
    if (src.getBody() != null) {
        dst.setBody(src.getBody());
    }
    return dst;
}
Also used : BBEncoder(org.apache.qpid.server.protocol.v0_10.transport.BBEncoder) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) ByteBuffer(java.nio.ByteBuffer) BBDecoder(org.apache.qpid.server.protocol.v0_10.transport.BBDecoder)

Example 8 with Method

use of org.apache.qpid.server.protocol.v0_10.transport.Method in project qpid-broker-j by apache.

the class Disassembler method method.

private void method(Method method, SegmentType type) {
    BBEncoder enc = _encoder.get();
    enc.init();
    enc.writeUint16(method.getEncodedType());
    if (type == SegmentType.COMMAND) {
        if (method.isSync()) {
            enc.writeUint16(0x0101);
        } else {
            enc.writeUint16(0x0100);
        }
    }
    method.write(enc);
    int methodLimit = enc.position();
    byte flags = FIRST_SEG;
    boolean payload = method.hasPayload();
    if (!payload) {
        flags |= LAST_SEG;
    }
    int headerLimit = -1;
    if (payload) {
        final Header hdr = method.getHeader();
        if (hdr != null) {
            if (hdr.getDeliveryProperties() != null) {
                enc.writeStruct32(hdr.getDeliveryProperties());
            }
            if (hdr.getMessageProperties() != null) {
                enc.writeStruct32(hdr.getMessageProperties());
            }
            if (hdr.getNonStandardProperties() != null) {
                for (Struct st : hdr.getNonStandardProperties()) {
                    enc.writeStruct32(st);
                }
            }
        }
        headerLimit = enc.position();
    }
    synchronized (_sendlock) {
        ByteBuffer buf = enc.underlyingBuffer();
        buf.flip();
        ByteBuffer copy = ByteBuffer.allocate(buf.remaining());
        copy.put(buf.duplicate());
        copy.flip();
        final ByteBuffer methodBuf = view(copy, 0, methodLimit);
        fragment(flags, type, method, methodBuf);
        if (payload) {
            QpidByteBuffer qpidByteBuffer = method.getBody();
            ByteBuffer body = null;
            if (qpidByteBuffer != null) {
                body = ByteBuffer.allocate(qpidByteBuffer.remaining());
                qpidByteBuffer.copyTo(body);
                body.flip();
            }
            ByteBuffer headerBuf = view(copy, methodLimit, headerLimit);
            fragment(body == null ? LAST_SEG : 0x0, SegmentType.HEADER, method, headerBuf);
            if (body != null) {
                fragment(LAST_SEG, SegmentType.BODY, method, body.duplicate());
            }
        }
    }
}
Also used : BBEncoder(org.apache.qpid.server.protocol.v0_10.transport.BBEncoder) ProtocolHeader(org.apache.qpid.server.protocol.v0_10.transport.ProtocolHeader) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Struct(org.apache.qpid.server.protocol.v0_10.transport.Struct)

Example 9 with Method

use of org.apache.qpid.server.protocol.v0_10.transport.Method in project qpid-broker-j by apache.

the class ServerSessionDelegateTest method testExchangeDeleteWhenIfUsedIsSetAndExchangeHasNoBinding.

@Test
public void testExchangeDeleteWhenIfUsedIsSetAndExchangeHasNoBinding() throws Exception {
    Exchange<?> exchange = mock(Exchange.class);
    when(exchange.hasBindings()).thenReturn(false);
    doReturn(exchange).when(_host).getAttainedMessageDestination(eq(getTestName()), anyBoolean());
    final ExchangeDelete method = new ExchangeDelete(getTestName(), Option.IF_UNUSED);
    _delegate.exchangeDelete(_session, method);
    verify(exchange).delete();
}
Also used : ExchangeDelete(org.apache.qpid.server.protocol.v0_10.transport.ExchangeDelete) Test(org.junit.Test)

Aggregations

Header (org.apache.qpid.server.protocol.v0_10.transport.Header)6 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)4 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)4 Method (org.apache.qpid.server.protocol.v0_10.transport.Method)4 ProtocolHeader (org.apache.qpid.server.protocol.v0_10.transport.ProtocolHeader)4 Struct (org.apache.qpid.server.protocol.v0_10.transport.Struct)4 ArrayList (java.util.ArrayList)3 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 Test (org.junit.Test)3 ByteBuffer (java.nio.ByteBuffer)2 BBDecoder (org.apache.qpid.server.protocol.v0_10.transport.BBDecoder)2 BBEncoder (org.apache.qpid.server.protocol.v0_10.transport.BBEncoder)2 ExchangeDelete (org.apache.qpid.server.protocol.v0_10.transport.ExchangeDelete)2 MessageTransfer (org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)2 Date (java.util.Date)1 Subject (javax.security.auth.Subject)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 ServerMessage (org.apache.qpid.server.message.ServerMessage)1 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)1 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)1