Search in sources :

Example 6 with QmfData

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

the class JSON method fromQmfData.

/**
 * Serialise a QmfData Object to JSON. If the Object is a QmfConsoleData we serialise the ObjectId as a String
 * which is the same encoding used for the various "ref" properies in fromObject().
 * @param data the QmfData that we wish to serialise to JSON.
 * @return the JSON String encoding.
 */
public static final String fromQmfData(final QmfData data) {
    String consoleDataInfo = "";
    if (data instanceof QmfConsoleData) {
        QmfConsoleData consoleData = (QmfConsoleData) data;
        SchemaClassId sid = consoleData.getSchemaClassId();
        long[] ts = consoleData.getTimestamps();
        String objectId = "\"_object_id\":\"" + consoleData.getObjectId().toString() + "\",";
        String schemaId = "\"_schema_id\":{" + "\"_package_name\":\"" + sid.getPackageName() + "\",\"_class_name\":\"" + sid.getClassName() + "\",\"_type\":\"" + sid.getType() + "\",\"_hash\":\"" + sid.getHashString() + "\"},";
        String timestamps = "\"_update_ts\":" + ts[0] + "," + "\"_create_ts\":" + ts[1] + "," + "\"_delete_ts\":" + ts[2] + ",";
        consoleDataInfo = objectId + schemaId + timestamps;
    }
    return "{" + consoleDataInfo + encodeMapContents(data.mapEncode()) + "}";
}
Also used : QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) SchemaClassId(org.apache.qpid.qmf2.common.SchemaClassId)

Example 7 with QmfData

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

the class AgentTest method onEvent.

public void onEvent(WorkItem wi) {
    System.out.println("WorkItem type: " + wi.getType());
    _control.incValue("methodCount", 1);
    if (wi.getType() == METHOD_CALL) {
        MethodCallWorkItem item = (MethodCallWorkItem) wi;
        MethodCallParams methodCallParams = item.getMethodCallParams();
        String methodName = methodCallParams.getName();
        ObjectId objectId = methodCallParams.getObjectId();
        String userId = methodCallParams.getUserId();
        userId = userId.equals("") ? "anonymous" : userId;
        QmfData inArgs = methodCallParams.getArgs();
        ObjectId controlAddress = _control.getObjectId();
        System.out.println("Method Call User ID = " + userId);
        try {
            if (objectId == null) {
                // Method invoked directly on Agent
                if (methodName.equals("toString")) {
                    QmfData outArgs = new QmfData();
                    outArgs.setValue("string", _agent.toString());
                    _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
                }
            } else if (objectId.equals(controlAddress)) {
                if (methodName.equals("stop")) {
                    System.out.println("Invoked stop method");
                    String message = inArgs.getStringValue("message");
                    System.out.println("Stopping: message = " + message);
                    _agent.methodResponse(methodName, item.getHandle(), null, null);
                    _agent.destroy();
                    System.exit(1);
                } else if (methodName.equals("echo")) {
                    System.out.println("Invoked echo method");
                    _agent.methodResponse(methodName, item.getHandle(), inArgs, null);
                } else if (methodName.equals("event")) {
                    System.out.println("Invoked event method");
                    QmfEvent event = new QmfEvent(_eventSchema);
                    event.setSeverity((int) inArgs.getLongValue("severity"));
                    event.setValue("text", inArgs.getStringValue("text"));
                    _agent.raiseEvent(event);
                    _agent.methodResponse(methodName, item.getHandle(), null, null);
                } else if (methodName.equals("fail")) {
                    System.out.println("Invoked fail method");
                    QmfData error = new QmfData();
                    if (inArgs.getBooleanValue("useString")) {
                        error.setValue("error_text", inArgs.getStringValue("stringVal"));
                    } else {
                        error.setValue("whatHappened", "It Failed");
                        error.setValue("howBad", 75);
                        error.setValue("details", inArgs.getValue("details"));
                    }
                    _agent.methodResponse(methodName, item.getHandle(), null, error);
                } else if (methodName.equals("create_child")) {
                    System.out.println("Invoked create_child method");
                    String childName = inArgs.getStringValue("name");
                    System.out.println("childName = " + childName);
                    QmfAgentData child = new QmfAgentData(_childSchema);
                    child.setValue("name", childName);
                    _agent.addObject(child);
                    QmfData outArgs = new QmfData();
                    // Set subtype just to test
                    outArgs.setRefValue("childAddr", child.getObjectId(), "reference");
                    _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
                }
            }
        } catch (QmfException qmfe) {
            System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentTest failed");
            QmfData error = new QmfData();
            error.setValue("error_text", qmfe.getMessage());
            _agent.methodResponse(methodName, item.getHandle(), null, error);
        }
    }
}
Also used : MethodCallWorkItem(org.apache.qpid.qmf2.agent.MethodCallWorkItem) QmfData(org.apache.qpid.qmf2.common.QmfData) ObjectId(org.apache.qpid.qmf2.common.ObjectId) MethodCallParams(org.apache.qpid.qmf2.agent.MethodCallParams) QmfEvent(org.apache.qpid.qmf2.common.QmfEvent) QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 8 with QmfData

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

the class BigPayloadAgentTest method onEvent.

public void onEvent(WorkItem wi) {
    System.out.println("WorkItem type: " + wi.getType());
    if (wi.getType() == METHOD_CALL) {
        MethodCallWorkItem item = (MethodCallWorkItem) wi;
        MethodCallParams methodCallParams = item.getMethodCallParams();
        String methodName = methodCallParams.getName();
        ObjectId objectId = methodCallParams.getObjectId();
        QmfData inArgs = methodCallParams.getArgs();
        ObjectId controlAddress = _control.getObjectId();
        if (objectId.equals(controlAddress)) {
            if (methodName.equals("processPayload")) {
                System.out.println("Invoked processPayload method");
                byte[] parameter = inArgs.getValue("parameter");
                System.out.println("payload size = " + parameter.length);
                QmfData outArgs = new QmfData();
                outArgs.setValue("return", parameter);
                _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
            }
        }
    }
}
Also used : MethodCallWorkItem(org.apache.qpid.qmf2.agent.MethodCallWorkItem) QmfData(org.apache.qpid.qmf2.common.QmfData) ObjectId(org.apache.qpid.qmf2.common.ObjectId) MethodCallParams(org.apache.qpid.qmf2.agent.MethodCallParams)

Example 9 with QmfData

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

the class QpidConfig method delExchange.

/**
 * Remove an exchange using the QMF "delete" method.
 * @param args the exchange name is the first argument.
 * The remaining QMF method properties are populated form config parsed from the command line.
 */
private void delExchange(final String[] args) {
    if (args.length < 1) {
        usage();
    }
    QmfData arguments = new QmfData();
    arguments.setValue("type", "exchange");
    arguments.setValue("name", args[0]);
    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 10 with QmfData

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

the class QpidConfig method delQueue.

/**
 * Remove a queue using the QMF "delete" 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 delQueue(final String[] args) {
    if (args.length < 1) {
        usage();
    }
    if (_ifEmpty || _ifUnused) {
        // Check the selected queue object to see if it is not empty or is in use
        List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
        for (QmfConsoleData queue : queues) {
            ObjectId queueId = queue.getObjectId();
            String name = queue.getStringValue("name");
            if (name.equals(args[0])) {
                long msgDepth = queue.getLongValue("msgDepth");
                if (_ifEmpty == true && msgDepth > 0) {
                    System.out.println("Cannot delete queue " + name + "; queue not empty");
                    return;
                }
                long consumerCount = queue.getLongValue("consumerCount");
                if (_ifUnused == true && consumerCount > 0) {
                    System.out.println("Cannot delete queue " + name + "; queue in use");
                    return;
                }
            }
        }
    }
    QmfData arguments = new QmfData();
    arguments.setValue("type", "queue");
    arguments.setValue("name", args[0]);
    try {
        _broker.invokeMethod("delete", arguments);
    } catch (QmfException e) {
        System.out.println(e.getMessage());
    }
}
Also used : QmfData(org.apache.qpid.qmf2.common.QmfData) ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) QmfException(org.apache.qpid.qmf2.common.QmfException)

Aggregations

QmfData (org.apache.qpid.qmf2.common.QmfData)16 QmfException (org.apache.qpid.qmf2.common.QmfException)13 HashMap (java.util.HashMap)8 JMSException (javax.jms.JMSException)7 Map (java.util.Map)6 MapMessage (javax.jms.MapMessage)6 ObjectId (org.apache.qpid.qmf2.common.ObjectId)6 QmfConsoleData (org.apache.qpid.qmf2.console.QmfConsoleData)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Message (javax.jms.Message)4 AMQPMessage (org.apache.qpid.qmf2.common.AMQPMessage)4 Handle (org.apache.qpid.qmf2.common.Handle)4 MethodCallParams (org.apache.qpid.qmf2.agent.MethodCallParams)3 MethodCallWorkItem (org.apache.qpid.qmf2.agent.MethodCallWorkItem)3 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)3 SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)3 IOException (java.io.IOException)2 Destination (javax.jms.Destination)2 AddressParser (org.apache.qpid.messaging.util.AddressParser)2 QmfEvent (org.apache.qpid.qmf2.common.QmfEvent)2