/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.qpid.qmf2.common; import java.util.HashMap; import java.util.Map; // QMF2 Imports import org.apache.qpid.qmf2.console.Agent; /** * Descriptions below are taken from QMF2 API Proposal *
* A WorkItem describes an event that has arrived for the application to process. *
* The Notifier is invoked when one or more WorkItems become available for processing. *
* The type of the Object returned by getParams is determined by the WorkItemType and described below. *
* *
WorkItem Type | Description |
---|---|
AGENT_ADDED: | *
* When the QMF Console receives the first heartbeat from an Agent, an AGENT_ADDED WorkItem is pushed onto the
* work-queue.
* * The getParams() method returns a map which contains a reference to the new Console Agent instance. The reference is * indexed from the map using the key string "agent". There is no handle associated with this WorkItem. * * Note: If a new Agent is discovered as a result of the Console findAgent() method, then no AGENT_ADDED WorkItem is * generated for that Agent. * * Use AgentAddedWorkItem to enable neater access. * |
*
AGENT_DELETED: | *
* When a known Agent stops sending heartbeat messages the Console will time out that Agent. On Agent timeout, an
* AGENT_DELETED WorkItem is pushed onto the work-queue.
* * The getParams() method returns a map which contains a reference to the Agent instance that has been deleted. * The reference is indexed from the map using the key string "agent". There is no handle associated with this WorkItem. * * The Console application must release all saved references to the Agent before returning the WorkItem. * * Use AgentDeletedWorkItem to enable neater access. * |
*
AGENT_RESTARTED: | *
* Sent when the QMF Console detects an Agent was restarted, an AGENT_RESTARTED WorkItem is pushed onto the work-queue.
* * The getParams() method returns a map which contains a reference to the Console Agent instance. The reference * is indexed from the map using the key string "agent". There is no handle associated with this WorkItem. * * Use AgentRestartedWorkItem to enable neater access. * |
*
AGENT_HEARTBEAT: | *
* When the QMF Console receives heartbeats from an Agent, an AGENT_HEARTBEAT WorkItem is pushed onto the work-queue.
* * The getParams() method returns a map which contains a reference to the Console Agent instance. The reference * is indexed from the map using the key string "agent". There is no handle associated with this WorkItem. * * Note: the first heartbeat results in an AGENT_ADDED WorkItem for Agent not an AGENT_HEARTBEAT. * * Use AgentHeartbeatWorkItem to enable neater access. * |
*
NEW_PACKAGE: | TBD | *
NEW_CLASS: | TBD | *
OBJECT_UPDATE: | *
* The OBJECT_UPDATE WorkItem is generated in response to an asynchronous refresh made by a QmfConsoleData object.
* * The getParams() method will return a QmfConsoleData. * * The getHandle() method returns the reply handle provided to the refresh() method call. * This handle is merely the handle used for the asynchronous response, it is not associated with the QmfConsoleData * in any other way. * * Use ObjectUpdateWorkItem to enable neater access. * |
*
METHOD_RESPONSE: | *
* The METHOD_RESPONSE WorkItem is generated in response to an asynchronous invokeMethod made by a QmfConsoleData object.
* * The getParams() method will return a MethodResult object. * * The getHandle() method returns the reply handle provided to the refresh() method call. * This handle is merely the handle used for the asynchronous response, it is not associated with the QmfConsoleData * in any other way. * * Use MethodResponseWorkItem to enable neater access. * |
*
EVENT_RECEIVED: | *
* When an Agent generates a QmfEvent an EVENT_RECEIVED WorkItem is pushed onto the work-queue.
* * The getParams() method returns a map which contains a reference to the Console Agent instance that generated * the Event and a reference to the QmfEvent itself. The Agent reference is indexed from the map using the key string * "agent, The QmfEvent reference is indexed from the map using the key string "event". There is no handle associated * with this WorkItem. * * Use EventReceivedWorkItem to enable neater access. * |
*
SUBSCRIBE_RESPONSE: | *
* The SUBSCRIBE_RESPONSE WorkItem returns the result of a subscription request made by this Console. This WorkItem is
* generated when the Console's createSubscription() is called in an asychronous manner, rather than pending for the result.
* * The getParams() method will return an instance of the SubscribeParams class. * * The SubscriptionId object must be used when the subscription is refreshed or cancelled. It must be passed to the * Console's refresh_subscription() and cancelSubscription() methods. The value of the SubscriptionId does not change * over the lifetime of the subscription. * * The console handle will be provided by the Agent on each data indication event that corresponds to this subscription. * It should not change for the lifetime of the subscription. * * The getHandle() method returns the reply handle provided to the createSubscription() method call. This handle is * merely the handle used for the asynchronous response, it is not associated with the subscription in any other way. * * Once a subscription is created, the Agent that maintains the subscription will periodically issue updates for the * subscribed data. This update will contain the current values of the subscribed data, and will appear as the first * SUBSCRIPTION_INDICATION WorkItem for this subscription. * * Use SubscribeResponseWorkItem to enable neater access. * |
*
SUBSCRIPTION_INDICATION: | *
* The SUBSCRIPTION_INDICATION WorkItem signals the arrival of an update to subscribed data from the Agent.
* * The getParams() method will return an instance of the SubscribeIndication class. * The getHandle() method returns null. * * Use SubscriptionIndicationWorkItem to enable neater access. * |
*
RESUBSCRIBE_RESPONSE: | *
* The RESUBSCRIBE_RESPONSE WorkItem is generated in response to a subscription refresh request made by this Console.
* This WorkItem is generated when the Console's refreshSubscription() is called in an asychronous manner, rather than
* pending for the result.
* * The getParams() method will return an instance of the SubscribeParams class. * * The getHandle() method returns the reply handle provided to the refreshSubscription() method call. This handle is * merely the handle used for the asynchronous response, it is not associated with the subscription in any other way. * * Use ResubscribeResponseWorkItem to enable neater access. * |
*
METHOD_CALL: | *
* The METHOD_CALL WorkItem describes a method call that must be serviced by the application on behalf of this Agent.
* * The getParams() method will return an instance of the MethodCallParams class. * * Use MethodCallWorkItem to enable neater access. * |
*
QUERY: | *
* The QUERY WorkItem describes a query that the application must service. The application should call the
* queryResponse() method for each object that satisfies the query. When complete, the application must call the
* queryComplete() method. If a failure occurs, the application should indicate the error to the agent by calling
* the query_complete() method with a description of the error.
* * The getParams() method will return an instance of the QmfQuery class. * * The getHandle() WorkItem method returns the reply handle which should be passed to the Agent's queryResponse() * and queryComplete() methods. * * Use QueryWorkItem to enable neater access. * |
*
SUBSCRIBE_REQUEST: | *
* The SUBSCRIBE_REQUEST WorkItem provides a query that the agent application must periodically publish until the
* subscription is cancelled or expires. On receipt of this WorkItem, the application should call the Agent
* subscriptionResponse() method to acknowledge the request. On each publish interval, the application should call Agent
* subscriptionIndicate(), passing a list of the objects that satisfy the query. The subscription remains in effect until
* an UNSUBSCRIBE_REQUEST WorkItem for the subscription is received, or the subscription expires.
* * The getParams() method will return an instance of the SubscriptionParams class. * * The getHandle() WorkItem method returns the reply handle which should be passed to the Agent's * subscriptionResponse() method. * * Use SubscribeRequestWorkItem to enable neater access. * |
*
RESUBSCRIBE_REQUEST: | *
* The RESUBSCRIBE_REQUEST is sent by a Console to renew an existing subscription. The Console may request a new
* duration for the subscription, otherwise the previous lifetime interval is repeated.
* * The getParams() method will return an instance of the ResubscribeParams class. * * The getHandle() WorkItem method returns the reply handle which should be passed to the Agent's * subscriptionResponse() method. * * Use ResubscribeRequestWorkItem to enable neater access. * |
*
UNSUBSCRIBE_REQUEST: | *
* The UNSUBSCRIBE_REQUEST is sent by a Console to terminate an existing subscription. The Agent application should
* terminate the given subscription if it exists, and cancel sending any further updates against it.
* * The getParams() method will return a String holding the subscriptionId. * * The getHandle() method returns null. * * Use UnsubscribeRequestWorkItem to enable neater access. * |
*
* The following diagram illustrates the QMF2 WorkItem class hierarchy. *
* * @author Fraser Adams */ public class WorkItem { /** * An Enumeration of the types of WorkItems produced on the Console or Agent. */ public enum WorkItemType { // Enumeration of the types of WorkItems produced on the Console AGENT_ADDED, AGENT_DELETED, AGENT_RESTARTED, AGENT_HEARTBEAT, NEW_PACKAGE, NEW_CLASS, OBJECT_UPDATE, EVENT_RECEIVED, METHOD_RESPONSE, SUBSCRIBE_RESPONSE, SUBSCRIPTION_INDICATION, RESUBSCRIBE_RESPONSE, // Enumeration of the types of WorkItems produced on the Agent METHOD_CALL, QUERY, SUBSCRIBE_REQUEST, RESUBSCRIBE_REQUEST, UNSUBSCRIBE_REQUEST; } private final WorkItemType _type; private final Handle _handle; private final Object _params; /** * Construct a WorkItem * * @param type the type of WorkItem specified by the WorkItemType enum * @param handle the handle passed by async calls - the correlation ID * @param params the payload of the WorkItem */ public WorkItem(WorkItemType type, Handle handle, Object params) { _type = type; _handle = handle; _params = params; } /** * Return the type of work item. * @return the type of work item. */ public final WorkItemType getType() { return _type; } /** * Return the reply handle for an asynchronous operation, if present. * @return the reply handle for an asynchronous operation, if present. */ public final Handle getHandle() { return _handle; } /** * Return the payload of the work item. * @return the payload of the work item. *
* The type of this object is determined by the type of the workitem as follows: *
* Console * AGENT_ADDED: Map{"agent":Agent} - Use AgentAddedWorkItem to enable neater access * AGENT_DELETED: Map{"agent":Agent} - Use AgentDeletedWorkItem to enable neater access * AGENT_RESTARTED: Map{"agent":Agent} - Use AgentRestartedWorkItem to enable neater access * AGENT_HEARTBEAT: Map{"agent":Agent} - Use AgentHeartbeatWorkItem to enable neater access * OBJECT_UPDATE: QmfConsoleData - Use ObjectUpdateWorkItem to enable neater access * METHOD_RESPONSE: MethodResult - Use MethodResponseWorkItem to enable neater access * EVENT_RECEIVED: Map{"agent":Agent, "event":QmfEvent} - Use EventReceivedWorkItem to enable neater access * SUBSCRIBE_RESPONSE: SubscribeParams - Use SubscribeResponseWorkItem to enable neater access * SUBSCRIPTION_INDICATION: SubscribeIndication - Use SubscriptionIndicationWorkItem to enable neater access * RESUBSCRIBE_RESPONSE: SubscribeParams - Use ResubscribeResponseWorkItem to enable neater access * * Agent * METHOD_CALL: MethodCallParams - Use MethodCallWorkItem to enable neater access * QUERY: QmfQuery - Use QueryWorkItem to enable neater access * SUBSCRIBE_REQUEST: SubscriptionParams - Use SubscribeRequestWorkItem to enable neater access * RESUBSCRIBE_REQUEST: ResubscribeParams - Use ResubscribeRequestWorkItem to enable neater access * UNSUBSCRIBE_REQUEST: String (subscriptionId) - Use UnsubscribeRequestWorkItem to enable neater access **/ @SuppressWarnings("unchecked") public final