Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation |
00001 #ifndef _qpid_agent_ManagementAgent_ 00002 #define _qpid_agent_ManagementAgent_ 00003 00004 // 00005 // Licensed to the Apache Software Foundation (ASF) under one 00006 // or more contributor license agreements. See the NOTICE file 00007 // distributed with this work for additional information 00008 // regarding copyright ownership. The ASF licenses this file 00009 // to you under the Apache License, Version 2.0 (the 00010 // "License"); you may not use this file except in compliance 00011 // with the License. You may obtain a copy of the License at 00012 // 00013 // http://www.apache.org/licenses/LICENSE-2.0 00014 // 00015 // Unless required by applicable law or agreed to in writing, 00016 // software distributed under the License is distributed on an 00017 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00018 // KIND, either express or implied. See the License for the 00019 // specific language governing permissions and limitations 00020 // under the License. 00021 // 00022 00023 #include "qpid/agent/QmfAgentImportExport.h" 00024 #include "qpid/management/ManagementObject.h" 00025 #include "qpid/management/ManagementEvent.h" 00026 #include "qpid/management/Manageable.h" 00027 #include "qpid/management/ConnectionSettings.h" 00028 00029 namespace qpid { 00030 namespace management { 00031 00032 class Notifyable { 00033 public: 00034 virtual ~Notifyable() {} 00035 virtual void notify() = 0; 00036 }; 00037 00038 class ManagementAgent 00039 { 00040 public: 00041 00042 class Singleton { 00043 public: 00044 QMF_AGENT_EXTERN Singleton(bool disableManagement = false); 00045 QMF_AGENT_EXTERN ~Singleton(); 00046 QMF_AGENT_EXTERN static ManagementAgent* getInstance(); 00047 }; 00048 00049 typedef enum { 00050 SEV_EMERG = 0, 00051 SEV_ALERT = 1, 00052 SEV_CRIT = 2, 00053 SEV_ERROR = 3, 00054 SEV_WARN = 4, 00055 SEV_NOTE = 5, 00056 SEV_INFO = 6, 00057 SEV_DEBUG = 7, 00058 SEV_DEFAULT = 8 00059 } severity_t; 00060 00061 ManagementAgent() {} 00062 virtual ~ManagementAgent() {} 00063 00064 virtual int getMaxThreads() = 0; 00065 00066 // Set the name of the agent 00067 // 00068 // vendor - Vendor name or domain (i.e. "apache.org") 00069 // product - Product name (i.e. "qpid") 00070 // instance - A unique identifier for this instance of the agent. 00071 // If empty, the agent will create a GUID for the instance. 00072 // 00073 virtual void setName(const std::string& vendor, 00074 const std::string& product, 00075 const std::string& instance="") = 0; 00076 00077 // Connect to a management broker 00078 // 00079 // brokerHost - Hostname or IP address (dotted-quad) of broker. 00080 // 00081 // brokerPort - TCP port of broker. 00082 // 00083 // intervalSeconds - The interval (in seconds) that this agent shall use 00084 // between broadcast updates to the broker. 00085 // 00086 // useExternalThread - If true, the thread of control used for callbacks 00087 // must be supplied by the user of the object (via the 00088 // pollCallbacks method). 00089 // 00090 // If false, callbacks shall be invoked on the management 00091 // agent's thread. In this case, the callback implementations 00092 // MUST be thread safe. 00093 // 00094 // storeFile - File where this process has read and write access. This 00095 // file shall be used to store persistent state. 00096 // 00097 virtual void init(const std::string& brokerHost = "localhost", 00098 uint16_t brokerPort = 5672, 00099 uint16_t intervalSeconds = 10, 00100 bool useExternalThread = false, 00101 const std::string& storeFile = "", 00102 const std::string& uid = "guest", 00103 const std::string& pwd = "guest", 00104 const std::string& mech = "PLAIN", 00105 const std::string& proto = "tcp") = 0; 00106 00107 virtual void init(const management::ConnectionSettings& settings, 00108 uint16_t intervalSeconds = 10, 00109 bool useExternalThread = false, 00110 const std::string& storeFile = "") = 0; 00111 00112 00113 // Register a schema with the management agent. This is normally called by the 00114 // package initializer generated by the management code generator. 00115 // 00116 virtual void 00117 registerClass(const std::string& packageName, 00118 const std::string& className, 00119 uint8_t* md5Sum, 00120 management::ManagementObject::writeSchemaCall_t schemaCall) = 0; 00121 00122 virtual void 00123 registerEvent(const std::string& packageName, 00124 const std::string& eventName, 00125 uint8_t* md5Sum, 00126 management::ManagementEvent::writeSchemaCall_t schemaCall) = 0; 00127 00128 // Add a management object to the agent. Once added, this object shall be visible 00129 // in the greater management context. 00130 // 00131 // Please note that ManagementObject instances are not explicitly deleted from 00132 // the management agent. When the core object represented by a management object 00133 // is deleted, the "resourceDestroy" method on the management object must be called. 00134 // It will then be reclaimed in due course by the management agent. 00135 // 00136 // Once a ManagementObject instance is added to the agent, the agent then owns the 00137 // instance. The caller MUST NOT free the resources of the instance at any time. 00138 // When it is no longer needed, invoke its "resourceDestroy" method and discard the 00139 // pointer. This allows the management agent to report the deletion of the object 00140 // in an orderly way. 00141 // 00142 virtual ObjectId addObject(ManagementObject* objectPtr, uint64_t persistId = 0) = 0; 00143 virtual ObjectId addObject(ManagementObject* objectPtr, 00144 const std::string& key, 00145 bool persistent = true) = 0; 00146 00147 // 00148 // 00149 virtual void raiseEvent(const ManagementEvent& event, 00150 severity_t severity = SEV_DEFAULT) = 0; 00151 00152 // If "useExternalThread" was set to true in init, this method must 00153 // be called to provide a thread for any pending method calls that have arrived. 00154 // The method calls for ManagementObject instances shall be invoked synchronously 00155 // during the execution of this method. 00156 // 00157 // callLimit may optionally be used to limit the number of callbacks invoked. 00158 // if 0, no limit is imposed. 00159 // 00160 // The return value is the number of callbacks that remain queued after this 00161 // call is complete. It can be used to determine whether or not further calls 00162 // to pollCallbacks are necessary to clear the backlog. If callLimit is zero, 00163 // the return value will also be zero. 00164 // 00165 virtual uint32_t pollCallbacks(uint32_t callLimit = 0) = 0; 00166 00167 // In the "useExternalThread" scenario, there are three ways that an application can 00168 // use to be notified that there is work to do. Of course the application may periodically 00169 // call pollCallbacks if it wishes, but this will cause long latencies in the responses 00170 // to method calls. 00171 // 00172 // The notification methods are: 00173 // 00174 // 1) Register a C-style callback by providing a pointer to a function 00175 // 2) Register a C++-style callback by providing an object of a class that is derived 00176 // from Notifyable 00177 // 3) Call getSignalFd() to get a file descriptor that can be used in a select 00178 // call. The file descriptor shall become readable when the agent has work to 00179 // do. Note that this mechanism is specific to Posix-based operating environments. 00180 // getSignalFd will probably not function correctly on Windows. 00181 // 00182 // If a callback is registered, the callback function will be called on the agent's 00183 // thread. The callback function must perform no work other than to signal the application 00184 // thread to call pollCallbacks. 00185 // 00186 typedef void (*cb_t)(void*); 00187 virtual void setSignalCallback(cb_t callback, void* context) = 0; 00188 virtual void setSignalCallback(Notifyable& notifyable) = 0; 00189 virtual int getSignalFd() = 0; 00190 }; 00191 00192 }} 00193 00194 #endif