Search in sources :

Example 1 with QmfException

use of org.apache.qpid.qmf2.common.QmfException in project qpid by apache.

the class Test4 method addObject.

public void addObject(QmfAgentData object) throws QmfException {
    SchemaClassId classId = object.getSchemaClassId();
    SchemaClass schema = _schemaCache.get(classId);
    // Try to create an objectName using the set of property names that have been specified as idNames in the schema
    StringBuilder buf = new StringBuilder();
    if (schema != null && schema instanceof SchemaObjectClass) {
        String[] idNames = ((SchemaObjectClass) schema).getIdNames();
        for (String name : idNames) {
            buf.append(object.getStringValue(name));
        }
    }
    String objectName = buf.toString();
    // If the schema hasn't given any help we use a UUID
    if (objectName.length() == 0)
        objectName = UUID.randomUUID().toString();
    // Finish up the name by incorporating package and class names
    objectName = classId.getPackageName() + ":" + classId.getClassName() + ":" + objectName;
    // Now we've got a good name for the object we create it's ObjectId and add that to the object
    ObjectId addr = new ObjectId("test", /*name*/
    objectName, 0);
    object.setObjectId(addr);
    if (_objectIndex.get(addr) != null) {
        throw new QmfException("Duplicate QmfAgentData Address");
    }
    _objectIndex.put(addr, object);
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) SchemaClass(org.apache.qpid.qmf2.common.SchemaClass) SchemaObjectClass(org.apache.qpid.qmf2.common.SchemaObjectClass) SchemaClassId(org.apache.qpid.qmf2.common.SchemaClassId) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 2 with QmfException

use of org.apache.qpid.qmf2.common.QmfException in project qpid by apache.

the class QpidConfig method addExchange.

/**
 * Add an exchange using the QMF "create" method.
 * @param args the exchange type is the first argument and the exchange name is the second argument.
 * The remaining QMF method properties are populated form config parsed from the command line.
 */
private void addExchange(final String[] args) {
    if (args.length < 2) {
        usage();
    }
    Map<String, Object> properties = new HashMap<String, Object>();
    if (_durable) {
        properties.put("durable", true);
    }
    properties.put("exchange-type", args[0]);
    if (_msgSequence) {
        properties.put(MSG_SEQUENCE, 1l);
    }
    if (_ive) {
        properties.put(IVE, 1l);
    }
    if (_altExchange != null) {
        properties.put("alternate-exchange", _altExchange);
    }
    QmfData arguments = new QmfData();
    arguments.setValue("type", "exchange");
    arguments.setValue("name", args[1]);
    arguments.setValue("properties", properties);
    try {
        _broker.invokeMethod("create", arguments);
    } catch (QmfException e) {
        System.out.println(e.getMessage());
    }
// passive exchange creation not implemented yet (not sure how to do it using QMF2)
}
Also used : QmfData(org.apache.qpid.qmf2.common.QmfData) HashMap(java.util.HashMap) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 3 with QmfException

use of org.apache.qpid.qmf2.common.QmfException in project qpid by apache.

the class QpidConfig method unbind.

/**
 * Remove a binding using the QMF "delete" method.
 * @param args the exchange name is the first argument, the queue name is the second argument and the binding key
 * is the third argument.
 * The remaining QMF method properties are populated form config parsed from the command line.
 */
private void unbind(final String[] args) {
    if (args.length < 2) {
        usage();
    }
    String bindingIdentifier = args[0] + "/" + args[1];
    if (args.length > 2) {
        bindingIdentifier = bindingIdentifier + "/" + args[2];
    }
    QmfData arguments = new QmfData();
    arguments.setValue("type", "binding");
    arguments.setValue("name", bindingIdentifier);
    try {
        _broker.invokeMethod("delete", arguments);
    } catch (QmfException e) {
        System.out.println(e.getMessage());
    }
}
Also used : QmfData(org.apache.qpid.qmf2.common.QmfData) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 4 with QmfException

use of org.apache.qpid.qmf2.common.QmfException in project qpid by apache.

the class QpidConfig method addQueue.

/**
 * Add a queue using the QMF "create" method.
 * @param args the queue name is the first argument.
 * The remaining QMF method properties are populated form config parsed from the command line.
 */
private void addQueue(final String[] args) {
    if (args.length < 1) {
        usage();
    }
    Map<String, Object> properties = new HashMap<String, Object>();
    for (String a : extraArguments) {
        String[] r = a.split("=");
        String value = r.length == 2 ? r[1] : null;
        properties.put(r[0], value);
    }
    if (_durable) {
        properties.put("durable", true);
        properties.put(FILECOUNT, _fileCount);
        properties.put(FILESIZE, _fileSize);
    }
    if (_maxQueueSize > 0) {
        properties.put(MAX_QUEUE_SIZE, _maxQueueSize);
    }
    if (_maxQueueCount > 0) {
        properties.put(MAX_QUEUE_COUNT, _maxQueueCount);
    }
    if (_limitPolicy.equals("reject")) {
        properties.put(POLICY_TYPE, "reject");
    } else if (_limitPolicy.equals("flow-to-disk")) {
        properties.put(POLICY_TYPE, "flow_to_disk");
    } else if (_limitPolicy.equals("ring")) {
        properties.put(POLICY_TYPE, "ring");
    } else if (_limitPolicy.equals("ring-strict")) {
        properties.put(POLICY_TYPE, "ring_strict");
    }
    if (_order.equals("lvq")) {
        properties.put(LVQ, 1l);
    } else if (_order.equals("lvq-no-browse")) {
        properties.put(LVQNB, 1l);
    }
    if (_altExchange != null) {
        properties.put("alternate-exchange", _altExchange);
    }
    if (_flowStopSize > 0) {
        properties.put(FLOW_STOP_SIZE, _flowStopSize);
    }
    if (_flowResumeSize > 0) {
        properties.put(FLOW_RESUME_SIZE, _flowResumeSize);
    }
    if (_flowStopCount > 0) {
        properties.put(FLOW_STOP_COUNT, _flowStopCount);
    }
    if (_flowResumeCount > 0) {
        properties.put(FLOW_RESUME_COUNT, _flowResumeCount);
    }
    QmfData arguments = new QmfData();
    arguments.setValue("type", "queue");
    arguments.setValue("name", args[0]);
    arguments.setValue("properties", properties);
    try {
        _broker.invokeMethod("create", arguments);
    } catch (QmfException e) {
        System.out.println(e.getMessage());
    }
// passive queue creation not implemented yet (not sure how to do it using QMF2)
}
Also used : QmfData(org.apache.qpid.qmf2.common.QmfData) HashMap(java.util.HashMap) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 5 with QmfException

use of org.apache.qpid.qmf2.common.QmfException in project qpid by apache.

the class QpidConfig method bind.

/**
 * Add a binding using the QMF "create" method.
 * @param args the exchange name is the first argument, the queue name is the second argument and the binding key
 * is the third argument.
 * The remaining QMF method properties are populated form config parsed from the command line.
 */
private void bind(final String[] args) {
    if (args.length < 2) {
        usage();
    }
    // Look up exchange objects to find the type of the selected exchange
    String exchangeType = null;
    List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
    for (QmfConsoleData exchange : exchanges) {
        String name = exchange.getStringValue("name");
        if (args[0].equals(name)) {
            exchangeType = exchange.getStringValue("type");
            break;
        }
    }
    if (exchangeType == null) {
        System.out.println("Exchange " + args[0] + " is invalid");
        return;
    }
    Map<String, Object> properties = new HashMap<String, Object>();
    if (exchangeType.equals("xml")) {
        if (_file == null) {
            System.out.println("Invalid args to bind xml:  need an input file or stdin");
            return;
        }
        String xquery = null;
        if (_file.equals("-")) {
            // Read xquery off stdin
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            try {
                StringBuilder buf = new StringBuilder();
                String line;
                while (// read until eof
                (line = in.readLine()) != null) {
                    buf.append(line + "\n");
                }
                xquery = buf.toString();
            } catch (IOException ioe) {
                System.out.println("Exception " + ioe + " while reading stdin");
                return;
            }
        } else {
            // Read xquery from input file
            File file = new File(_file);
            try {
                FileInputStream fin = new FileInputStream(file);
                try {
                    byte[] content = new byte[(int) file.length()];
                    fin.read(content);
                    xquery = new String(content);
                } finally {
                    fin.close();
                }
            } catch (FileNotFoundException e) {
                System.out.println("File " + _file + " not found");
                return;
            } catch (IOException ioe) {
                System.out.println("Exception " + ioe + " while reading " + _file);
                return;
            }
        }
        properties.put("xquery", xquery);
    } else if (exchangeType.equals("headers")) {
        if (args.length < 5) {
            System.out.println("Invalid args to bind headers: need 'any'/'all' plus conditions");
            return;
        }
        String op = args[3];
        if (op.equals("all") || op.equals("any")) {
            properties.put("x-match", op);
            String[] bindings = Arrays.copyOfRange(args, 4, args.length);
            for (String binding : bindings) {
                if (binding.contains("=")) {
                    binding = binding.split(",")[0];
                    String[] kv = binding.split("=");
                    properties.put(kv[0], kv[1]);
                }
            }
        } else {
            System.out.println("Invalid condition arg to bind headers, need 'any' or 'all', not '" + op + "'");
            return;
        }
    }
    String bindingIdentifier = args[0] + "/" + args[1];
    if (args.length > 2) {
        bindingIdentifier = bindingIdentifier + "/" + args[2];
    }
    QmfData arguments = new QmfData();
    arguments.setValue("type", "binding");
    arguments.setValue("name", bindingIdentifier);
    arguments.setValue("properties", properties);
    try {
        _broker.invokeMethod("create", arguments);
    } catch (QmfException e) {
        System.out.println(e.getMessage());
    }
}
Also used : QmfData(org.apache.qpid.qmf2.common.QmfData) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedReader(java.io.BufferedReader) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) File(java.io.File) QmfException(org.apache.qpid.qmf2.common.QmfException)

Aggregations

QmfException (org.apache.qpid.qmf2.common.QmfException)24 QmfData (org.apache.qpid.qmf2.common.QmfData)13 JMSException (javax.jms.JMSException)9 ObjectId (org.apache.qpid.qmf2.common.ObjectId)8 HashMap (java.util.HashMap)6 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)6 QmfQuery (org.apache.qpid.qmf2.common.QmfQuery)5 SchemaObjectClass (org.apache.qpid.qmf2.common.SchemaObjectClass)5 QmfConsoleData (org.apache.qpid.qmf2.console.QmfConsoleData)5 Destination (javax.jms.Destination)4 MapMessage (javax.jms.MapMessage)4 Handle (org.apache.qpid.qmf2.common.Handle)4 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)3 SchemaMethod (org.apache.qpid.qmf2.common.SchemaMethod)3 SchemaProperty (org.apache.qpid.qmf2.common.SchemaProperty)3 IOException (java.io.IOException)2 Timer (java.util.Timer)2 Message (javax.jms.Message)2