Search in sources :

Example 16 with QmfConsoleData

use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.

the class QpidConfig method exchangeList.

/**
 * For every exchange list detailed info (equivalent of qpid-config exchanges).
 *
 * More or less a direct Java port of ExchangeList in qpid-config, which handles qpid-config exchanges.
 *
 * @param filter specifies the exchange name to display info for, if set to "" displays info for every exchange.
 */
private void exchangeList(final String filter) {
    List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
    String caption1 = "Type      ";
    String caption2 = "Exchange Name";
    int maxNameLen = caption2.length();
    for (QmfConsoleData exchange : exchanges) {
        String name = exchange.getStringValue("name");
        if (filter.equals("") || filter.equals(name)) {
            if (name.length() > maxNameLen) {
                maxNameLen = name.length();
            }
        }
    }
    System.out.printf("%s%-" + maxNameLen + "s Attributes\n", caption1, caption2);
    StringBuilder buf = new StringBuilder();
    for (int i = 0; i < (((maxNameLen + caption1.length()) / 5) + 5); i++) {
        buf.append("=====");
    }
    String line = buf.toString();
    System.out.println(line);
    for (QmfConsoleData exchange : exchanges) {
        String name = exchange.getStringValue("name");
        if (filter.equals("") || filter.equals(name)) {
            System.out.printf("%-10s%-" + maxNameLen + "s ", exchange.getStringValue("type"), name);
            Map args = (Map) exchange.getValue("arguments");
            args = (args == null) ? Collections.EMPTY_MAP : args;
            if (exchange.getBooleanValue("durable")) {
                System.out.printf("--durable ");
            }
            if (args.containsKey(MSG_SEQUENCE) && QmfData.getLong(args.get(MSG_SEQUENCE)) == 1) {
                System.out.printf("--sequence ");
            }
            if (args.containsKey(IVE) && QmfData.getLong(args.get(IVE)) == 1) {
                System.out.printf("--ive ");
            }
            if (exchange.hasValue("altExchange")) {
                ObjectId altExchangeRef = exchange.getRefValue("altExchange");
                QmfConsoleData altExchange = findById(exchanges, altExchangeRef);
                if (altExchange != null) {
                    System.out.printf("--alternate-exchange=%s", altExchange.getStringValue("name"));
                }
            }
            System.out.println();
        }
    }
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with QmfConsoleData

use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.

the class AgentSubscriptionTestConsole method onEvent.

public void onEvent(WorkItem wi) {
    System.out.println("WorkItem type: " + wi.getType());
    if (wi.getType() == AGENT_HEARTBEAT) {
        AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem) wi;
        Agent agent = item.getAgent();
        System.out.println(agent.getName());
    }
    if (wi.getType() == EVENT_RECEIVED) {
        EventReceivedWorkItem item = (EventReceivedWorkItem) wi;
        Agent agent = item.getAgent();
        QmfEvent event = item.getEvent();
        String className = event.getSchemaClassId().getClassName();
        System.out.println("Event: " + className);
    // event.listValues();
    }
    if (wi.getType() == METHOD_RESPONSE) {
        MethodResponseWorkItem item = (MethodResponseWorkItem) wi;
        MethodResult result = item.getMethodResult();
        String correlationId = item.getHandle().getCorrelationId();
        System.out.println("correlationId = " + correlationId);
        System.out.println(result.getStringValue("message"));
    }
    if (wi.getType() == OBJECT_UPDATE) {
        ObjectUpdateWorkItem item = (ObjectUpdateWorkItem) wi;
        QmfConsoleData object = item.getQmfConsoleData();
        ObjectId objectId = object.getObjectId();
        String correlationId = item.getHandle().getCorrelationId();
        System.out.println("correlationId = " + correlationId);
        System.out.println("objectId = " + objectId);
        System.out.println("MethodCount = " + object.getLongValue("methodCount"));
    }
    if (wi.getType() == SUBSCRIBE_RESPONSE) {
        SubscribeResponseWorkItem item = (SubscribeResponseWorkItem) wi;
        SubscribeParams params = item.getSubscribeParams();
        System.out.println("duration = " + params.getLifetime());
        System.out.println("interval = " + params.getPublishInterval());
        System.out.println("subscriptionId = " + params.getSubscriptionId());
        System.out.println("consoleHandle = " + params.getConsoleHandle());
        String correlationId = item.getHandle().getCorrelationId();
        System.out.println("correlationId = " + correlationId);
    }
    if (wi.getType() == SUBSCRIPTION_INDICATION) {
        SubscriptionIndicationWorkItem item = (SubscriptionIndicationWorkItem) wi;
        SubscribeIndication indication = item.getSubscribeIndication();
        String correlationId = indication.getConsoleHandle();
        System.out.println("correlationId = " + correlationId);
        List<QmfConsoleData> objects = indication.getData();
        for (QmfConsoleData object : objects) {
            if (object.isDeleted()) {
                System.out.println("object has been deleted");
            }
            System.out.println("offset = " + object.getValue("offset"));
        }
    }
}
Also used : Agent(org.apache.qpid.qmf2.console.Agent) SubscriptionIndicationWorkItem(org.apache.qpid.qmf2.console.SubscriptionIndicationWorkItem) ObjectId(org.apache.qpid.qmf2.common.ObjectId) AgentHeartbeatWorkItem(org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem) EventReceivedWorkItem(org.apache.qpid.qmf2.console.EventReceivedWorkItem) QmfEvent(org.apache.qpid.qmf2.common.QmfEvent) MethodResponseWorkItem(org.apache.qpid.qmf2.console.MethodResponseWorkItem) SubscribeIndication(org.apache.qpid.qmf2.console.SubscribeIndication) ObjectUpdateWorkItem(org.apache.qpid.qmf2.console.ObjectUpdateWorkItem) SubscribeParams(org.apache.qpid.qmf2.console.SubscribeParams) SubscribeResponseWorkItem(org.apache.qpid.qmf2.console.SubscribeResponseWorkItem) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) MethodResult(org.apache.qpid.qmf2.console.MethodResult)

Example 18 with QmfConsoleData

use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.

the class AgentTestConsole method onEvent.

public void onEvent(WorkItem wi) {
    System.out.println("WorkItem type: " + wi.getType());
    if (wi.getType() == AGENT_ADDED) {
        AgentAddedWorkItem item = (AgentAddedWorkItem) wi;
        Agent agent = item.getAgent();
        // If this is the gizmo Agent we notify the main thread so processing can continue.
        if (agent.getProduct().equals("gizmo")) {
            synchronized (this) {
                _gizmo = agent;
                notify();
            }
        }
    }
    if (wi.getType() == AGENT_HEARTBEAT) {
        AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem) wi;
        Agent agent = item.getAgent();
        System.out.println(agent.getName());
    }
    if (wi.getType() == EVENT_RECEIVED) {
        EventReceivedWorkItem item = (EventReceivedWorkItem) wi;
        Agent agent = item.getAgent();
        QmfEvent event = item.getEvent();
        String className = event.getSchemaClassId().getClassName();
        System.out.println("Event: " + className);
    // event.listValues();
    }
    if (wi.getType() == METHOD_RESPONSE) {
        MethodResponseWorkItem item = (MethodResponseWorkItem) wi;
        MethodResult result = item.getMethodResult();
        String correlationId = item.getHandle().getCorrelationId();
        System.out.println("correlationId = " + correlationId);
        System.out.println(result.getStringValue("message"));
    }
    if (wi.getType() == OBJECT_UPDATE) {
        ObjectUpdateWorkItem item = (ObjectUpdateWorkItem) wi;
        QmfConsoleData object = item.getQmfConsoleData();
        ObjectId objectId = object.getObjectId();
        String correlationId = item.getHandle().getCorrelationId();
        System.out.println("correlationId = " + correlationId);
        System.out.println("objectId = " + objectId);
        System.out.println("MethodCount = " + object.getLongValue("methodCount"));
    }
}
Also used : Agent(org.apache.qpid.qmf2.console.Agent) ObjectUpdateWorkItem(org.apache.qpid.qmf2.console.ObjectUpdateWorkItem) ObjectId(org.apache.qpid.qmf2.common.ObjectId) AgentHeartbeatWorkItem(org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem) EventReceivedWorkItem(org.apache.qpid.qmf2.console.EventReceivedWorkItem) QmfEvent(org.apache.qpid.qmf2.common.QmfEvent) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) AgentAddedWorkItem(org.apache.qpid.qmf2.console.AgentAddedWorkItem) MethodResponseWorkItem(org.apache.qpid.qmf2.console.MethodResponseWorkItem) MethodResult(org.apache.qpid.qmf2.console.MethodResult)

Example 19 with QmfConsoleData

use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.

the class ConnectionAudit method checkExistingSubscriptions.

/**
 * When we start up we need to check any subscriptions that already exist against the whitelist.
 * Subsequent checks are made only when we receive new subscribe events.
 */
private void checkExistingSubscriptions() {
    readWhitelist();
    List<QmfConsoleData> subscriptions = _console.getObjects("org.apache.qpid.broker", "subscription");
    for (QmfConsoleData subscription : subscriptions) {
        QmfConsoleData queue = dereference(subscription.getRefValue("queueRef"));
        QmfConsoleData session = dereference(subscription.getRefValue("sessionRef"));
        QmfConsoleData connection = dereference(session.getRefValue("connectionRef"));
        String queueName = queue.getStringValue("name");
        String address = connection.getStringValue("address");
        String timestamp = new Date(subscription.getCreateTime() / 1000000l).toString();
        validateQueue(queueName, address, timestamp);
    }
}
Also used : QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) Date(java.util.Date)

Example 20 with QmfConsoleData

use of org.apache.qpid.qmf2.console.QmfConsoleData in project qpid by apache.

the class ConnectionLogger method logConnectionInformation.

/**
 * Logs audit information about each connection made to the broker
 *
 * Obtains connection, session and subscription objects and iterates in turn through these comparing
 * references to find the subscriptions association with sessions and sessions associated with
 * connections. Ultimately it then uses logQueueInformation to display the queues associated with
 * each subscription.
 */
private void logConnectionInformation() {
    System.out.println("\n\n**** ConnectionLogger: Logging current connection information ****");
    List<QmfConsoleData> connections = _console.getObjects("org.apache.qpid.broker", "connection");
    List<QmfConsoleData> sessions = _console.getObjects("org.apache.qpid.broker", "session");
    List<QmfConsoleData> subscriptions = _console.getObjects("org.apache.qpid.broker", "subscription");
    for (QmfConsoleData connection : connections) {
        System.out.printf("\nConnection '%s'\n", connection.getStringValue("address"));
        String[] properties = { "authIdentity", "remoteProcessName", "federationLink" };
        for (String p : properties) {
            System.out.println(p + ": " + connection.getStringValue(p));
        }
        System.out.println("createTimestamp: " + new Date(connection.getCreateTime() / 1000000l));
        ObjectId connectionId = connection.getObjectId();
        for (QmfConsoleData session : sessions) {
            // Iterate through all session objects
            ObjectId connectionRef = session.getRefValue("connectionRef");
            if (connectionRef.equals(connectionId)) {
                // But only select sessions that are associated with the connection under consideration.
                System.out.printf("Session '%s'\n", session.getStringValue("name"));
                int subscriptionCount = 0;
                ObjectId sessionId = session.getObjectId();
                for (QmfConsoleData subscription : subscriptions) {
                    // Iterate through all subscription objects
                    ObjectId sessionRef = subscription.getRefValue("sessionRef");
                    if (sessionRef.equals(sessionId)) {
                        // But only select subscriptions that are associated with the session under consideration.
                        subscriptionCount++;
                        ObjectId queueRef = subscription.getRefValue("queueRef");
                        if (_logQueues) {
                            logQueueInformation(queueRef);
                        }
                    }
                }
                if (subscriptionCount == 0) {
                    System.out.println("    ** No Subscriptions for this Session - probably a producer only Session **");
                }
            }
        }
    }
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) Date(java.util.Date)

Aggregations

QmfConsoleData (org.apache.qpid.qmf2.console.QmfConsoleData)20 ObjectId (org.apache.qpid.qmf2.common.ObjectId)16 Map (java.util.Map)11 HashMap (java.util.HashMap)10 QmfException (org.apache.qpid.qmf2.common.QmfException)5 Agent (org.apache.qpid.qmf2.console.Agent)5 Date (java.util.Date)4 QmfData (org.apache.qpid.qmf2.common.QmfData)4 QmfEvent (org.apache.qpid.qmf2.common.QmfEvent)4 SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)4 AgentHeartbeatWorkItem (org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem)4 MethodResult (org.apache.qpid.qmf2.console.MethodResult)4 ArrayList (java.util.ArrayList)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 EventReceivedWorkItem (org.apache.qpid.qmf2.console.EventReceivedWorkItem)3 MethodResponseWorkItem (org.apache.qpid.qmf2.console.MethodResponseWorkItem)3 ObjectUpdateWorkItem (org.apache.qpid.qmf2.console.ObjectUpdateWorkItem)3 SubscribeIndication (org.apache.qpid.qmf2.console.SubscribeIndication)3 SubscriptionIndicationWorkItem (org.apache.qpid.qmf2.console.SubscriptionIndicationWorkItem)3 IOException (java.io.IOException)2