use of org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties in project qpid-broker-j by apache.
the class Assembler method assemble.
private void assemble(Frame frame, ByteBuffer segment) {
BBDecoder dec = _decoder.get();
dec.init(segment);
int channel = frame.getChannel();
Method command;
switch(frame.getType()) {
case CONTROL:
int controlType = dec.readUint16();
Method control = Method.create(controlType);
control.read(dec);
emit(channel, control);
break;
case COMMAND:
int commandType = dec.readUint16();
// read in the session header, right now we don't use it
int hdr = dec.readUint16();
command = Method.create(commandType);
command.setSync((0x0001 & hdr) != 0);
command.read(dec);
if (command.hasPayload() && !frame.isLastSegment()) {
setIncompleteCommand(channel, command);
} else {
emit(channel, command);
}
break;
case HEADER:
command = getIncompleteCommand(channel);
List<Struct> structs = null;
DeliveryProperties deliveryProps = null;
MessageProperties messageProps = null;
while (dec.hasRemaining()) {
Struct struct = dec.readStruct32();
if (struct instanceof DeliveryProperties && deliveryProps == null) {
deliveryProps = (DeliveryProperties) struct;
} else if (struct instanceof MessageProperties && messageProps == null) {
messageProps = (MessageProperties) struct;
} else {
if (structs == null) {
structs = new ArrayList<>(2);
}
structs.add(struct);
}
}
command.setHeader(new Header(deliveryProps, messageProps, structs));
if (frame.isLastSegment()) {
setIncompleteCommand(channel, null);
emit(channel, command);
}
break;
case BODY:
command = getIncompleteCommand(channel);
command.setBody(QpidByteBuffer.wrap(segment));
setIncompleteCommand(channel, null);
emit(channel, command);
break;
default:
throw new IllegalStateException("unknown frame type: " + frame.getType());
}
dec.releaseBuffer();
}
use of org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties in project qpid-broker-j by apache.
the class PropertyConverter_0_10_to_1_0Test method testExpirationConversion.
public void testExpirationConversion() {
long timestamp = System.currentTimeMillis();
int ttl = 100000;
final long expiration = timestamp + ttl;
final DeliveryProperties deliveryProperties = new DeliveryProperties();
deliveryProperties.setExpiration(expiration);
MessageTransferMessage message = createTestMessage(deliveryProperties, new MessageProperties(), null, timestamp);
final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
Properties properties = convertedMessage.getPropertiesSection().getValue();
assertNull("Unexpected expiration", properties.getAbsoluteExpiryTime());
Header header = convertedMessage.getHeaderSection().getValue();
assertEquals("Unexpected TTL", ttl, header.getTtl().intValue());
}
use of org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method testToConversionWhenQueueIsSpecified.
public void testToConversionWhenQueueIsSpecified() {
final String testQueue = "testQueue";
Properties properties = new Properties();
properties.setTo(testQueue);
Message_1_0 message = createTestMessage(properties);
final Queue<?> queue = mock(Queue.class);
when(queue.getName()).thenReturn(testQueue);
when(_namedAddressSpace.getAttainedMessageDestination(testQueue)).thenReturn(queue);
final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
final DeliveryProperties deliveryProperties = convertedMessage.getStoredMessage().getMetaData().getDeliveryProperties();
assertEquals("Unexpected exchange", "", deliveryProperties.getExchange());
assertEquals("Unexpected routing key", testQueue, deliveryProperties.getRoutingKey());
}
use of org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method testToConversionWhenExchangeAndRoutingKeyIsSpecified.
public void testToConversionWhenExchangeAndRoutingKeyIsSpecified() {
final String testExchange = "testExchange";
final String testRoutingKey = "testRoutingKey";
String to = testExchange + "/" + testRoutingKey;
Properties properties = new Properties();
properties.setTo(to);
Message_1_0 message = createTestMessage(properties);
final Exchange<?> exchange = mock(Exchange.class);
when(exchange.getName()).thenReturn(testExchange);
when(_namedAddressSpace.getAttainedMessageDestination(testExchange)).thenReturn(exchange);
final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
final DeliveryProperties deliveryProperties = convertedMessage.getStoredMessage().getMetaData().getDeliveryProperties();
assertEquals("Unexpected exchange", testExchange, deliveryProperties.getExchange());
assertEquals("Unexpected routing key", testRoutingKey, deliveryProperties.getRoutingKey());
}
use of org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method testAbsoluteExpiryTimeConversion.
public void testAbsoluteExpiryTimeConversion() {
long ttl = 10000;
long arrivalTime = System.currentTimeMillis();
long expiryTime = arrivalTime + ttl;
Properties properties = new Properties();
properties.setAbsoluteExpiryTime(new Date(expiryTime));
Message_1_0 message = createTestMessage(properties, arrivalTime);
final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
final DeliveryProperties deliveryProperties = convertedMessage.getStoredMessage().getMetaData().getDeliveryProperties();
assertEquals("Unexpected ttl", ttl, deliveryProperties.getTtl());
assertEquals("Unexpected expiration", expiryTime, deliveryProperties.getExpiration());
}
Aggregations