Search in sources :

Example 11 with QmfAgentData

use of org.apache.qpid.qmf2.agent.QmfAgentData in project qpid by apache.

the class AgentTest method populateData.

public void populateData() throws QmfException {
    System.out.println("*** AgentTest creating a control object ***");
    _control = new QmfAgentData(_controlSchema);
    _control.setValue("state", "OPERATIONAL");
    _control.setValue("methodCount", 0);
    _agent.addObject(_control);
    System.out.println("AgentTest Schema control object added OK");
}
Also used : QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData)

Example 12 with QmfAgentData

use of org.apache.qpid.qmf2.agent.QmfAgentData in project qpid by apache.

the class BigPayloadAgentTest method populateData.

public void populateData() throws QmfException {
    System.out.println("*** BigPayloadAgentTest creating a control object ***");
    _control = new QmfAgentData(_controlSchema);
    _control.setValue("name", "controller");
    _agent.addObject(_control);
    System.out.println("BigPayloadAgentTest Schema control object added OK");
}
Also used : QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData)

Example 13 with QmfAgentData

use of org.apache.qpid.qmf2.agent.QmfAgentData in project qpid by apache.

the class AgentExternalTest method evaluateQuery.

/**
     * This method evaluates a QmfQuery over the Agent's data on behalf of a Subscription
     *
     * @param query the QmfQuery that the Subscription wants to be evaluated over the Agent's data
     * @return a List of QmfAgentData objects that match the specified QmfQuery
     */
public List<QmfAgentData> evaluateQuery(QmfQuery query) {
    List<QmfAgentData> results = new ArrayList<QmfAgentData>(_objectIndex.size());
    if (query.getTarget() == QmfQueryTarget.OBJECT) {
        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()) {
                results.add(object);
            }
        } else {
            // Look up QmfAgentData objects evaluating the query
            for (QmfAgentData object : _objectIndex.values()) {
                if (!object.isDeleted() && query.evaluate(object)) {
                    results.add(object);
                }
            }
        }
    }
    return results;
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) ArrayList(java.util.ArrayList) QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData)

Example 14 with QmfAgentData

use of org.apache.qpid.qmf2.agent.QmfAgentData in project qpid by apache.

the class AgentExternalTest method onEvent.

public void onEvent(WorkItem wi) {
    System.out.println("WorkItem type: " + wi.getType());
    if (wi.getType() == METHOD_CALL) {
        _control.incValue("methodCount", 1);
        MethodCallWorkItem item = (MethodCallWorkItem) wi;
        MethodCallParams methodCallParams = item.getMethodCallParams();
        String methodName = methodCallParams.getName();
        ObjectId objectId = methodCallParams.getObjectId();
        String userId = methodCallParams.getUserId();
        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);
                    addObject(child);
                    QmfData outArgs = new QmfData();
                    // Set suptype 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: AgentExternalTest failed");
            QmfData error = new QmfData();
            error.setValue("error_text", qmfe.getMessage());
            _agent.methodResponse(methodName, item.getHandle(), null, error);
        }
    }
    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 {
            // 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);
        }
    }
    if (wi.getType() == SUBSCRIBE_REQUEST) {
        SubscribeRequestWorkItem item = (SubscribeRequestWorkItem) wi;
        SubscriptionParams params = item.getSubscriptionParams();
        Handle handle = item.getHandle();
        System.out.println("Subscribe Request User ID = " + params.getUserId());
        try {
            Subscription subscription = new Subscription(this, params);
            _subscriptions.put(subscription.getSubscriptionId(), subscription);
            _timer.schedule(subscription, 0, params.getPublishInterval());
            if (subscription == null) {
                System.out.println("Requested Subscription has already expired or been cancelled");
                QmfData error = new QmfData();
                error.setValue("error_text", "Requested Subscription has already expired or been cancelled");
                _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), null, 0, 0, error);
            } else {
                _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), subscription.getSubscriptionId(), subscription.getDuration(), subscription.getInterval(), null);
            }
        } catch (QmfException qmfe) {
            _agent.raiseException(handle, "Subscribe Request failed, invalid Query: " + qmfe.getMessage());
        }
    }
    if (wi.getType() == RESUBSCRIBE_REQUEST) {
        ResubscribeRequestWorkItem item = (ResubscribeRequestWorkItem) wi;
        ResubscribeParams params = item.getResubscribeParams();
        Handle handle = item.getHandle();
        System.out.println("Resubscribe Request User ID = " + params.getUserId());
        String subscriptionId = params.getSubscriptionId();
        Subscription subscription = _subscriptions.get(subscriptionId);
        if (subscription != null) {
            subscription.refresh(params);
            _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), subscription.getSubscriptionId(), subscription.getDuration(), subscription.getInterval(), null);
        } else {
            System.out.println("Requested Subscription has already expired or been cancelled");
            QmfData error = new QmfData();
            error.setValue("error_text", "Requested Subscription has already expired or been cancelled");
            _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), null, 0, 0, error);
        }
    }
    if (wi.getType() == UNSUBSCRIBE_REQUEST) {
        UnsubscribeRequestWorkItem item = (UnsubscribeRequestWorkItem) wi;
        String subscriptionId = item.getSubscriptionId();
        System.out.println("Received cancellation request for " + subscriptionId);
        Subscription subscription = _subscriptions.get(subscriptionId);
        if (subscription != null) {
            subscription.cancel();
        }
    }
}
Also used : MethodCallWorkItem(org.apache.qpid.qmf2.agent.MethodCallWorkItem) QmfData(org.apache.qpid.qmf2.common.QmfData) UnsubscribeRequestWorkItem(org.apache.qpid.qmf2.agent.UnsubscribeRequestWorkItem) ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfEvent(org.apache.qpid.qmf2.common.QmfEvent) SubscribeRequestWorkItem(org.apache.qpid.qmf2.agent.SubscribeRequestWorkItem) Handle(org.apache.qpid.qmf2.common.Handle) SubscriptionParams(org.apache.qpid.qmf2.agent.SubscriptionParams) ResubscribeParams(org.apache.qpid.qmf2.agent.ResubscribeParams) MethodCallParams(org.apache.qpid.qmf2.agent.MethodCallParams) QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData) QueryWorkItem(org.apache.qpid.qmf2.agent.QueryWorkItem) Subscription(org.apache.qpid.qmf2.agent.Subscription) QmfQuery(org.apache.qpid.qmf2.common.QmfQuery) ResubscribeRequestWorkItem(org.apache.qpid.qmf2.agent.ResubscribeRequestWorkItem) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 15 with QmfAgentData

use of org.apache.qpid.qmf2.agent.QmfAgentData in project qpid by apache.

the class QmfManagementAgent method childRemoved.

/**
     * ConfigurationChangeListener method called when a child ConfiguredObject is removed.
     * <p>
     * This method checks the type of the child ConfiguredObject that has been removed and raises the appropriate
     * QMF2 Events, it then destroys the QMF2 Management Object and removes the mapping between child and the QMF Object.
     *
     * @param object the parent object that the child is being removed from.
     * @param child the child object being removed.
     */
@Override
public void childRemoved(final ConfiguredObject object, final ConfiguredObject child) {
    if (_log.isDebugEnabled()) {
        _log.debug("childRemoved: " + child.getClass().getSimpleName() + "." + child.getName());
    }
    child.removeChangeListener(this);
    // Look up the associated QmfAgentData and mark it for deletion by the Agent.
    QmfAgentData data = _objects.get(child);
    if (data != null) {
        if (child instanceof Connection) {
            // Raise a Client Disconnect Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Connection) data).createClientDisconnectEvent());
        } else if (child instanceof Session) {
        // no-op, don't need to do anything specific when Session is removed.
        } else if (child instanceof Exchange) {
            // Raise an Exchange Delete Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Exchange) data).createExchangeDeleteEvent());
        } else if (child instanceof Queue) {
            // Raise a Queue Delete Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Queue) data).createQueueDeleteEvent());
        } else if (child instanceof Binding) {
            String eName = ((Binding) child).getExchange().getName();
            if (// Don't send Event for Unbinding from default direct.
            !eName.equals("<<default>>")) {
                // Raise an Unbind Event.
                _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Binding) data).createUnbindEvent());
            }
        } else if (child instanceof Consumer) {
            // Raise an Unsubscribe Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Subscription) data).createUnsubscribeEvent());
        }
        data.destroy();
    }
    // Remove the mapping from the internal ConfiguredObject->QmfAgentData Map.
    _objects.remove(child);
}
Also used : Binding(org.apache.qpid.server.model.Binding) Connection(org.apache.qpid.server.model.Connection) Exchange(org.apache.qpid.server.model.Exchange) Consumer(org.apache.qpid.server.model.Consumer) QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData) Queue(org.apache.qpid.server.model.Queue) Session(org.apache.qpid.server.model.Session)

Aggregations

QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)11 ObjectId (org.apache.qpid.qmf2.common.ObjectId)11 QmfException (org.apache.qpid.qmf2.common.QmfException)5 ArrayList (java.util.ArrayList)4 Queue (org.apache.qpid.server.model.Queue)4 MethodCallParams (org.apache.qpid.qmf2.agent.MethodCallParams)3 MethodCallWorkItem (org.apache.qpid.qmf2.agent.MethodCallWorkItem)3 QmfData (org.apache.qpid.qmf2.common.QmfData)3 QmfQuery (org.apache.qpid.qmf2.common.QmfQuery)3 SchemaClass (org.apache.qpid.qmf2.common.SchemaClass)3 SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)3 Binding (org.apache.qpid.server.model.Binding)3 Exchange (org.apache.qpid.server.model.Exchange)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Subscription (org.apache.qpid.qmf2.agent.Subscription)2 QmfEvent (org.apache.qpid.qmf2.common.QmfEvent)2 SchemaObjectClass (org.apache.qpid.qmf2.common.SchemaObjectClass)2 Broker (org.apache.qpid.server.model.Broker)2 Connection (org.apache.qpid.server.model.Connection)2