Search in sources :

Example 81 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class ServerDisassembler method frame.

private void frame(byte flags, byte type, byte track, int channel, int size, QpidByteBuffer buffer) {
    try (QpidByteBuffer data = QpidByteBuffer.allocateDirect(HEADER_SIZE)) {
        data.put(0, flags);
        data.put(1, type);
        data.putShort(2, (short) (size + HEADER_SIZE));
        data.put(4, (byte) 0);
        data.put(5, track);
        data.putShort(6, (short) channel);
        _sender.send(data);
    }
    if (size > 0) {
        try (QpidByteBuffer view = buffer.view(0, size)) {
            _sender.send(view);
            buffer.position(buffer.position() + size);
        }
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 82 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class ServerEncoder method getBuffer.

public QpidByteBuffer getBuffer() {
    int pos = _out.position();
    _out.position(0);
    QpidByteBuffer slice = _out.view(0, pos);
    QpidByteBuffer old = _out;
    _out.position(pos);
    _out = _out.slice();
    old.dispose();
    return slice;
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 83 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class ServerInputHandler method received.

public void received(QpidByteBuffer buf) {
    int position = buf.position();
    List<ServerFrame> frames = new ArrayList<>();
    while (buf.hasRemaining() && _state != ERROR) {
        buf.mark();
        switch(_state) {
            case PROTO_HDR:
                if (buf.remaining() < 8) {
                    break;
                }
                if (buf.get() != 'A' || buf.get() != 'M' || buf.get() != 'Q' || buf.get() != 'P') {
                    buf.reset();
                    error("bad protocol header: %s", str(buf));
                    _state = ERROR;
                } else {
                    byte protoClass = buf.get();
                    byte instance = buf.get();
                    byte major = buf.get();
                    byte minor = buf.get();
                    _serverAssembler.init(new ProtocolHeader(protoClass, instance, major, minor));
                    _state = FRAME_HDR;
                }
                break;
            case FRAME_HDR:
                if (buf.remaining() < ServerFrame.HEADER_SIZE) {
                    buf.reset();
                } else {
                    flags = buf.get();
                    type = SegmentType.get(buf.get());
                    int size = (0xFFFF & buf.getShort());
                    size -= ServerFrame.HEADER_SIZE;
                    if (size < 0 || size > (_maxFrameSize - ServerFrame.HEADER_SIZE)) {
                        error("bad frame size: %d", size);
                        _state = ERROR;
                    } else {
                        // skip unused byte
                        buf.get();
                        byte b = buf.get();
                        if ((b & 0xF0) != 0) {
                            error("non-zero reserved bits in upper nibble of " + "frame header byte 5: '%x'", b);
                            _state = ERROR;
                        } else {
                            track = (byte) (b & 0xF);
                            channel = (0xFFFF & buf.getShort());
                            buf.position(buf.position() + 4);
                            if (size == 0) {
                                ServerFrame frame = new ServerFrame(flags, type, track, channel, EMPTY_BYTE_BUFFER.duplicate());
                                frames.add(frame);
                            } else if (buf.remaining() < size) {
                                buf.reset();
                            } else {
                                final QpidByteBuffer body = buf.slice();
                                body.limit(size);
                                ServerFrame frame = new ServerFrame(flags, type, track, channel, body);
                                frames.add(frame);
                                buf.position(buf.position() + size);
                            }
                        }
                    }
                }
                break;
            default:
                throw new IllegalStateException();
        }
        int newPosition = buf.position();
        if (position == newPosition) {
            break;
        } else {
            position = newPosition;
        }
    }
    _serverAssembler.received(frames);
}
Also used : ArrayList(java.util.ArrayList) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ProtocolHeader(org.apache.qpid.server.protocol.v0_10.transport.ProtocolHeader)

Example 84 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class ServerSessionDelegate method createStoreMessage.

private StoredMessage<MessageMetaData_0_10> createStoreMessage(final MessageTransfer xfr, final MessageMetaData_0_10 messageMetaData, final MessageStore store) {
    final MessageHandle<MessageMetaData_0_10> addedMessage = store.addMessage(messageMetaData);
    QpidByteBuffer body = xfr.getBody();
    if (body != null) {
        addedMessage.addContent(body);
    }
    final StoredMessage<MessageMetaData_0_10> storedMessage = addedMessage.allContentAdded();
    return storedMessage;
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 85 with QpidByteBuffer

use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.

the class Method method toString.

@Override
public String toString() {
    StringBuilder str = new StringBuilder();
    str.append("ch=");
    str.append(channel);
    if (getEncodedTrack() == Frame.L4 && idSet) {
        str.append(" id=");
        str.append(id);
    }
    if (sync || batch) {
        str.append(" ");
        str.append("[");
        if (sync) {
            str.append("S");
        }
        if (batch) {
            str.append("B");
        }
        str.append("]");
    }
    str.append(" ");
    str.append(super.toString());
    Header hdr = getHeader();
    if (hdr != null) {
        for (Struct st : hdr.getStructs()) {
            str.append("\n  ");
            str.append(st);
        }
    }
    QpidByteBuffer body = getBody();
    if (body != null) {
        str.append("\n  body=");
        str.append(str(body, 64));
    }
    return str.toString();
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Aggregations

QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)185 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)61 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)61 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)42 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)30 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)29 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)29 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)29 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)28 ArrayList (java.util.ArrayList)22 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)20 Test (org.junit.Test)13 MapToJmsMapMessage (org.apache.qpid.server.typedmessage.mimecontentconverter.MapToJmsMapMessage)12 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)10 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)9 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)9 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)9 ByteBuffer (java.nio.ByteBuffer)8 LinkedHashMap (java.util.LinkedHashMap)8 JmsMapMessageToMap (org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap)8