Exemple #1
0
void
MonitorTestInterface_i::consumer_stats_check()
{
  bool foundConsumerStats = false;
  Monitor::NameList_var names = nsm_->get_statistic_names ();
  CORBA::ULong length = names->length ();
  for(CORBA::ULong i = 0; i < length; i++)
    {
      const char * name = names[i].in ();
      size_t slashcount = 0;
      bool isConsumerQueueSize = false;
      for (size_t nCh = 0; name[nCh] != 0 && slashcount < 3; ++nCh)
        {
          if (name[nCh] == '/')
            {
              slashcount += 1;
              if(slashcount == 3)
              {
                isConsumerQueueSize = 0 == ACE_OS::strcmp(
                  &name[nCh + 1],
                  NotifyMonitoringExt::EventChannelQueueSize);
              }
            }
        }
      if (isConsumerQueueSize)
      {
        foundConsumerStats = true;
        // We have a consumer queue
        try
          {
            Monitor::Data_var queueSizeData =
              nsm_->get_statistic(name);

            Monitor::Numeric queueSizeNum = queueSizeData->data_union.num ();
            ACE_DEBUG ((LM_DEBUG, "Monitor: %s: Average: %f, Maximum: %f, Most recent: %f\n",
                name,
                queueSizeNum.average, queueSizeNum.maximum, queueSizeNum.last));
            if (queueSizeNum.average <= 0.0 || queueSizeNum.average > 2000.0)
              ACE_ERROR ((LM_ERROR, "Monitor: ERROR: %s average queue size [%f] should be greater than zero and less than 2000.\n",
                name,
                queueSizeNum.average));
            if (queueSizeNum.last > 2000.0)
              ACE_ERROR ((LM_ERROR, "Monitor: ERROR: %s most recent queue size [%f] should not be greater than 2000.\n",
                name,
                queueSizeNum.last));
          }
        catch (const CORBA::Exception& ex)
          {
            ex._tao_print_exception (name);
          }
      }

    }
  if(! foundConsumerStats)
    {
      ACE_ERROR ((LM_ERROR, "Monitor: ERROR: No consumer queue size statistics found.\n"
                ));
    }
}
Exemple #2
0
void
MonitorTestInterface_i::brain_dump(const char * /*context*/)
{
#if 0 // verbose output should be controlled via a command line option
  ACE_DEBUG ((LM_DEBUG, "\nStatistics as of: %s\n", context));
  // Temporary::Dale: Dump known names
  CosNotification::NotificationServiceMonitorControl::NameList_var names =
    nsm_->get_statistic_names ();
  CORBA::ULong length = names->length ();
  ACE_DEBUG ((LM_DEBUG, "Statistic names [%d]\n", (int)length));

  // It's much easier to read once it's sorted
  const char** narray = 0;
  ACE_NEW_THROW_EX (narray,
                    const char* [length],
                    CORBA::NO_MEMORY ());
  for(CORBA::ULong i = 0; i < length; i++)
    narray[i] = names[i].in ();
  ACE_OS::qsort (narray, length,
                 sizeof (const char*), sorter);

  for(CORBA::ULong i = 0; i < length; i++)
    {
      stat_dump(narray[i]);
    }
  delete [] narray;
#endif // verbose option
}
Exemple #3
0
int
ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
#if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)

  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
      CORBA::Object_var obj =
        orb->string_to_object (
          "corbaloc:iiop:127.0.0.1:32101/TAO_MonitorAndControl");

      CosNotification::NotificationServiceMonitorControl_var monitor =
        CosNotification::NotificationServiceMonitorControl::_narrow (
          obj.in ());

      if (CORBA::is_nil (monitor.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Unable to resolve the TAO_MonitorAndControl\n"),
                            -1);
        }

      monitor->shutdown ();
      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("MonitorClient: ");
    }
  catch (...)
    {
      error ("Caught an unexpected exception type");
    }

#else /* TAO_HAS_MONITOR_FRAMEWORK==1 */
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);
#endif /* TAO_HAS_MONITOR_FRAMEWORK==1 */

  return 0;
}
Exemple #4
0
void
MonitorTestInterface_i::stat_dump (const char * statName)
{
  try
    {
      Monitor::Data_var data = nsm_->get_statistic(statName);
      switch (data->data_union._d())
      {
      case Monitor::DATA_NUMERIC:
        {
        ACE_DEBUG ((LM_DEBUG, "Numeric: %s\n", statName));
        Monitor::Numeric num = data->data_union.num();
        ACE_DEBUG ((LM_DEBUG, "   count: %d, average: %f; sumsq: %f, min: %f, max: %f: last %f\n",
          (unsigned int)num.count, num.average, num.sum_of_squares, num.minimum, num.maximum, num.last));
        break;
        }
      default:
        {
        Monitor::NameList list = data->data_union.list ();
        size_t len = list.length ();
        ACE_DEBUG ((LM_DEBUG, "Text[%d]: %s\n", (int)len, statName));

        for (size_t i = 0; i < len; i++)
        {
          ACE_CString str = list[i].in ();
          ACE_DEBUG ((LM_DEBUG, "   %d: %s\n", (int)i, str.c_str()));
        }
        break;
        }
      }
    }
  catch (const CORBA::Exception& ex)
    {

      ex._tao_print_exception (statName);
    }
}
Exemple #5
0
void
MonitorTestInterface_i::running (MonitorTestInterface::Which proc)
{
  ACE_CString str;
  Monitor::Data_var data;
  Monitor::NameList list;
  Monitor::Numeric num;

  switch (proc)
    {
    case MonitorTestInterface::NotifyService:
      {
      data =
        nsm_->get_statistic (NotifyMonitoringExt::EventChannelFactoryNames);
      list = data->data_union.list ();

      if (list.length () != 1)
        {
          ACE_ERROR ((LM_ERROR,
                      "ERROR: There should be only one Event "
                      "Channel Factory\n"));
        }

      this->base_ = list[0];
      this->base_ += "/";
      str = this->base_ + NotifyMonitoringExt::ActiveEventChannelCount;
      data = this->nsm_->get_statistic (str.c_str ());
      num = data->data_union.num ();

      if (!ACE::is_equal (num.dlist[0].value, 0.0))
        {
          ACE_ERROR ((LM_ERROR,
                      "ERROR: There should be no active Event "
                      "Channels\n"));
        }

      str = this->base_ + NotifyMonitoringExt::InactiveEventChannelCount;
      data = this->nsm_->get_statistic (str.c_str ());
      num = data->data_union.num ();

      if (!ACE::is_equal (num.dlist[0].value, 0.0))
        {
          ACE_ERROR ((LM_ERROR,
                      "ERROR: There should be no inactive Event "
                      "Channels\n"));
        }

      break;
      }
    case MonitorTestInterface::Consumer:
      {
      str = this->base_ + NotifyMonitoringExt::ActiveEventChannelNames;
      data = nsm_->get_statistic (str.c_str ());
      list = data->data_union.list ();

      if (list.length () != 1)
        {
          ACE_ERROR ((LM_ERROR,
                      "ERROR: There should be only one active "
                      "Event Channel\n"));
        }

      // Base will now be the factory plus the event channel.
      this->base_ = list[0];
      this->base_ += "/";

      str = this->base_ + NotifyMonitoringExt::EventChannelConsumerCount;
      data = this->nsm_->get_statistic (str.c_str ());
      num = data->data_union.num ();
      if (!ACE::is_equal (num.dlist[0].value, 1.0))
        ACE_ERROR ((LM_ERROR, "Monitor: ERROR: There should be only one Consumer\n"));

      str = this->base_ + NotifyMonitoringExt::EventChannelConsumerAdminCount;
      data = nsm_->get_statistic(str.c_str ());
      num = data->data_union.num ();
      if (!ACE::is_equal (num.dlist[0].value, 1.0))
        ACE_ERROR ((LM_ERROR,
                        "Monitor: ERROR: There should be only one ConsumerAdmin\n"));

      str = this->base_ + NotifyMonitoringExt::EventChannelQueueElementCount;
      data = nsm_->get_statistic(str.c_str ());
      num = data->data_union.num ();
      if (!ACE::is_equal (num.dlist[0].value, 0.0))
        ACE_ERROR ((LM_ERROR, "Monitor: ERROR: There should be no events queued\n"));

        brain_dump ("Running Consumer");

      break;
      }
    case MonitorTestInterface::Supplier:
      {
      str = this->base_ + NotifyMonitoringExt::EventChannelSupplierCount;
      data = nsm_->get_statistic(str.c_str ());
      num = data->data_union.num ();

      if (!ACE::is_equal (num.dlist[0].value, 1.0))
        ACE_ERROR ((LM_ERROR, "Monitor: ERROR: There should be only one Supplier\n"));

      str = this->base_ + NotifyMonitoringExt::EventChannelSupplierAdminCount;
      data = nsm_->get_statistic(str.c_str ());
      num = data->data_union.num ();
      if (!ACE::is_equal (num.dlist[0].value, 1.0))
        ACE_ERROR ((LM_ERROR,
              "Monitor: ERROR: There should be only one SupplierAdmin\n"));
        brain_dump ("Running Supplier");
      break;
      }
    default:
      ACE_ERROR ((LM_ERROR, "Monitor: ERROR: Impossible enum value %d\n", proc));
      break;
    }
}
Exemple #6
0
int
ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
  int status = 0;

#if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)

  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) != 0)
        {
          return 1;
        }

      CORBA::Object_var obj =
        orb->string_to_object (monitor_ior);
      CosNotification::NotificationServiceMonitorControl_var nsm =
        CosNotification::NotificationServiceMonitorControl::_narrow (obj.in ());

      if (CORBA::is_nil (nsm.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Monitor: Unable to locate the "
                             "Notification Service Monitor\n"),
                            1);
        }

      MonitorTestInterface_i* mti = 0;
      ACE_NEW_RETURN (mti, MonitorTestInterface_i (nsm.in ()), 1);
      PortableServer::ServantBase_var owner_transfer (mti);

      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      PortableServer::ObjectId_var id = root_poa->activate_object (mti);
      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      MonitorTestInterface_var test =
        MonitorTestInterface::_narrow (object.in ());
      CORBA::String_var ior = orb->object_to_string (test.in ());

      // Test the case where there are no consumers or suppliers first
      // before we write out our IOR
      mti->running (MonitorTestInterface::NotifyService);

      FILE *output_file= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_output_file), ACE_TEXT ("w"));

      if (output_file == 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Cannot open output file for writing IOR: %s\n",
                             ior_output_file),
                             1);
        }

      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();
      poa_manager->activate ();

      orb->run ();
      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("test_monitor: ");
      status++;
    }

#else
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);
#endif /* TAO_HAS_MONITOR_FRAMEWORK==1 */

  return status;
}
Exemple #7
0
void
MonitorTestInterface_i::finished (MonitorTestInterface::Which proc)
{
//  ACE_CString str;
//  Monitor::Data_var data;
//  Monitor::NameList list;
//  Monitor::Numeric num;

  switch (proc)
    {
    case MonitorTestInterface::NotifyService:
      ACE_ERROR ((LM_ERROR, "This should not be called\n"));
      break;
    case MonitorTestInterface::Consumer:
      // By the time the consumer finishes, it should have destroyed
      // the event channel.
      this->running (MonitorTestInterface::NotifyService);
      break;
    case MonitorTestInterface::Supplier:
      {
      ACE_CString consumerCountName = this->base_ + NotifyMonitoringExt::EventChannelConsumerCount;
      Monitor::Data_var consumerCountData =
        nsm_->get_statistic(consumerCountName.c_str ());
      Monitor::Numeric consumerCountNum =
        consumerCountData->data_union.num ();
      if (!ACE::is_equal (consumerCountNum.last, 1.0))
      ACE_ERROR ((LM_ERROR, "Monitor: ERROR: There should still be one Consumer\n"));

      ACE_CString queueElementName = this->base_ + NotifyMonitoringExt::EventChannelQueueElementCount;
      Monitor::Data_var queueElementData =
        nsm_->get_statistic(queueElementName.c_str ());
      Monitor::Numeric queueElementNum =
        queueElementData->data_union.num ();
      if (ACE::is_equal (queueElementNum.last, 0.0))
      ACE_ERROR ((LM_ERROR, "Monitor: ERROR: There should be at least one "
                            "event queued\n"));

      ACE_CString adminNamesName  = this->base_ + NotifyMonitoringExt::EventChannelConsumerAdminNames;
      Monitor::Data_var adminNamesData =
        nsm_->get_statistic(adminNamesName.c_str ());
      Monitor::NameList nameList =
        adminNamesData->data_union.list ();
      for (CORBA::ULong i = 0; i < nameList.length (); i++)
        {
          ACE_CString queueSizeName = nameList[i].in ();
          queueSizeName += "/";
          queueSizeName += NotifyMonitoringExt::EventChannelQueueSize;
          Monitor::Data_var queueSizeData =
            nsm_->get_statistic(queueSizeName.c_str ());
          Monitor::Numeric queueSizeNum =
            queueSizeData->data_union.num ();
        ACE_DEBUG ((LM_DEBUG, "Monitor: Queue Size: Average: %f, Maximum: %f, Most recent: %f\n",
            queueSizeNum.average, queueSizeNum.maximum, queueSizeNum.last));
          if (queueSizeNum.average <= 0.0 || queueSizeNum.average > 2000.0)
            ACE_ERROR ((LM_ERROR, "Monitor: ERROR: The average queue size [%f] should be greater than zero and less than 2000.\n",
              queueSizeNum.average));
          if (queueSizeNum.last > 2000.0)
            ACE_ERROR ((LM_ERROR, "Monitor: ERROR: The most recent queue size [%f] should not be greater than 2000.\n",
              queueSizeNum.last));
      }

      consumer_stats_check();

      brain_dump ("Finished Supplier");
      break;
      }
    default:
      ACE_ERROR ((LM_ERROR, "Impossible enum value %d\n", proc));
      break;
    }
}
Exemple #8
0
int
TAO_MonitorManager::ORBTask::svc (void)
{
  try
    {
      if (CORBA::is_nil (this->orb_.in ()))
        {
          ORBSVCS_ERROR_RETURN ((LM_ERROR,
                             "(%P|%t) TAO_MonitorManager: Unable to "
                             "initialize the ORB\n"),
                            1);
        }

      PortableServer::POA_var poa;

      {
        ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->mutex_, -1);

        CORBA::Object_var obj =
          this->orb_->resolve_initial_references ("RootPOA");

        poa = PortableServer::POA::_narrow (obj.in ());

        if (CORBA::is_nil (poa.in ()))
          {
            ORBSVCS_ERROR_RETURN ((LM_ERROR,
                               "(%P|%t) TAO_MonitorManager: Unable to "
                               "resolve the RootPOA\n"),
                              1);
          }

        PortableServer::POAManager_var poa_manager = poa->the_POAManager ();
        poa_manager->activate ();

        // Activate the object
        NotificationServiceMonitor_i* servant;
        ACE_NEW_RETURN (servant,
                        NotificationServiceMonitor_i (this->orb_.in ()), 1);
        PortableServer::ServantBase_var owner_transfer(servant);
        PortableServer::ObjectId_var id = poa->activate_object (servant);

        // Register the object with the IORTable
        obj = poa->id_to_reference (id.in ());
        CosNotification::NotificationServiceMonitorControl_var monitor =
          CosNotification::NotificationServiceMonitorControl::_narrow (obj.in ());
        CORBA::String_var ior = this->orb_->object_to_string (monitor.in ());
        obj = this->orb_->resolve_initial_references ("IORTable");
        IORTable::Table_var iortable = IORTable::Table::_narrow (obj.in ());

        if (CORBA::is_nil (iortable.in ()))
          {
            ORBSVCS_ERROR_RETURN ((LM_ERROR,
                               "(%P|%t) TAO_MonitorManager: Unable to "
                               "resolve the IORTable\n"),
                              1);
          }

        iortable->bind(ACE_TEXT_ALWAYS_CHAR(mc_orb_name_.c_str()), ior.in ());

        if (this->use_name_svc_)
          {
            TAO_Naming_Client nc;
            nc.init (this->orb_.in ());
            CosNaming::Name name (1);
            name.length (1);
            name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(mc_orb_name_.c_str()));
            nc->rebind (name, monitor.in ());
          }

        if (this->ior_output_.length () > 0)
          {
            FILE* fp = ACE_OS::fopen (this->ior_output_.c_str (), "w");

            if (fp == 0)
              {
                ORBSVCS_ERROR_RETURN ((LM_ERROR,
                                   ACE_TEXT ("(%P|%t) TAO_MonitorManager: "
                                   ACE_TEXT ("Unable to write to %s\n")),
                                   this->ior_output_.c_str ()),
                                  1);
              }
            else
              {
                ACE_OS::fprintf (fp, "%s", ior.in ());
                ACE_OS::fclose (fp);
              }
          }
      }

      // R1: race condition (partially fixed):
      // TAO_MonitorManager::fini() is called directly after
      // TAO_MonitorManager::run(), the shutdown call on the ORB could
      // happen but the ORB::run() loop won't exit.
      startup_barrier_.wait ();
      this->orb_->run ();

      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->mutex_, -1);

      // Destroy the POA and ORB
      if (!CORBA::is_nil (poa.in ()))
        {
          poa->destroy (true, true);
        }

      this->orb_->destroy ();

      // Set to nil to avoid double shutdown in TAO_MonitorManager::fini()
      this->orb_ = CORBA::ORB::_nil ();
    }
  catch (const CORBA::Exception& ex)
    {
      if (!CORBA::is_nil (this->orb_.in ()))
        {
          try
            {
              this->orb_->shutdown ();
            }
          catch (...)
            {
            }

          this->orb_ = CORBA::ORB::_nil ();
        }

      ex._tao_print_exception ("Caught in "
                               "TAO_MonitorManager::ORBTask::svc");
    }
  catch (...)
    {
      if (!CORBA::is_nil (this->orb_.in ()))
        {
          try
            {
              this->orb_->shutdown ();
            }
          catch (...)
            {
            }
          this->orb_ = CORBA::ORB::_nil ();
        }

      ORBSVCS_ERROR ((LM_ERROR,
                  "Unexpected exception type caught "
                  "in TAO_MonitorManager::ORBTask::svc"));
    }

  return 0;
}