void SequencePushConsumer::push_structured_events ( const CosNotification::EventBatch &batch) { this->test_client_->events_received_ += batch.length (); if (batch.length () > this->test_client_->consumer_batch_size_) ACE_DEBUG ((LM_ERROR, "Error: Received more than max event batch %d\n", batch.length ())); this->test_client_->on_event_received (); ACE_OS::sleep (this->test_client_->consumer_delay_); }
static void SendBatch (int batch_id) { CosNotification::EventBatch events; events.length(BATCH_SIZE); for (CORBA::Long i = 0; i < BATCH_SIZE; ++i) { int id = batch_id * BATCH_SIZE + i; CosNotification::StructuredEvent event; event.header.fixed_header.event_type.domain_name = CORBA::string_dup ("a"); event.header.fixed_header.event_type.type_name = CORBA::string_dup ("b"); event.header.fixed_header.event_name = CORBA::string_dup ("c"); event.header.variable_header.length (3); event.header.variable_header[0].name = CORBA::string_dup ("id"); event.header.variable_header[0].value <<= (CORBA::Long)id; event.header.variable_header[1].name = CORBA::string_dup (CosNotification::Priority); event.header.variable_header[1].value <<= (CORBA::Short)(id); event.header.variable_header[2].name = CORBA::string_dup (CosNotification::Timeout); event.header.variable_header[2].value <<= (TimeBase::TimeT) (num_events - id); events[i] = event; } supplier_1->send_events (events); }
static void SendEvents (int id) { ACE_UNUSED_ARG(id); CosNotification::EventBatch events (amount); events.length (amount); for(CORBA::ULong z = 0; z < amount; z++) { const char* type = ( (z & 1) == 1 ? "odd" : "even" ); events[z].header.fixed_header.event_type.domain_name = CORBA::string_dup("Orbix 2000 Demos"); events[z].header.fixed_header.event_type.type_name = CORBA::string_dup("Sequence Notification Push Demo Event"); events[z].header.fixed_header.event_name = CORBA::string_dup("test event"); events[z].filterable_data.length (1); events[z].filterable_data[0].name = CORBA::string_dup("type"); events[z].filterable_data[0].value <<= type; } try { supplier_1->send_events(events); } catch (const CORBA::Exception& e) { e._tao_print_exception ("Error: Supplier exception: "); } }
void Notify_Sequence_Push_Consumer::push_structured_events ( const CosNotification::EventBatch& events) { this->count_ += events.length (); if (this->count_ >= max_events) { this->client_.consumer_done (this); } }
void Notify_Sequence_Push_Consumer::push_structured_events( const CosNotification::EventBatch& events) { ACE_DEBUG((LM_DEBUG, "{%u}", events.length())); this->count_ += events.length(); if (this->count_ > this->high_) { this->client_.consumer_done (this); ACE_ERROR((LM_ERROR, ACE_TEXT ("Sequence Consumer (%P|%t): ERROR: too ") ACE_TEXT ("many events received.\n"))); } else if (this->count_ >= this->low_) { this->client_.consumer_done (this); } }
static void SendEvents (int id) { static const char* types[] = { "good", "bad", "ugly" }; CosNotification::EventBatch events; CosNotification::StructuredEvent event; event.header.fixed_header.event_type.domain_name = CORBA::string_dup("Orbix 2000 Demos"); event.header.fixed_header.event_type.type_name = CORBA::string_dup("Sequence Notification Push Demo Event"); event.header.fixed_header.event_name = CORBA::string_dup("test event"); event.header.variable_header.length (1); event.header.variable_header[0].name = CORBA::string_dup(CosNotification::Priority); event.filterable_data.length (3); event.filterable_data[0].name = CORBA::string_dup("Number"); event.filterable_data[1].name = CORBA::string_dup("Index"); event.filterable_data[2].name = CORBA::string_dup("enum"); events.length(PER_BATCH); for(int z = 0; z < PER_BATCH; ++z) { event.header.variable_header[0].value <<= (CORBA::Short) (id > num_batches / 2 ? -id : id); if (z % 2 == 0) { event.filterable_data[0].value <<= (CORBA::Long)20; } else { event.filterable_data[0].value <<= (CORBA::Long)10; } event.filterable_data[1].value <<= z; event.filterable_data[2].value <<= types[id % 3]; events[z] = event; } try { supplier_1->send_events(events); } catch (const CORBA::Exception& e) { e._tao_print_exception ("Error: Supplier exception: "); } }
void EventSequenceConsumer_i::push_structured_events ( const CosNotification::EventBatch& events ) { std::cout << "events received " << std::endl; const char* value = 0; for (unsigned int n = 0; n < events.length(); ++n) { for (unsigned int i = 0; i < events[n].filterable_data.length(); ++i) { events[n].filterable_data[i].value >>= value; std::cout << events[n].filterable_data[i].name.in() << "\t" << value << std::endl; } } }
void TAO_Notify_SequenceProxyPushConsumer::push_structured_events (const CosNotification::EventBatch& event_batch) { // Check if we should proceed at all. if (this->admin_properties().reject_new_events () == 1 && this->admin_properties().queue_full ()) throw CORBA::IMP_LIMIT (); if (this->is_connected () == 0) { throw CosEventComm::Disconnected (); } for (CORBA::ULong i = 0; i < event_batch.length (); ++i) { const CosNotification::StructuredEvent& notification = event_batch[i]; TAO_Notify_StructuredEvent_No_Copy event (notification); this->push_i (&event); } }
void Notify_Sequence_Push_Consumer::push_structured_events ( const CosNotification::EventBatch& events) { if (count_ == 0) { // Sleep long enough to force the channel to back up, otherwise // there will be no ordering. ACE_OS::sleep(2); } ACE_ASSERT(events.length() == static_cast<CORBA::ULong>(BATCH_SIZE)); count_ += events.length(); if (this->count_ > this->expected_) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: too many events received.\n"))); } if (this->count_ >= this->expected_) { this->client_.consumer_done (this); } ACE_ASSERT(events[0].header.variable_header.length() == 3); ACE_ASSERT(ACE_OS::strcmp(events[0].header.variable_header[0].name.in(), "id") == 0); CORBA::Long first_id = 0; events[0].header.variable_header[0].value >>= first_id; CORBA::Long last_id = 0; events[events.length() - 1].header.variable_header[0].value >>= last_id; ACE_DEBUG((LM_DEBUG, "\n Received id %d-%d\n", first_id, last_id)); int events_length = static_cast<int>(events.length()); CORBA::Long previous_id = first_id; if (count_ > events_length) // Ignore the very first batch { // First check that the sequences are ordered correctly for (CORBA::ULong idx = 1; idx < events.length(); ++idx) { CORBA::Long id = 0; events[idx].header.variable_header[0].value >>= id; CORBA::Long expected_id = previous_id + 1; if (order_policy_ == CosNotification::PriorityOrder || order_policy_ == CosNotification::DeadlineOrder) { expected_id = previous_id - 1; } if (id != expected_id) { ACE_ERROR((LM_ERROR, "Error: Expected:%d Received:%d\n", expected_id, id)); return; } previous_id = id; } // Next check that the first id in the sequence is ordered // relative to the previously retrieved sequence. if (previous_first_ != 0) { CORBA::Long expected_id = previous_first_ + BATCH_SIZE; if (order_policy_ == CosNotification::PriorityOrder || order_policy_ == CosNotification::DeadlineOrder) { expected_id = previous_first_ - BATCH_SIZE; } if (first_id != expected_id) { ACE_ERROR((LM_ERROR, "Error: Expected:%d Received:%d\n", expected_id, first_id)); return; } } previous_first_ = first_id; } }
// FUZZ: disable check_for_ACE_Guard bool TAO_Notify_SequencePushConsumer::dispatch_from_queue (Request_Queue& requests, ACE_Guard <TAO_SYNCH_MUTEX> & ace_mon) // FUZZ: enable check_for_ACE_Guard { bool result = true; if (DEBUG_LEVEL > 0) { ORBSVCS_DEBUG ( (LM_DEBUG, ACE_TEXT ("(%P|%t) SequencePushConsumer dispatch queued requests. queue size:%u\n"), requests.size ())); } CORBA::ULong queue_size = ACE_Utils::truncate_cast<CORBA::ULong> (requests.size ()); CORBA::Long max_batch_size = queue_size; if (this->max_batch_size_.is_valid () ) { max_batch_size = this->max_batch_size_.value (); } CORBA::Long batch_size = queue_size; if (batch_size > max_batch_size) { batch_size = max_batch_size; } if (batch_size > 0) { CosNotification::EventBatch batch (batch_size); batch.length (batch_size); Request_Queue completed; CORBA::Long pos = 0; TAO_Notify_Method_Request_Event_Queueable * request = 0; while (pos < batch_size && requests.dequeue_head (request) == 0) { if (DEBUG_LEVEL > 0) { ORBSVCS_DEBUG ( (LM_DEBUG, ACE_TEXT ("(%P|%t) Sequence Dispatch Method_Request_Dispatch @%@\n"), request)); } const TAO_Notify_Event * ev = request->event (); ev->convert (batch [pos]); ++pos; // note enqueue at head, use queue as stack. completed.enqueue_head (request); } batch.length (pos); ACE_ASSERT (pos > 0); ace_mon.release (); bool from_timeout = false; TAO_Notify_Consumer::DispatchStatus status = this->dispatch_batch (batch); ace_mon.acquire (); switch (status) { case DISPATCH_SUCCESS: { TAO_Notify_Method_Request_Event_Queueable * request = 0; while (completed.dequeue_head (request) == 0) { request->complete (); request->release (); } result = true; break; } case DISPATCH_FAIL_TIMEOUT: from_timeout = true; // Fall through case DISPATCH_FAIL: { TAO_Notify_Method_Request_Event_Queueable * request = 0; while (completed.dequeue_head (request) == 0) { if (request->should_retry ()) { if (DEBUG_LEVEL > 0) ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Consumer %d: Will retry %d\n"), static_cast <int> (this->proxy ()->id ()), request->sequence ())); requests.enqueue_head (request); result = false; } else { if (DEBUG_LEVEL > 0) ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Consumer %d: Discarding %d\n"), static_cast<int> (this->proxy ()->id ()), request->sequence ())); request->complete (); request->release (); } } while (requests.dequeue_head (request) == 0) { if (request->should_retry ()) { if (DEBUG_LEVEL > 0) ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Consumer %d: Will retry %d\n"), static_cast<int> (this->proxy ()->id ()), request->sequence ())); requests.enqueue_head (request); result = false; } else { if (DEBUG_LEVEL > 0) ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Consumer %d: Discarding %d\n"), static_cast<int> (this->proxy ()->id ()), request->sequence ())); request->complete (); request->release (); } } ace_mon.release(); try { this->proxy_supplier ()->destroy (from_timeout); } catch (const CORBA::Exception&) { // todo is there something meaningful we can do here? ; } ace_mon.acquire(); break; } case DISPATCH_RETRY: case DISPATCH_DISCARD: { TAO_Notify_Method_Request_Event_Queueable * request = 0; while (completed.dequeue_head (request) == 0) { if (request->should_retry ()) { if (DEBUG_LEVEL > 0) ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Consumer %d: Will retry %d\n"), static_cast<int> (this->proxy ()->id ()), request->sequence ())); requests.enqueue_head (request); result = false; } else { if (DEBUG_LEVEL > 0) ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Consumer %d: Discarding %d\n"), static_cast<int> (this->proxy ()->id ()), request->sequence ())); request->complete (); request->release (); } } break; } default: { result = false; break; } } } return result; }
void Notify_Sequence_Push_Consumer::push_structured_events ( const CosNotification::EventBatch& events) { ++count_; // The pacing interval is set large enough that it should never come into // play unless something goes wrong. if (events.length() != static_cast<size_t>(BATCH_SIZE)) { ACE_ERROR((LM_ERROR, "Error : Unexpected batch size %u/%u\n", events.length(), BATCH_SIZE)); this->client_.consumer_done (this); } ACE_ASSERT(ACE_OS::strcmp(events[0].header.variable_header[0].name.in(), "Id") == 0); CORBA::Long id1 = 0; CORBA::Long id2 = 0; events[0].header.variable_header[0].value >>= id1; events[events.length() - 1].header.variable_header[0].value >>= id2; ACE_DEBUG((LM_DEBUG, "{%d-%d}\n", id1, id2)); if (count_ == 1) { // We sleep long enough after the first batch to ensure that // the supplier has time to send all the events. This will allow // the notify service to discard all but one batch. ACE_OS::sleep(FIRST_SLEEP_SECS); first_ = id1; } // Validate the batch is ordered for (CORBA::Long i = 1; i < BATCH_SIZE; ++i) { CORBA::Long id = 0; events[i].header.variable_header[0].value >>= id; if (id != id1 + i) { ACE_ERROR((LM_ERROR, "Error: Invalid batch. Expected %d, Was %d\n", id1 + i, id)); this->client_.consumer_done (this); return; } } CORBA::Long expected = 0; if (discard_policy_ == CosNotification::PriorityOrder) { expected = sent_ - BATCH_SIZE + 1; // e.g. 37, 38, 39, 40 } else if (discard_policy_ == CosNotification::FifoOrder) { expected = sent_ - BATCH_SIZE + 1; // e.g. 37, 38, 39, 40 } else { ACE_ASSERT(discard_policy_ == CosNotification::LifoOrder); expected = BATCH_SIZE + 1; // e.g. 5, 6, 7, 8 } // On some slower platforms, the discard policy may be applied before the first // batch is sent. In that case we may only get a single batch. // On other platforms we may get two batches, but the first batch // may or may not conform to the discard policy. if (count_ == 1 && id1 != expected && discard_policy_ != CosNotification::LifoOrder) { // We expect to get another batch with the correct one. } else { this->client_.consumer_done (this); } if (count_ > 2) { ACE_ERROR((LM_ERROR, "Error : Too many batches received.\n")); } }
int ACE_TMAIN (int argc, ACE_TCHAR* argv[]) { int status = 0; ACE_Auto_Ptr<sig_i> sig_impl; try { Supplier_Client client; ACE_Argv_Type_Converter argcon (argc, argv); status = client.init (argcon.get_argc (), argcon.get_TCHAR_argv ()); if (status == 0) { CosNotifyChannelAdmin::EventChannel_var ec = client.create_event_channel ("MyEventChannel", 0); sig_impl.reset (new sig_i (client.orb ())); sig_var sig = sig_impl->_this (); // If the ior_output_file exists, output the ior to it if (ior_output_file != 0) { CORBA::String_var ior = client.orb ()->object_to_string (sig.in ()); FILE *output_file= ACE_OS::fopen (ior_output_file, ACE_TEXT ("w")); ACE_ASSERT (output_file != 0); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } CosNotifyChannelAdmin::SupplierAdmin_var admin = create_supplieradmin (ec.in ()); ACE_ASSERT (!CORBA::is_nil (admin.in ())); create_suppliers (admin.in (), client.root_poa ()); sig_impl->wait_for_startup (); // If this is changed, you should update max_events // found in Notify_Push_Consumer.cpp int batch_size = 4; int num_events = 80 / batch_size; ACE_DEBUG ((LM_DEBUG, "1 supplier sending %d batches of %d events...\n", num_events, batch_size)); CosNotification::EventBatch events; events.length(batch_size); for (int i = 0; i < num_events; ++i) { supplier_1->send_events (events); } ACE_DEBUG ((LM_DEBUG, "\nSupplier sent %d events.\n", num_events)); sig_impl->wait_for_completion (); ACE_OS::unlink (ior_output_file); supplier_1->disconnect (); ec->destroy (); } } catch (const CORBA::Exception& e) { e._tao_print_exception ("Error: "); status = 1; } return status; }
void Sequence::run_test (void) { // operations: CosNotification::StructuredEvent event; // EventHeader. // FixedEventHeader. // EventType. // string. event.header.fixed_header.event_type.domain_name = CORBA::string_dup("*"); // string event.header.fixed_header.event_type.type_name = CORBA::string_dup("*"); // string event.header.fixed_header.event_name = CORBA::string_dup("myevent"); // OptionalHeaderFields. // PropertySeq. // sequence<Property>: string name, any value CosNotification::PropertySeq& qos = event.header.variable_header; qos.length (1); // put nothing here // FilterableEventBody // PropertySeq // sequence<Property>: string name, any value event.filterable_data.length (3); event.filterable_data[0].name = CORBA::string_dup("threshold"); event.filterable_data[1].name = CORBA::string_dup("temperature"); event.filterable_data[1].value <<= (CORBA::Long)70; event.filterable_data[2].name = CORBA::string_dup("pressure"); event.filterable_data[2].value <<= (CORBA::Long)80; CORBA::Short prio = CosNotification::LowestPriority; CosNotification::EventBatch batch; batch.length (this->supplier_batch_size_); CORBA::ULong batch_index = 0; for (int i = 0; i < this->event_count_; ++i) { event.filterable_data[0].value <<= (CORBA::Long)i; // any event.remainder_of_body <<= (CORBA::Long)i; qos[0].name = CORBA::string_dup (CosNotification::Priority); qos[0].value <<= (CORBA::Short)prio++; batch[batch_index] = event; batch_index++; if (batch_index == this->supplier_batch_size_) { batch.length (batch_index); // set the correct length if (TAO_debug_level) ACE_DEBUG ((LM_DEBUG, "Sending batch with %d events\n", batch.length ())); this->supplier_->send_events (batch); // reset batch.length (this->supplier_batch_size_); batch_index = 0; } } // for // send the last batch. if (batch_index > 0) { batch.length (batch_index); // set the correct length this->supplier_->send_events (batch); } }