adminproperties.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 525 行 · 第 1/2 页
CPP
525 行
);
this->ec_ = notify_factory_->create_channel (this->initial_qos_,
this->initial_admin_,
id
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
ACE_ASSERT (!CORBA::is_nil (ec_.in ()));
CosNotifyChannelAdmin::AdminID adminid;
this->supplier_admin_ = ec_->new_for_suppliers (this->ifgop_,
adminid
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
ACE_ASSERT (!CORBA::is_nil (supplier_admin_.in ()));
this->consumer_admin_ = ec_->new_for_consumers (this->ifgop_,
adminid
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
ACE_ASSERT (!CORBA::is_nil (consumer_admin_.in ()));
return 0;
}
void
AdminProperties::run_test (ACE_ENV_SINGLE_ARG_DECL)
{
this->test_max_queue_length (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->test_max_clients (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// Destroy the EC and hence release server resources.
this->ec_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
}
void
AdminProperties::test_max_queue_length (ACE_ENV_SINGLE_ARG_DECL)
{
// Create the consumer
AdminProperties_StructuredPushConsumer *consumer;
ACE_NEW (consumer,
AdminProperties_StructuredPushConsumer (this));
consumer->init (root_poa_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
consumer->connect (this->consumer_admin_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
// Create the supplier
TAO_Notify_Tests_StructuredPushSupplier *supplier = 0;
ACE_NEW (supplier,
TAO_Notify_Tests_StructuredPushSupplier ());
supplier->init (root_poa_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
supplier->connect (this->supplier_admin_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
AdminProperties_Task supplier_task;
// Init the Task to send events;
supplier_task.init (supplier, this);
if (supplier_task.activate (THR_NEW_LWP | THR_JOINABLE,
1) != 0)
{
ACE_ERROR ((LM_ERROR,
"Cannot activate supplier task\n"));
}
ACE_OS::sleep (initial_delay_); // Consumers receive events in the main thread. delay receiving the 1st event.
CORBA::Long previous_count = 0;
do{
previous_count = consumer->events_received_.value ();
// we add a full 1 sec. to the waiting period for a new event.
ACE_Time_Value waiting_period (this->consumer_delay_.sec () + 1, 0);
this->orb_->run (waiting_period);
}while (previous_count != consumer->events_received_.value ());
// Test ended.
// wait for the supplier task to finish.
supplier_task.wait ();
CORBA::Long received_count = consumer->events_received_.value ();
// disconnect the participants.
consumer->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
supplier->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
// check the results and print the assessment.
// we expect to see event_count_+1 events
ACE_DEBUG ((LM_DEBUG, "Supplier send %d events, consumer received %d events, max_queue_length = %d\n",
event_count_, received_count, max_queue_length_));
if (received_count > this->max_queue_length_ + 1)
{
ACE_DEBUG ((LM_ERROR, "Error: MaxQueueLength exceeded, try increasing consumer delay (currently = %d)\n",
this->consumer_delay_.sec ()));
if (this->reject_new_events_ == 1 && was_rejected_ == 0)
ACE_DEBUG ((LM_ERROR, "RejectNewEvents failed\n"));
}
}
void
AdminProperties::test_max_clients (ACE_ENV_SINGLE_ARG_DECL)
{
this->create_suppliers (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->create_consumers (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// check the results and print the assessment.
if (this->consumers_connected_count_ > this->max_consumers_)
ACE_DEBUG ((LM_ERROR, "Connected consumers %d, exceed MaxConsumers %d\n",
this->consumers_connected_count_ > this->max_consumers_));
if (this->suppliers_connected_count_ > this->max_suppliers_)
ACE_DEBUG ((LM_ERROR, "Connected suppliers %d, exceed MaxSuppliers %d\n",
this->suppliers_connected_count_ > this->max_suppliers_));
}
void
AdminProperties::create_suppliers (ACE_ENV_SINGLE_ARG_DECL)
{
// Create the requested number of suppliers.
// @@ CosNotifyChannelAdmin::AdminID adminid;
// @@ CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
// @@ CosNotifyChannelAdmin::OR_OP;
int index = 0;
ACE_TRY
{
TAO_Notify_Tests_StructuredPushSupplier *supplier;
for (index = 0; index < this->suppliers_; ++index)
{
ACE_NEW (supplier,
TAO_Notify_Tests_StructuredPushSupplier ());
supplier->init (root_poa_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
supplier->connect (this->supplier_admin_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
this->suppliers_connected_count_++;
}
}
ACE_CATCH (CORBA::IMP_LIMIT, impl_limit)
{
if (TAO_debug_level)
ACE_DEBUG ((LM_DEBUG, "Impl Limit excpetion when connecting supplier\n"));
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"Exception in connecting supplier\n");
}
ACE_ENDTRY;
}
void
AdminProperties::create_consumers (ACE_ENV_SINGLE_ARG_DECL)
{
// Create the requested number of suppliers.
// @@ CosNotifyChannelAdmin::AdminID adminid;
// @@ CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
// @@ CosNotifyChannelAdmin::OR_OP;
int index = 0;
ACE_TRY
{
TAO_Notify_Tests_StructuredPushConsumer *consumer;
for (index = 0; index < this->consumers_; ++index)
{
ACE_NEW (consumer,
TAO_Notify_Tests_StructuredPushConsumer ());
consumer->init (root_poa_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
consumer->connect (this->consumer_admin_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
this->consumers_connected_count_++;
}
}
ACE_CATCH (CORBA::IMP_LIMIT, impl_limit)
{
if (TAO_debug_level)
ACE_DEBUG ((LM_DEBUG, "Impl Limit excpetion when connecting consumer\n"));
}
ACE_CATCHANY
{
if (TAO_debug_level)
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"Exception in connecting consumer \n");
}
ACE_ENDTRY;
}
/***************************************************************************/
int
main (int argc, char* argv[])
{
AdminProperties test;
ACE_TRY_NEW_ENV
{
test.init (argc,
argv
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
test.run_test (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCH (CORBA::UserException, ue)
{
ACE_PRINT_EXCEPTION (ue,
"Events user error: ");
return 1;
}
ACE_CATCH (CORBA::SystemException, se)
{
ACE_PRINT_EXCEPTION (se,
"Events system error: ");
return 1;
}
ACE_ENDTRY;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?