use of com.swiftmq.amqp.v100.types.AMQPMap in project swiftmq-ce by iitsoftware.
the class AMQPValueMapMessageFactory method verify.
public void verify(AMQPMessage message) throws Exception {
AmqpValue value = message.getAmqpValue();
if (value == null)
throw new Exception(("verify - no AmqpValue section found!"));
AMQPType t = value.getValue();
if (!(t instanceof AMQPMap))
throw new Exception(("verify - AmqpValue does not contain an AmqpMap!"));
Map map = ((AMQPMap) message.getAmqpValue().getValue()).getValue();
for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
if (!((entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals("key1")) || (entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals("key3")) || (entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals("REPLY")) || (entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals(String.valueOf(Integer.MAX_VALUE + 1))) || (entry.getKey() instanceof AMQPString && ((AMQPString) entry.getKey()).getValue().equals(String.valueOf(Integer.MAX_VALUE + 2))) || (entry.getKey() instanceof AMQPLong && ((AMQPLong) entry.getKey()).getValue() == Integer.MAX_VALUE + 1) || (entry.getKey() instanceof AMQPLong && ((AMQPLong) entry.getKey()).getValue() == Integer.MAX_VALUE + 2))) {
System.out.println(map);
throw new Exception("verify - invalid values in map detected: " + map);
}
}
}
use of com.swiftmq.amqp.v100.types.AMQPMap in project swiftmq-ce by iitsoftware.
the class AMQPValueMapMessageFactory method create.
public AMQPMessage create(int sequenceNo) throws Exception {
AMQPMessage msg = new AMQPMessage();
Map map = new HashMap();
map.put(new AMQPString("key1"), new AMQPString("value1"));
map.put(new AMQPLong(Integer.MAX_VALUE + 1), new AMQPLong(200));
map.put(new AMQPString("key3"), new AMQPString("value1"));
map.put(new AMQPLong(Integer.MAX_VALUE + 2), new AMQPLong(400));
msg.setAmqpValue(new AmqpValue(new AMQPMap(map)));
return msg;
}
use of com.swiftmq.amqp.v100.types.AMQPMap 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.AMQPMap 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.AMQPMap 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;
}
Aggregations