use of com.swiftmq.amqp.v100.generated.transport.definitions.MessageFormat in project swiftmq-ce by iitsoftware.
the class AMQPNativeInboundTransformer method transform.
public MessageImpl transform(TransferFrame frame, DestinationFactory destinationFactory) throws AMQPException, JMSException {
BytesMessageImpl msg = null;
if (frame.getMorePayloads() == null) {
byte[] payload = frame.getPayload();
msg = new BytesMessageImpl(payload, payload.length);
} else {
byte[] b = new byte[frame.getPayloadLength()];
byte[] payload = frame.getPayload();
System.arraycopy(payload, 0, b, 0, payload.length);
int pos = payload.length;
List morePayloads = frame.getMorePayloads();
for (int i = 0; i < morePayloads.size(); i++) {
payload = (byte[]) morePayloads.get(i);
System.arraycopy(payload, 0, b, pos, payload.length);
pos += payload.length;
}
msg = new BytesMessageImpl(b, b.length);
}
try {
msg.setLongProperty(messageFormat, frame.getMessageFormat().getValue());
msg.setBooleanProperty(amqpNative, true);
setDefaultHeader(msg);
} catch (Exception e) {
throw new AMQPException(e.toString());
}
msg.reset();
return msg;
}
use of com.swiftmq.amqp.v100.generated.transport.definitions.MessageFormat in project swiftmq-ce by iitsoftware.
the class JMSMappingOutboundTransformer method transform.
public void transform(Delivery delivery) throws AMQPException, JMSException {
jmsTypeProp = getValue(PROP_JMS_TYPE, null);
MessageImpl message = delivery.getMessage();
if (message.propertyExists(amqpNative) && message.getBooleanProperty(amqpNative))
throw new JMSException("Message is an AMQP native transformation");
try {
AMQPMessage amqpMessage = new AMQPMessage();
Header header = new Header();
int deliveryMode = message.getJMSDeliveryMode();
header.setDurable(new AMQPBoolean(deliveryMode == DeliveryMode.PERSISTENT));
header.setPriority(new AMQPUnsignedByte(message.getJMSPriority()));
header.setDeliveryCount(new AMQPUnsignedInt(delivery.getMessageIndex().getDeliveryCount() - 1));
long ttl = message.getJMSExpiration();
if (ttl > 0) {
if (message.propertyExists(Util.PROP_EXPIRATION_CURRENT_TIME_ADD))
header.setTtl(new Milliseconds(ttl - message.getLongProperty(Util.PROP_EXPIRATION_CURRENT_TIME_ADD)));
}
Properties properties = new Properties();
String messageId = message.getJMSMessageID();
if (messageId != null)
properties.setMessageId(new MessageIdString(message.getJMSMessageID()));
if (message.propertyExists(Util.PROP_AMQP_TO_ADDRESS))
properties.setTo(new AddressString(message.getStringProperty(Util.PROP_AMQP_TO_ADDRESS)));
else
properties.setTo(new AddressString(message.getJMSDestination().toString()));
Destination replyTo = message.getJMSReplyTo();
if (replyTo != null)
properties.setReplyTo(new AddressString(replyTo.toString()));
String correlationId = message.getJMSCorrelationID();
if (correlationId != null)
properties.setCorrelationId(new MessageIdString(correlationId));
if (ttl > 0)
properties.setAbsoluteExpiryTime(new AMQPTimestamp(ttl));
long timestamp = message.getJMSTimestamp();
if (timestamp > 0)
properties.setCreationTime(new AMQPTimestamp(timestamp));
Map daMap = null;
Map maMap = null;
Map ftMap = null;
Map apMap = null;
String firstAcquirerName = prefixVendor + "FirstAcquirer";
String subject = prefixVendor + "Subject";
String contentType = prefixVendor + "ContentType";
String contentEncoding = prefixVendor + "ContentEncoding";
String replyToGroupId = prefixVendor + "ReplyToGroupID";
for (Enumeration _enum = message.getPropertyNames(); _enum.hasMoreElements(); ) {
String name = (String) _enum.nextElement();
if (name.equals(amqpNative) || name.equals(messageFormat) || name.equals(Util.PROP_EXPIRATION_CURRENT_TIME_ADD) || name.equals(Util.PROP_AMQP_TO_ADDRESS))
continue;
if (name.equals(firstAcquirerName))
header.setFirstAcquirer(new AMQPBoolean(message.getBooleanProperty(firstAcquirerName)));
else if (name.equals(MessageImpl.PROP_USER_ID))
properties.setUserId(new AMQPBinary(message.getStringProperty(MessageImpl.PROP_USER_ID).getBytes()));
else if (name.equals(subject))
properties.setSubject(new AMQPString(message.getStringProperty(subject)));
else if (name.equals(contentType))
properties.setContentType(new AMQPSymbol(message.getStringProperty(contentType)));
else if (name.equals(contentEncoding))
properties.setContentEncoding(new AMQPSymbol(message.getStringProperty(contentEncoding)));
else if (name.equals("JMSXGroupID") && message.getObjectProperty(Util.PROP_GROUP_ID) instanceof String)
properties.setGroupId(new AMQPString(message.getStringProperty(Util.PROP_GROUP_ID)));
else if (name.equals("JMSXGroupSeq") && message.getObjectProperty(Util.PROP_GROUP_SEQ) instanceof Long)
properties.setGroupSequence(new SequenceNo(message.getLongProperty(Util.PROP_GROUP_SEQ)));
else if (name.equals(replyToGroupId))
properties.setReplyToGroupId(new AMQPString(message.getStringProperty(replyToGroupId)));
else if (name.startsWith(prefixDA)) {
if (daMap == null)
daMap = new HashMap();
daMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixDA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
} else if (name.startsWith(prefixMA)) {
if (maMap == null)
maMap = new HashMap();
maMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixMA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
} else if (name.startsWith(prefixFT)) {
if (ftMap == null)
ftMap = new HashMap();
ftMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixFT.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
} else {
if (apMap == null)
apMap = new HashMap();
apMap.put(new AMQPString(nameTranslator.translate(name)), Util.convertJMStoAMQP(message.getObjectProperty(name)));
}
}
if (message.getJMSType() != null) {
if (jmsTypeProp != null) {
if (apMap == null)
apMap = new HashMap();
apMap.put(new AMQPString(jmsTypeProp), Util.convertJMStoAMQP(message.getJMSType()));
} else {
if (maMap == null)
maMap = new HashMap();
maMap.put(new AMQPSymbol("x-opt-jms-type"), new AMQPString(message.getJMSType()));
}
}
amqpMessage.setHeader(header);
amqpMessage.setProperties(properties);
if (daMap != null)
amqpMessage.setDeliveryAnnotations(new DeliveryAnnotations(daMap));
if (maMap != null)
amqpMessage.setMessageAnnotations(new MessageAnnotations(maMap));
if (apMap != null)
amqpMessage.setApplicationProperties(new ApplicationProperties(apMap));
if (ftMap != null)
amqpMessage.setFooter(new Footer(ftMap));
bodyFactory.createBody(message, amqpMessage);
delivery.setAmqpMessage(amqpMessage);
dbos.rewind();
amqpMessage.writeContent(dbos);
byte[] payload = new byte[dbos.getCount()];
System.arraycopy(dbos.getBuffer(), 0, payload, 0, dbos.getCount());
delivery.setData(payload);
delivery.setMessageFormat(0);
} catch (IOException e) {
e.printStackTrace();
throw new AMQPException(e.toString());
}
}
use of com.swiftmq.amqp.v100.generated.transport.definitions.MessageFormat in project swiftmq-client by iitsoftware.
the class SessionDispatcher method doSend.
private void doSend(POSendMessage po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, po=" + po + ", dataLength=" + po.getPackager().getSize());
try {
Producer producer = po.getProducer();
producer.verifyState();
Packager packager = po.getPackager();
if (remoteIncomingWindow > 0 && outgoingWindow > 0) {
do {
boolean wasFirstPacket = false;
boolean isAtMostOnce = producer.getQoS() == QoS.AT_MOST_ONCE;
packager.setMaxFrameSize(mySession.myConnection.connectionDispatcher.getMaxFrameSize());
TransferFrame frame = new TransferFrame(mySession.getChannel());
frame.setHandle(new Handle(producer.getHandle()));
frame.setSettled(new AMQPBoolean(isAtMostOnce));
if (packager.getCurrentPacketNumber() == 0) {
long dId = nextDeliveryId();
wasFirstPacket = true;
producer.incDeliveryCountSnd();
DeliveryTag deliveryTag = po.getDeliveryTag() != null ? po.getDeliveryTag() : producer.createDeliveryTag();
if (!isAtMostOnce) {
if (po.getTxnId() == null && !po.isRecovery())
producer.getDeliveryMemory().addUnsettledDelivery(new UnsettledDelivery(deliveryTag, null, po.getMessage()));
unsettledOutgoingDeliveries.put(dId, new DeliveryMapping(deliveryTag, producer));
}
frame.setDeliveryTag(deliveryTag);
frame.setDeliveryId(new DeliveryNumber(dId));
frame.setMessageFormat(new MessageFormat(0));
TxnIdIF txnId = po.getTxnId();
if (txnId != null) {
TransactionalState txState = new TransactionalState();
txState.setTxnId(txnId);
frame.setState(txState);
}
}
packager.setMessageFormat(0);
packager.getNextPacket(frame);
// We may increase the outgoing window and send a flow before
if (wasFirstPacket && outgoingWindow - packager.getPredictedNumberPackets() < 0) {
outgoingWindow += packager.getPredictedNumberPackets();
sendFlow();
windowChanged = true;
}
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", sending message, wasFirstPacket=" + wasFirstPacket + ", maxSize=" + packager.getMaxPayloadLength() + ", packetSize=" + frame.getPayload().length + ", predictedNumberPackets=" + packager.getPredictedNumberPackets() + ", currentPacket=" + packager.getCurrentPacketNumber() + ", hasMore=" + packager.hasMore());
outboundHandler.send(frame);
nextOutgoingId++;
remoteIncomingWindow--;
if (!isAtMostOnce)
outgoingWindow--;
if (!packager.hasMore()) {
// b) everything else: after the last packet has been sent
if (producer.isTransactionController() || po.getTxnId() != null)
producer.setWaitingPO(po);
else {
po.setSuccess(true);
if (po.getSemaphore() != null)
po.getSemaphore().notifySingleWaiter();
}
// If that was the last packet and outgoing window was increased for this message, we need to reset it and send another flow
if (windowChanged) {
outgoingWindow = mySession.getOutgoingWindowSize();
sendFlow();
}
break;
}
} while (remoteIncomingWindow > 0 && outgoingWindow > 0);
if (packager.hasMore()) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", has more but no window, storing message");
outboundDeliveries.add(po);
}
} else {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, po=" + po + ", remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", no window, storing message");
outboundDeliveries.add(po);
}
} catch (Exception e) {
po.setSuccess(false);
po.setException(e.getMessage());
if (po.getSemaphore() != null)
po.getSemaphore().notifySingleWaiter();
}
}
use of com.swiftmq.amqp.v100.generated.transport.definitions.MessageFormat in project swiftmq-client by iitsoftware.
the class Packager method getNextPacket.
public void getNextPacket(TransferFrame currentFrame) throws IOException {
currentFrame.setMore(AMQPBoolean.FALSE);
if (messageFormat != -1)
currentFrame.setMessageFormat(new MessageFormat(messageFormat));
currentPacketNumber++;
byte[] b = null;
if (dbis != null) {
int len = Math.min(dbis.available(), maxPacketLength - currentFrame.getPredictedSize());
b = new byte[len];
dbis.readFully(b);
} else {
if (maxPacketLength - currentFrame.getPredictedSize() - size >= 0) {
if (data.length != size) {
b = new byte[size];
System.arraycopy(data, 0, b, 0, size);
data = null;
} else
b = data;
} else {
if (dbis == null) {
dbis = new DataByteArrayInputStream();
dbis.setBuffer(data, 0, size);
}
int len = Math.min(dbis.available(), maxPacketLength - currentFrame.getPredictedSize());
b = new byte[len];
dbis.readFully(b);
}
}
if (hasMore())
currentFrame.setMore(AMQPBoolean.TRUE);
currentFrame.setPayload(b);
if (predictedNumberPackets == -1)
predictedNumberPackets = size / b.length + 1;
}
Aggregations