use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-client by iitsoftware.
the class AMQPRepo method add.
AMQPRepo add(File file, String appname) throws Exception {
String filename = file.getName();
String content = loadFile(file);
AMQPMessage request = new AMQPMessage();
Map propMap = new HashMap();
propMap.put(new AMQPString("app"), new AMQPString(appname));
propMap.put(new AMQPString("file"), new AMQPString(filename));
propMap.put(new AMQPString("operation"), new AMQPString("add"));
request.setApplicationProperties(new ApplicationProperties(propMap));
Properties properties = new Properties();
properties.setReplyTo(replyQueue);
request.setProperties(properties);
request.setAmqpValue(new AmqpValue(new AMQPString(content)));
producer.send(request);
AMQPMessage reply = consumer.receive(TIMEOUT);
if (reply == null)
throw new Exception("Timeout occurred while waiting for a reply!");
AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
if (success)
System.out.println(filename + " added to repository " + appname);
else {
String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
System.out.println(result);
}
return this;
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-client by iitsoftware.
the class AMQPRepo method remove.
AMQPRepo remove(File file, String appname) throws Exception {
String filename = file.getName();
AMQPMessage request = new AMQPMessage();
Map propMap = new HashMap();
propMap.put(new AMQPString("app"), new AMQPString(appname));
propMap.put(new AMQPString("file"), new AMQPString(filename));
propMap.put(new AMQPString("operation"), new AMQPString("remove"));
request.setApplicationProperties(new ApplicationProperties(propMap));
Properties properties = new Properties();
properties.setReplyTo(replyQueue);
request.setProperties(properties);
producer.send(request);
AMQPMessage reply = consumer.receive(TIMEOUT);
if (reply == null)
throw new Exception("Timeout occurred while waiting for a reply!");
AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
if (success)
System.out.println(filename + " removed from repository " + appname);
else {
String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
System.out.println(result);
}
return this;
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-client by iitsoftware.
the class AMQPRepo method list.
AMQPRepo list(String appname) throws Exception {
AMQPMessage request = new AMQPMessage();
Map propMap = new HashMap();
propMap.put(new AMQPString("app"), new AMQPString(appname));
propMap.put(new AMQPString("operation"), new AMQPString("list"));
request.setApplicationProperties(new ApplicationProperties(propMap));
Properties properties = new Properties();
properties.setReplyTo(replyQueue);
request.setProperties(properties);
producer.send(request);
AMQPMessage reply = consumer.receive(TIMEOUT);
if (reply == null)
throw new Exception("Timeout occurred while waiting for a reply!");
AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
if (success) {
System.out.println("Content of repository " + appname + ":");
System.out.println();
int n = Integer.parseInt(((AMQPString) (body.getValue().get(new AMQPString("nfiles")))).getValue());
for (int i = 0; i < n; i++) System.out.println(((AMQPString) (body.getValue().get(new AMQPString("storetime" + i)))).getValue() + "\t" + ((AMQPString) (body.getValue().get(new AMQPString("file" + i)))).getValue());
System.out.println();
} else {
String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
System.out.println(result);
}
return this;
}
use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-client by iitsoftware.
the class Properties method decode.
private void decode() throws Exception {
List l = getValue();
AMQPType t = null;
int idx = 0;
// Factory : MessageIdFactory
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() != AMQPTypeDecoder.NULL)
messageId = MessageIdFactory.create(t);
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
userId = (AMQPBinary) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'userId' in 'Properties' type: " + e);
}
// Factory : AddressFactory
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() != AMQPTypeDecoder.NULL)
to = AddressFactory.create(t);
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
subject = (AMQPString) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'subject' in 'Properties' type: " + e);
}
// Factory : AddressFactory
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() != AMQPTypeDecoder.NULL)
replyTo = AddressFactory.create(t);
// Factory : MessageIdFactory
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
if (t.getCode() != AMQPTypeDecoder.NULL)
correlationId = MessageIdFactory.create(t);
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
contentType = (AMQPSymbol) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'contentType' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
contentEncoding = (AMQPSymbol) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'contentEncoding' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
absoluteExpiryTime = (AMQPTimestamp) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'absoluteExpiryTime' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
creationTime = (AMQPTimestamp) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'creationTime' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
groupId = (AMQPString) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'groupId' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
groupSequence = new SequenceNo(((AMQPUnsignedInt) t).getValue());
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'groupSequence' in 'Properties' type: " + e);
}
// Factory : ./.
if (idx >= l.size())
return;
t = (AMQPType) l.get(idx++);
try {
if (t.getCode() != AMQPTypeDecoder.NULL)
replyToGroupId = (AMQPString) t;
} catch (ClassCastException e) {
throw new Exception("Invalid type of field 'replyToGroupId' in 'Properties' type: " + e);
}
}
use of com.swiftmq.amqp.v100.types.AMQPString 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");
}
Aggregations