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);
}
}
}
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;
}
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);
}
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;
}
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();
}
Aggregations