use of com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString in project swiftmq-ce by iitsoftware.
the class SourceLink method verifyLocalAddress.
public void verifyLocalAddress() throws AuthenticationException, QueueException, TopicException, InvalidSelectorException {
if (!dynamic) {
// This is for the case of reconnecting to a Durable Subscriber without specifying a Source in the attach frame.
if (localAddress == null) {
String topicName = ctx.topicManager.getDurableTopicName(getName(), mySessionHandler.getVersionedConnection().getActiveLogin());
if (topicName != null)
localAddress = new AddressString(topicName);
durability = TerminusDurability.CONFIGURATION;
}
super.verifyLocalAddress();
}
if (receiver == null) {
MessageSelector msel = null;
if (messageSelector != null) {
msel = new MessageSelector(messageSelector);
msel.compile();
}
if (dynamic) {
expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
durability = TerminusDurability.NONE;
// sndSettleMode = SenderSettleMode.SETTLED.getValue(); // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
queueName = ctx.queueManager.createTemporaryQueue();
receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
} else {
if (isQueue) {
expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
durability = TerminusDurability.CONFIGURATION;
// sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
receiver = ctx.queueManager.createQueueReceiver(getLocalAddress().getValueString(), mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
} else {
if (durability.getValue() == TerminusDurability.CONFIGURATION.getValue() || durability.getValue() == TerminusDurability.UNSETTLED_STATE.getValue()) {
if (!expiryPolicy.getValue().equals(TerminusExpiryPolicy.LINK_DETACH.getValue()))
expiryPolicy = TerminusExpiryPolicy.NEVER;
durability = TerminusDurability.CONFIGURATION;
// sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
queueName = ctx.topicManager.subscribeDurable(name, (TopicImpl) getLocalDestination(), msel, noLocal, mySessionHandler.getVersionedConnection().getActiveLogin());
} else {
expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
queueName = ctx.queueManager.createTemporaryQueue();
// sndSettleMode = SenderSettleMode.SETTLED.getValue(); // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
subscriberId = ctx.topicManager.subscribe((TopicImpl) localDestination, msel, noLocal, queueName, mySessionHandler.getVersionedConnection().getActiveLogin());
}
receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), null);
}
}
}
if (remoteUnsettled != null) {
final AbstractQueue aq = ctx.queueManager.getQueueForInternalUse(receiver.getQueueName());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, abstractQueue=" + aq);
DataByteArrayInputStream dbis = new DataByteArrayInputStream();
for (Iterator iter = remoteUnsettled.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
AMQPBinary deliveryTag = (AMQPBinary) entry.getKey();
DeliveryStateIF deliveryStateIF = null;
try {
deliveryStateIF = DeliveryStateFactory.create((AMQPList) entry.getValue());
} catch (Exception e) {
throw new QueueException("Unable to create delivery tag");
}
final MessageIndex messageIndex = new MessageIndex();
dbis.setBuffer(deliveryTag.getValue());
try {
messageIndex.readContent(dbis);
} catch (IOException e) {
throw new QueueException("Unable to convert delivery tag into a message index");
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", deliveryStateIF=" + deliveryStateIF);
if (deliveryStateIF != null) {
deliveryStateIF.accept(new DeliveryStateVisitorAdapter() {
public void visit(Accepted accepted) {
try {
if (aq != null) {
MessageIndex indexEntry = aq.getIndexEntry(messageIndex);
if (indexEntry != null) {
aq.removeMessageByIndex(indexEntry);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + indexEntry + ", removed");
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", NOT FOUND!");
}
}
} catch (QueueException e) {
e.printStackTrace();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", exception=" + e);
}
}
});
}
}
}
}
use of com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString 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.messaging.message_format.AddressString in project swiftmq-client by iitsoftware.
the class SessionDispatcher method visit.
public void visit(POAttachDurableConsumer po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " ...");
DeliveryMemory deliveryMemory = po.getDeliveryMemory();
if (deliveryMemory.getLinkName() != null)
deliveryMemory.setLinkName(po.getLinkName());
DurableConsumer consumer = new DurableConsumer(mySession, po.getSource(), po.getLinkName(), po.getLinkCredit(), po.getQoS(), deliveryMemory);
int handle = ArrayListTool.setFirstFreeOrExpand(handles, consumer);
consumer.setHandle(handle);
po.setLink(consumer);
waitingPO.put(po.getLinkName(), po);
try {
AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
attachFrame.setName(new AMQPString(po.getLinkName()));
attachFrame.setHandle(new Handle(handle));
attachFrame.setRole(Role.RECEIVER);
if (consumer.getQoS() == QoS.AT_MOST_ONCE)
attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
Source source = new Source();
String s = po.getSource();
if (s != null)
source.setAddress(new AddressString(s));
else
source.setDynamic(AMQPBoolean.TRUE);
// This identifies a durable
source.setDurable(TerminusDurability.CONFIGURATION);
source.setExpiryPolicy(po.getExpiryPolicy());
source.setTimeout(new Seconds(0));
Map m = null;
if (po.isNoLocal()) {
m = new HashMap();
m.put(new AMQPSymbol("no-local-filter"), new NoLocalFilter());
}
if (po.getSelector() != null) {
if (m == null)
m = new HashMap();
m.put(new AMQPSymbol("jms-selector-filter"), new SelectorFilter(po.getSelector()));
}
if (m != null)
source.setFilter(new FilterSet(m));
attachFrame.setSource(source);
Target target = new Target();
target.setAddress(new AddressString(uniqueSessionId + "/" + po.getSource() + "/" + (nextLinkId++)));
target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
target.setTimeout(new Seconds(0));
attachFrame.setTarget(target);
attachFrame.setUnsettled(getUnsettledMap(consumer.getDeliveryMemory()));
outboundHandler.send(attachFrame);
} catch (Exception e) {
e.printStackTrace();
}
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " done");
}
use of com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString in project swiftmq-client by iitsoftware.
the class SessionDispatcher method visit.
public void visit(POAttachProducer po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " ...");
String name = null;
DeliveryMemory deliveryMemory = po.getDeliveryMemory();
if (deliveryMemory.getLinkName() != null)
name = deliveryMemory.getLinkName();
else {
name = uniqueSessionId + "/" + po.getTarget() + "/" + (nextLinkId++);
deliveryMemory.setLinkName(name);
}
Producer producer = new Producer(mySession, po.getTarget(), name, po.getQoS(), deliveryMemory);
int handle = ArrayListTool.setFirstFreeOrExpand(handles, producer);
producer.setHandle(handle);
po.setLink(producer);
waitingPO.put(name, po);
try {
AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
attachFrame.setName(new AMQPString(name));
attachFrame.setHandle(new Handle(handle));
attachFrame.setRole(Role.SENDER);
switch(producer.getQoS()) {
case QoS.AT_LEAST_ONCE:
attachFrame.setRcvSettleMode(ReceiverSettleMode.FIRST);
break;
case QoS.AT_MOST_ONCE:
attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
break;
case QoS.EXACTLY_ONCE:
attachFrame.setRcvSettleMode(ReceiverSettleMode.SECOND);
break;
}
Source source = new Source();
source.setAddress(new AddressString(name));
source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
source.setTimeout(new Seconds(0));
attachFrame.setSource(source);
String t = po.getTarget();
if (t.equals(Coordinator.DESCRIPTOR_NAME)) {
Coordinator coordinator = new Coordinator();
coordinator.setCapabilities(new AMQPArray(AMQPTypeDecoder.SYM8, new AMQPType[] { TxnCapability.LOCAL_TRANSACTIONS }));
attachFrame.setTarget(coordinator);
} else {
Target target = new Target();
target.setAddress(new AddressString(t));
target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
target.setTimeout(new Seconds(0));
attachFrame.setTarget(target);
}
attachFrame.setInitialDeliveryCount(new SequenceNo(producer.getDeliveryCountSnd()));
attachFrame.setUnsettled(getUnsettledMap(producer.getDeliveryMemory()));
outboundHandler.send(attachFrame);
} catch (Exception e) {
e.printStackTrace();
}
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " done");
}
use of com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString in project swiftmq-client by iitsoftware.
the class SessionDispatcher method visit.
public void visit(POAttachConsumer po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " ...");
String name = null;
DeliveryMemory deliveryMemory = po.getDeliveryMemory();
if (deliveryMemory.getLinkName() != null)
name = deliveryMemory.getLinkName();
else {
name = uniqueSessionId + "/" + po.getSource() + "/" + (nextLinkId++);
deliveryMemory.setLinkName(name);
}
Consumer consumer = null;
if (po.getLinkCredit() == -1)
consumer = new Consumer(mySession, po.getSource(), name, po.getQoS(), deliveryMemory);
else
consumer = new Consumer(mySession, po.getSource(), name, po.getLinkCredit(), po.getQoS(), deliveryMemory);
int handle = ArrayListTool.setFirstFreeOrExpand(handles, consumer);
consumer.setHandle(handle);
po.setLink(consumer);
waitingPO.put(name, po);
try {
AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
attachFrame.setName(new AMQPString(name));
attachFrame.setHandle(new Handle(handle));
attachFrame.setRole(Role.RECEIVER);
if (consumer.getQoS() == QoS.AT_MOST_ONCE)
attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
Source source = new Source();
String s = po.getSource();
if (s != null)
source.setAddress(new AddressString(s));
else
source.setDynamic(AMQPBoolean.TRUE);
source.setDurable(TerminusDurability.NONE);
source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
source.setTimeout(new Seconds(0));
Map m = null;
if (po.isNoLocal()) {
m = new HashMap();
m.put(new AMQPSymbol("no-local-filter"), new NoLocalFilter());
}
if (po.getSelector() != null) {
if (m == null)
m = new HashMap();
m.put(new AMQPSymbol("jms-selector-filter"), new SelectorFilter(po.getSelector()));
}
if (m != null)
source.setFilter(new FilterSet(m));
attachFrame.setSource(source);
Target target = new Target();
target.setAddress(new AddressString(name));
target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
target.setTimeout(new Seconds(0));
attachFrame.setTarget(target);
attachFrame.setUnsettled(getUnsettledMap(consumer.getDeliveryMemory()));
outboundHandler.send(attachFrame);
} catch (Exception e) {
e.printStackTrace();
}
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Aggregations