Search in sources :

Example 1 with AMQPMap

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);
        }
    }
}
Also used : AMQPType(com.swiftmq.amqp.v100.types.AMQPType) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) AMQPLong(com.swiftmq.amqp.v100.types.AMQPLong) Iterator(java.util.Iterator) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) Map(java.util.Map) HashMap(java.util.HashMap) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 2 with AMQPMap

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;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) AMQPLong(com.swiftmq.amqp.v100.types.AMQPLong) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) Map(java.util.Map) HashMap(java.util.HashMap) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 3 with AMQPMap

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;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 4 with AMQPMap

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;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with AMQPMap

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;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Map (java.util.Map)9 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)8 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)8 IOException (java.io.IOException)8 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)7 HashMap (java.util.HashMap)7 List (java.util.List)7 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)6 ArrayList (java.util.ArrayList)6 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)4 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)4 Fields (com.swiftmq.amqp.v100.generated.transport.definitions.Fields)4 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)4 Iterator (java.util.Iterator)3 AmqpSequence (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence)2 Data (com.swiftmq.amqp.v100.generated.messaging.message_format.Data)2 Handle (com.swiftmq.amqp.v100.generated.transport.definitions.Handle)2 Seconds (com.swiftmq.amqp.v100.generated.transport.definitions.Seconds)2 TransferNumber (com.swiftmq.amqp.v100.generated.transport.definitions.TransferNumber)2 AMQPLong (com.swiftmq.amqp.v100.types.AMQPLong)2