use of com.swiftmq.amqp.v091.types.Frame in project swiftmq-ce by iitsoftware.
the class ChannelHandler method handleHeaderFrame.
private void handleHeaderFrame(Frame frame) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", handleHeaderFrame");
if (currentMessage != null && currentMessage.getContentHeaderProperties() == null) {
try {
ContentHeaderProperties contentHeaderProperties = (ContentHeaderProperties) frame.getPayloadObject();
currentMessage.setContentHeaderProperties(contentHeaderProperties);
if (contentHeaderProperties.getBodySize() == 0)
publishCurrentMessage();
} catch (Exception e) {
amqpHandler.dispatch(new POSendChannelClose(channelNo, Constants.CHANNEL_ERROR, e.getMessage() == null ? e.toString() : e.getMessage(), currentMessage.getPublish()));
}
} else
amqpHandler.dispatch(new POSendClose(Constants.UNEXPECTED_FRAME, "Unexpected: " + frame));
}
use of com.swiftmq.amqp.v091.types.Frame in project swiftmq-ce by iitsoftware.
the class ChannelHandler method visit.
public void visit(POSendMessages po) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
try {
SourceMessageProcessor mp = po.getSourceMessageProcessor();
Consumer consumer = mp.getConsumer();
if (mp.getException() != null)
amqpHandler.dispatch(new POSendChannelClose(channelNo, Constants.CHANNEL_ERROR, mp.getException().toString(), null));
else {
if (!consumer.isNoAck() && waitingSends.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " sends waiting, adding to list");
waitingSends.add(po);
return;
}
Delivery[] deliveries = po.getDeliveries() != null ? po.getDeliveries() : mp.getTransformedMessages();
for (int i = po.getDeliveryStart(); i < deliveries.length; i++) {
Delivery delivery = deliveries[i];
if (!consumer.isNoAck() && !isWithinPrefetchLimits(delivery.getBody().length)) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " not within prefetch limit, adding to list");
po.setDeliveryStart(i);
po.setDeliveries(deliveries);
waitingSends.add(po);
return;
}
long deliveryTag = getNextDeliveryTag();
if (!consumer.isNoAck())
addUnacked(deliveryTag, consumer, delivery.getMessageIndex(), delivery.getBody().length);
else
consumer.ack(delivery.getMessageIndex());
Deliver deliver = new Deliver();
deliver.setConsumerTag(mp.getConsumer().getConsumerTag());
deliver.setDeliveryTag(deliveryTag);
deliver.setExchange("");
deliver.setRedelivered(delivery.isRedelivered());
deliver.setRoutingKey(mp.getConsumer().getOriginalQueueName());
Frame frame = new Frame(Frame.TYPE_METHOD, channelNo, 0, null);
amqpHandler.toPayload(frame, deliver);
versionedConnection.send(frame);
frame = new Frame(Frame.TYPE_HEADER, channelNo, 0, null);
ContentHeaderProperties contentHeaderProperties = delivery.getContentHeaderProperties();
contentHeaderProperties.setClassId(deliver._getClassId());
amqpHandler.toPayload(frame, contentHeaderProperties);
versionedConnection.send(frame);
byte[] body = delivery.getBody();
int maxFrameSize = amqpHandler.getMaxFrameSize();
int pos = 0;
while (pos < body.length) {
byte[] part = new byte[Math.min(body.length - pos, maxFrameSize)];
System.arraycopy(body, pos, part, 0, part.length);
pos += part.length;
frame = new Frame(Frame.TYPE_BODY, channelNo, 0, null);
frame.setPayload(part);
frame.setSize(part.length);
versionedConnection.send(frame);
}
}
mp.getConsumer().startMessageProcessor(mp);
}
} catch (Exception e) {
amqpHandler.dispatch(new POSendChannelClose(channelNo, Constants.CHANNEL_ERROR, e.toString(), null));
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
use of com.swiftmq.amqp.v091.types.Frame in project swiftmq-ce by iitsoftware.
the class ChannelHandler method sendFlow.
private void sendFlow(boolean activate) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", sendFlow (" + activate + ")");
remoteFlowActive = activate;
Flow flow = new Flow();
flow.setActive(activate);
Frame frame = new Frame(Frame.TYPE_METHOD, channelNo, 0, null);
amqpHandler.toPayload(frame, flow);
versionedConnection.send(frame);
}
Aggregations