Go to the documentation of this file.00001 #ifndef _ACS_NOTIFICATION_SERVICE_IMP_HANDLER_IMPL_H_
00002 #define _ACS_NOTIFICATION_SERVICE_IMP_HANDLER_IMPL_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __cplusplus
00032 #error This is a C++ include file and cannot be used from plain C
00033 #endif
00034
00035 #include "acsImpBaseHandlerImpl.h"
00036 #include "acsNotificationServiceMonitor.h"
00037
00038 #include <map>
00039
00040 typedef std::map<ACSServiceRequestDescription*, NotificationServiceMonitor*> MonitorMap;
00041
00042 class ACSNotificationServiceImpHandlerImpl : public ACSImpBaseHandlerImpl<ACSNotificationServiceImpHandlerImpl>, public POA_acsdaemon::NotificationServiceImp {
00043 private:
00044 MonitorMap monitorMap;
00045 int intervalCount;
00046 public:
00047
00048 ACSNotificationServiceImpHandlerImpl() : ACSImpBaseHandlerImpl<ACSNotificationServiceImpHandlerImpl>(NOTIFICATION_SERVICE) {}
00049
00050 virtual ~ACSNotificationServiceImpHandlerImpl()
00051 {
00052 MonitorMap::iterator iter = monitorMap.begin();
00053 for (; iter != monitorMap.end(); iter++)
00054 {
00055 NotificationServiceMonitor* nsm = iter->second;
00056 nsm->destroy();
00057 delete nsm;
00058 }
00059 }
00060
00061
00062
00063 void start_notification_service (
00064 const char * name,
00065 acsdaemon::DaemonCallback_ptr callback,
00066 CORBA::Short instance_number) throw(ACSErrTypeCommon::BadParameterEx, acsdaemonErrType::ServiceAlreadyRunningEx) {
00067 if (name != NULL && strlen(name) == 0) name = NULL;
00068 ACS_SHORT_LOG ((LM_INFO, "Starting '%s' Notification Service on Imp (instance %d).", name == NULL ? "default" : name, instance_number));
00069 ACSServiceRequestDescription *desc = new ACSServiceRequestDescription(NOTIFICATION_SERVICE, instance_number);
00070 desc->setName(name);
00071 #define NOTIFY_FACTORY_NAME_STRING "NotifyEventChannelFactory"
00072
00073 if (name != NULL) {
00074 int lendiff = (int)strlen(name) - strlen(NOTIFY_FACTORY_NAME_STRING);
00075 if (lendiff < 0 || strcmp(name + lendiff, NOTIFY_FACTORY_NAME_STRING) != 0)
00076 desc->setCorbalocName((ACE_CString(name) + NOTIFY_FACTORY_NAME_STRING).c_str());
00077
00078 }
00079 context->processRequest(LOCAL, START_SERVICE, desc, callback);
00080 }
00081
00082 void stop_notification_service (
00083 const char * name,
00084 acsdaemon::DaemonCallback_ptr callback,
00085 CORBA::Short instance_number) throw(ACSErrTypeCommon::BadParameterEx, acsdaemonErrType::ServiceNotRunningEx) {
00086 if (name != NULL && strlen(name) == 0) name = NULL;
00087 ACS_SHORT_LOG ((LM_INFO, "Stopping '%s' Notification Service on Imp (instance %d).", name == NULL ? "default" : name, instance_number));
00088 ACSServiceRequestDescription *desc = new ACSServiceRequestDescription(NOTIFICATION_SERVICE, instance_number);
00089 desc->setName(name);
00090 context->processRequest(LOCAL, STOP_SERVICE, desc, callback);
00091 }
00092
00093 acsdaemon::ServiceState get_service_status(const char * name, CORBA::Short instance_number) throw(ACSErrTypeCommon::BadParameterEx) {
00094 return context->getACSServiceState(instance_number, name);
00095 }
00096
00097 virtual acsdaemon::ServiceState getDetailedServiceState(ACSServiceRequestDescription *desc, CORBA::Object_ptr obj) {
00098
00099
00100 if (obj == 0)
00101 {
00102 if (monitorMap.find(desc) != monitorMap.end())
00103 {
00104 NotificationServiceMonitor* nsm = monitorMap[desc];
00105 nsm->destroy();
00106 monitorMap.erase(desc);
00107 delete nsm;
00108 }
00109 return acsdaemon::DEFUNCT;
00110 }
00111
00112 bool isRightNCType = obj->_is_a("IDL:sandia.gov/NotifyMonitoringExt/EventChannelFactory:1.0");
00113 if (!isRightNCType) {
00114 ACS_SHORT_LOG((LM_ERROR, "%s does not extend required interface, reported as defunctional.", desc->getName()));
00115 return acsdaemon::DEFUNCT;
00116 }
00117
00118 if (monitorMap.find(desc) == monitorMap.end())
00119 {
00120 CosNotifyChannelAdmin::EventChannelFactory_var ecf = CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj);
00121 NotificationServiceMonitor* nsm = new NotificationServiceMonitor(ecf.in());
00122 nsm->init();
00123 monitorMap[desc] = nsm;
00124 nsm->issuePingEvent();
00125 return acsdaemon::RUNNING;
00126 }
00127 else
00128 {
00129 NotificationServiceMonitor* nsm = monitorMap[desc];
00130 CORBA::ULongLong rtt = nsm->getAndResetRTT();
00131 nsm->issuePingEvent();
00132 if (rtt < 0) {
00133 ACS_SHORT_LOG((LM_ERROR, "%s is not responsive, reported as defunctional.", desc->getName()));
00134 return acsdaemon::DEFUNCT;
00135 }
00136 else if (rtt > 200000) {
00137 ACS_SHORT_LOG((LM_WARNING, "%s response time is slow, reported as degraded.", desc->getName()));
00138 return acsdaemon::DEGRADED;
00139 }
00140 else
00141 return acsdaemon::RUNNING;
00142 }
00143
00144 }
00145
00146 };
00147
00148
00149 #endif