Package org.apache.qpid.qmf2.common

Examples of org.apache.qpid.qmf2.common.QmfQuery


     */
    private void createQueueSubscription()
    {
        try
        {   // This QmfQuery simply does an ID query for objects with the className "queue"
            QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, new SchemaClassId("queue"));
            SubscribeParams params = _console.createSubscription(_broker, query, "queueStatsHandle");
            _subscriptionId = params.getSubscriptionId();
            _subscriptionDuration = params.getLifetime() - 10; // Subtract 10 as we want to refresh before it times out
            _startTime = System.currentTimeMillis();
        }
View Full Code Here


            addObject(ostrich);


            System.out.println("total number of objects registered: " + _objectIndex.size());

            QmfQuery query;
            List<QmfConsoleData> results;

            System.out.println("looking up wasp object by ID");
            query = new QmfQuery(QmfQueryTarget.OBJECT, wasp.getObjectId());
            results = evaluateDataQuery(query);
            displayResults(results);

            System.out.println("\nlooking up mammal objects");
            query = new QmfQuery(QmfQueryTarget.OBJECT, new SchemaClassId("mammal"));
            results = evaluateDataQuery(query);
            displayResults(results);

            System.out.println("\nlooking up everything in package com.fadams.qmf2");
            query = new QmfQuery(QmfQueryTarget.OBJECT, new SchemaClassId("com.fadams.qmf2", null));
            results = evaluateDataQuery(query);
            displayResults(results);


            System.out.println("\nQuery for all mammals with more than two legs");
            String predicate = "['and', ['eq', '_package_name', ['quote', 'com.fadams.qmf2']], " +
                                       "['eq', '_class_name', ['quote', 'mammal']], " +
                                       "['gt', 'legs', 2]]";

            //predicate = "['eq', '_package_name', ['quote', 'com.fadams.qmf2']]";

            //predicate = "[]";

            query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
            System.out.println(query.getPredicate());

            results = evaluateDataQuery(query);
            displayResults(results);


            System.out.println("\nQuery for everything with less than four legs");
            predicate = "['lt', 'legs', 4]";

            query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
            System.out.println(query.getPredicate());

            results = evaluateDataQuery(query);
            displayResults(results);


            System.out.println("\nQuery for everything with between two and four legs");
            predicate = "['and', ['ge', 'legs', 2], " +
                                "['le', 'legs', 4]]";

            query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
            System.out.println(query.getPredicate());

            results = evaluateDataQuery(query);
            displayResults(results);


            System.out.println("\nQuery for all reptiles or birds");
            predicate = "['or', ['eq', '_class_name', ['quote', 'reptile']], " +
                               "['eq', '_class_name', ['quote', 'bird']]]";

            query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
            System.out.println(query.getPredicate());

            results = evaluateDataQuery(query);
            displayResults(results);


            System.out.println("\nQuery for everything whose name matches the regex ^h");
            predicate = "['re_match', 'name', ['quote', '^h']]";

            query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
            System.out.println(query.getPredicate());

            results = evaluateDataQuery(query);
            displayResults(results);

View Full Code Here

            {
                if (AMQPMessage.isAMQPMap(message))
                {
                    try
                    {
                        QmfQuery query = new QmfQuery(AMQPMessage.getMap(message));
                        handleQueryRequest(handle, query);
                    }
                    catch (QmfException qmfe)
                    {
                        raiseException(handle, "Query Request failed, invalid Query: " + qmfe.getMessage());
View Full Code Here

        _objectIndex.put(addr, object);

        // Does the new object match any Subscriptions? If so add a reference to the matching Subscription and publish.
        for (Subscription subscription : _subscriptions.values())
        {
            QmfQuery query = subscription.getQuery();
            if (query.getObjectId() != null)
            {
                if (query.getObjectId().equals(addr))
                {
                    object.addSubscription(subscription.getSubscriptionId(), subscription);
                    object.publish();
                }
            }
            else if (query.evaluate(object))
            {
                object.addSubscription(subscription.getSubscriptionId(), subscription);
                object.publish();
            }
        }
View Full Code Here

        }

        if (wi.getType() == QUERY)
        {
            QueryWorkItem item = (QueryWorkItem)wi;
            QmfQuery query = item.getQmfQuery();

            System.out.println("Query User ID = " + item.getUserId());

            if (query.getObjectId() != null)
            {
                // Look up a QmfAgentData object by the ObjectId obtained from the query
                ObjectId objectId = query.getObjectId();
                QmfAgentData object = _objectIndex.get(objectId);
                if (object != null && !object.isDeleted())
                {
                    _agent.queryResponse(item.getHandle(), object);
                }
                _agent.queryComplete(item.getHandle(), 0);
            }
            else
            {
                // Look up QmfAgentData objects by the SchemaClassId obtained from the query
                // This is implemented by a linear search and allows searches with only the className specified.
                // Linear searches clearly don't scale brilliantly, but the number of QmfAgentData objects managed
                // by an Agent is generally fairly small, so it should be OK. Note that this is the same approach
                // taken by the C++ broker ManagementAgent, so if it's a problem here........
                for (QmfAgentData object : _objectIndex.values())
                {
                    if (!object.isDeleted() && query.evaluate(object))
                    {
                        _agent.queryResponse(item.getHandle(), object);
                    }
                }
                _agent.queryComplete(item.getHandle(), 0);
View Full Code Here

        _objectIndex.put(addr, object);

        // Does the new object match any Subscriptions? If so add a reference to the matching Subscription and publish.
        for (Subscription subscription : _subscriptions.values())
        {
            QmfQuery query = subscription.getQuery();
            if (query.getObjectId() != null)
            {
                if (query.getObjectId().equals(addr))
                {
                    object.addSubscription(subscription.getSubscriptionId(), subscription);
                    object.publish();
                }
            }
            else if (query.evaluate(object))
            {
                object.addSubscription(subscription.getSubscriptionId(), subscription);
                object.publish();
            }
        }
View Full Code Here

                    }
                    else if (_subscriptionEmulationEnabled && agentName.equals(_brokerAgentName))
                    { // If the data has come from is the broker Agent we emulate a Subscription on the Console
                        for (SubscriptionManager subscription : _subscriptionByHandle.values())
                        {
                            QmfQuery query = subscription.getQuery();
                            if (subscription.getAgent().getName().equals(_brokerAgentName) &&
                                query.getTarget() == QmfQueryTarget.OBJECT)
                            { // Only evaluate broker Agent subscriptions with QueryTarget == OBJECT on the Console.
                                long objectEpoch = 0;
                                consoleHandle = subscription.getConsoleHandle();
                                List<Map> list = AMQPMessage.getList(message);
                                List<QmfConsoleData> resultList = new ArrayList<QmfConsoleData>(list.size());
                                for (Map m : list)
                                { // Evaluate the QmfConsoleData object against the query
                                    QmfConsoleData object = new QmfConsoleData(m, agent);
                                    if (query.evaluate(object))
                                    {
                                        long epoch = object.getObjectId().getAgentEpoch();
                                        objectEpoch = (epoch > objectEpoch && !object.isDeleted()) ? epoch : objectEpoch;
                                        resultList.add(object);
                                    }
View Full Code Here

            }

            System.out.println("Creating Query for objects whose name property has a value that starts with 'a'");

            SubscribeParams params;
            QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, "['re_match', 'name', ['quote', '^a']]");

            // Create a subscription, response returned synchronously
            params = _console.createSubscription(_broker, query, "consoleHandle1", "{publishInterval:5}");
            System.out.println("duration = " + params.getLifetime());
            System.out.println("interval = " + params.getPublishInterval());
            System.out.println("subscriptionId = " + params.getSubscriptionId());
            System.out.println("consoleHandle = " + params.getConsoleHandle());

            // Sleep a while, getting query result as they become available
            try
            {
                Thread.sleep(20000);
            }
            catch (InterruptedException ie)
            {
            }

            // Refresh the subscription getting results asynchronously, just for variety
            System.out.println("Calling refreshSubscription on " + params.getSubscriptionId());
            _console.refreshSubscription(params.getSubscriptionId(), "{replyHandle:ignoredReplyHandle}");


            // Create a subscription for _class_name = queue
            System.out.println("Creating Query for all queue objects");
            query = new QmfQuery(QmfQueryTarget.OBJECT, "['eq', '_class_name', ['quote', 'queue']]");
            params = _console.createSubscription(_broker, query, "queues");

            while (_objectId == null)
            {
                System.out.println("Waiting for ObjectId to be set");
                try
                {
                    Thread.sleep(1000);
                }
                catch (InterruptedException ie)
                {
                }
            }

            // Cancel the query for all queue objects
            System.out.println("Cancelling Query for all queue objects");
            _console.cancelSubscription(params.getSubscriptionId());

            // Create a subscription for _object_id
            System.out.println("Creating Query for _object_id = " + _objectId);
            query = new QmfQuery(QmfQueryTarget.OBJECT, _objectId);
            params = _console.createSubscription(_broker, query, "queues");

        }
        catch (QmfException qmfe)
        {
View Full Code Here

            }

            System.out.println("Creating Query for objects whose state property has a value that starts with 'OP'");

            SubscribeParams params;
            QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, "['re_match', 'state', ['quote', '^OP']]");

            // Create a subscription, response returned synchronously
            params = _console.createSubscription(_gizmo, query, "consoleHandle1", "{publishInterval:5}");
            System.out.println("duration = " + params.getLifetime());
            System.out.println("interval = " + params.getPublishInterval());
View Full Code Here

     */
    private void createQueueSubscription()
    {
        try
        {   // This QmfQuery simply does an ID query for objects with the className "queue"
            QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, new SchemaClassId("queue"));
            SubscribeParams params = _console.createSubscription(_broker, query, "queueStatsHandle");
            _subscriptionId = params.getSubscriptionId();
            _subscriptionDuration = params.getLifetime() - 10; // Subtract 10 as we want to refresh before it times out
            _startTime = System.currentTimeMillis();
        }
View Full Code Here

TOP

Related Classes of org.apache.qpid.qmf2.common.QmfQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.