use of org.apache.qpid.server.protocol.v0_8.transport.AMQFrame in project qpid-broker-j by apache.
the class BasicInteraction method publishMessage.
public Interaction publishMessage() throws Exception {
List<AMQFrame> frames = new ArrayList<>();
BasicPublishBody publishFrame = new BasicPublishBody(0, AMQShortString.valueOf(_publishExchange), AMQShortString.valueOf(_publishRoutingKey), _publishMandatory, _publishImmediate);
frames.add(new AMQFrame(_interaction.getChannelId(), publishFrame));
final BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
basicContentHeaderProperties.setHeaders(FieldTable.convertToFieldTable(_contentHeaderPropertiesHeaders));
basicContentHeaderProperties.setContentType(_contentHeaderPropertiesContentType);
basicContentHeaderProperties.setDeliveryMode(_contentHeaderPropertiesDeliveryMode);
basicContentHeaderProperties.setPriority(_contentHeaderPropertiesPriority);
final int contentSize = _content == null ? 0 : _content.length;
ContentHeaderBody contentHeaderBody = new ContentHeaderBody(basicContentHeaderProperties, contentSize);
frames.add(new AMQFrame(_interaction.getChannelId(), contentHeaderBody));
if (contentSize > 0) {
final byte[] contentCopy = new byte[contentSize];
System.arraycopy(_content, 0, contentCopy, 0, contentSize);
final int framePayloadMax = _interaction.getMaximumFrameSize() - 8;
int offset = 0;
do {
int contentToCopyLength = Math.min(framePayloadMax, contentSize - offset);
ContentBody contentBody = new ContentBody(ByteBuffer.wrap(contentCopy, offset, contentToCopyLength));
frames.add(new AMQFrame(_interaction.getChannelId(), contentBody));
offset += contentToCopyLength;
} while (offset < contentSize);
}
CompositeAMQDataBlock frame = new CompositeAMQDataBlock(frames.toArray(new AMQFrame[frames.size()]));
return _interaction.sendPerformative(frame);
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQFrame in project qpid-broker-j by apache.
the class Interaction method sendPerformative.
public Interaction sendPerformative(int channel, final AMQBody amqBody) throws Exception {
final AMQFrame frameBody = new AMQFrame(channel, amqBody);
sendPerformativeAndChainFuture(frameBody);
return this;
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQFrame in project qpid-broker-j by apache.
the class ProtocolOutputConverterImpl method writeMessageDeliveryUnchanged.
private void writeMessageDeliveryUnchanged(MessageContentSource content, int channelId, AMQBody deliverBody, ContentHeaderBody contentHeaderBody, int bodySize) {
if (bodySize == 0) {
SmallCompositeAMQBodyBlock compositeBlock = new SmallCompositeAMQBodyBlock(channelId, deliverBody, contentHeaderBody);
writeFrame(compositeBlock);
} else {
int maxBodySize = (int) _connection.getMaxFrameSize() - AMQFrame.getFrameOverhead();
int capacity = bodySize > maxBodySize ? maxBodySize : bodySize;
int writtenSize = capacity;
AMQBody firstContentBody = new MessageContentSourceBody(content, 0, capacity);
CompositeAMQBodyBlock compositeBlock = new CompositeAMQBodyBlock(channelId, deliverBody, contentHeaderBody, firstContentBody);
writeFrame(compositeBlock);
while (writtenSize < bodySize) {
capacity = bodySize - writtenSize > maxBodySize ? maxBodySize : bodySize - writtenSize;
AMQBody body = new MessageContentSourceBody(content, writtenSize, capacity);
writtenSize += capacity;
writeFrame(new AMQFrame(channelId, body));
}
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQFrame in project qpid-broker-j by apache.
the class AMQDecoderTest method testMultiplePartialFrameDecode.
public void testMultiplePartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
ByteBuffer msgA = getHeartbeatBodyBuffer();
ByteBuffer msgB = getHeartbeatBodyBuffer();
ByteBuffer msgC = getHeartbeatBodyBuffer();
ByteBuffer sliceA = ByteBuffer.allocate(msgA.remaining() + msgB.remaining() / 2);
sliceA.put(msgA);
int limit = msgB.limit();
int pos = msgB.remaining() / 2;
msgB.limit(pos);
sliceA.put(msgB);
sliceA.flip();
msgB.limit(limit);
msgB.position(pos);
ByteBuffer sliceB = ByteBuffer.allocate(msgB.remaining() + pos);
sliceB.put(msgB);
msgC.limit(pos);
sliceB.put(msgC);
sliceB.flip();
msgC.limit(limit);
_decoder.decodeBuffer(sliceA);
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
assertEquals(1, frames.size());
frames.clear();
_decoder.decodeBuffer(sliceB);
assertEquals(1, frames.size());
frames.clear();
_decoder.decodeBuffer(msgC);
assertEquals(1, frames.size());
for (AMQDataBlock frame : frames) {
if (frame instanceof AMQFrame) {
assertEquals(HeartbeatBody.FRAME.getBodyFrame().getFrameType(), ((AMQFrame) frame).getBodyFrame().getFrameType());
} else {
fail("decode was not a frame");
}
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQFrame in project qpid-broker-j by apache.
the class AMQDecoderTest method testPartialFrameDecode.
public void testPartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
ByteBuffer msg = getHeartbeatBodyBuffer();
ByteBuffer msgA = msg.slice();
int msgbPos = msg.remaining() / 2;
int msgaLimit = msg.remaining() - msgbPos;
msgA.limit(msgaLimit);
msg.position(msgbPos);
ByteBuffer msgB = msg.slice();
_decoder.decodeBuffer(msgA);
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
assertEquals(0, frames.size());
_decoder.decodeBuffer(msgB);
assertEquals(1, frames.size());
if (frames.get(0) instanceof AMQFrame) {
assertEquals(HeartbeatBody.FRAME.getBodyFrame().getFrameType(), ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
} else {
fail("decode was not a frame");
}
}
Aggregations