SlideShare una empresa de Scribd logo
1 de 383
C++ Network Programming Systematic Reuse with  ACE & Frameworks Dr. Douglas C. Schmidt [email_address] www.dre.vanderbilt.edu/~schmidt/ Professor of EECS Vanderbilt University Nashville, Tennessee
Presentation Outline ,[object Object],[object Object],Cover OO techniques & language features that enhance software quality ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Air Frame GPS FLIR ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],GPS FLIR AP Nav HUD IFF Cyclic  Exec F-15 Motivation Consequence: Small HW/SW changes have big (negative) impact on DRE system QoS & maintenance Air Frame AP Nav HUD GPS IFF FLIR Cyclic  Exec A/V-8B Air Frame Cyclic  Exec AP Nav HUD IFF F/A-18 Air Frame AP Nav HUD GPS IFF FLIR Cyclic  Exec UCAV
Common Middleware Services ,[object Object],[object Object],[object Object],[object Object],Air Frame AP Nav HUD GPS IFF FLIR Domain-specific Services Motivation F-15 product variant A/V 8-B product variant F/A 18 product variant UCAV product variant Product-line architecture Hardware (CPU, Memory, I/O) OS & Network Protocols Host Infrastructure Middleware Distribution Middleware
Overview of Product-line Architectures (PLAs) ,[object Object],[object Object],James Coplien et al. Commonality & Variability in Software Engineering, IEEE Software 1998 ,[object Object],[object Object],Air Frame AP Nav HUD GPS IFF FLIR Reusable Architecture Framework Reusable Application Components OS & Network Protocols Host Infrastructure Middleware Distribution Middleware Common Middleware Services Domain-specific Services
Applying SCV to Bold Stroke PLA ,[object Object],[object Object],[object Object],[object Object],[object Object],Hardware (CPU, Memory, I/O) OS & Network Protocols Host Infrastructure Middleware Distribution Middleware Common Middleware Services Domain-specific Services
[object Object],[object Object],[object Object],[object Object],[object Object],Applying SCV to Bold Stroke PLA Frameworks are essential for developing PLAs Hardware (CPU, Memory, I/O) OS & Network Protocols Host Infrastructure Middleware Distribution Middleware Common Middleware Services Domain-specific Services
Overview of Frameworks Framework Characteristics  www.cs.wustl.edu/~schmidt/frameworks.html Application-specific functionality  ,[object Object],Networking  Database GUI  ,[object Object],Mission Computing E-commerce Scientific Visualization ,[object Object]
Benefits of Frameworks ,[object Object],[object Object],Distribution Infrastructure Concurrency Infrastructure Thin UI Clients Communication Services OS-Access Layer Broker Component Repository Component Configurator Proxy Proxy Broker Admin Controllres Admin Views AdminClient Picking Controllres Picking Views PickingClient Broker Logging Handler ThreadPool * Reactor Broker Scheduler/ ActivationList Service Request Service Request Service Request WarehouseRepHalfX
Benefits of Frameworks ,[object Object],[object Object],[object Object],[object Object]
Benefits of Frameworks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],www.dre.vanderbilt.edu/scoreboard
Comparing Reuse Techniques Class Library Architecture ADTs Strings Locks IPC Math LOCAL  INVOCATIONS APPLICATION- SPECIFIC FUNCTIONALITY EVENT LOOP GLUE CODE Files GUI ,[object Object],[object Object],Framework Architecture ADTs Locks Strings Files INVOKES ,[object Object],[object Object],Reactor  GUI DATABASE  NETWORKING APPLICATION-SPECIFIC FUNCTIONALITY CALLBACKS Middleware Bus Component Architecture ,[object Object],[object Object],Naming Locking Logging Events
Taxonomy of Reuse Techniques Class  Libraries Frameworks Macro-level Meso-level Micro-level Borrow caller’s thread Inversion of control Borrow caller’s thread Domain-specific or Domain-independent Domain-specific Domain-independent Stand-alone composition entities “ Semi-complete” applications Stand-alone language entities Components
The Frameworks in ACE Acceptor Connector Component Configurator Stream Reactor  Proactor Task  Application- specific  functionality  ACE frameworks are a product-line architecture for domain of network applications Calls back to service handlers to initialize them after they are connected Acceptor/Connector Inversion of Control & Hook Methods ACE Framework Calls back to initialize & finalize tasks when they are pushed & popped from a stream Streams Calls back to an application-supplied hook method to perform processing in one or more threads of control Task Calls back to application-supplied service objects to initialize, suspend, resume, & finalize them Service Configurator Calls back to application-supplied event handlers to perform processing when events occur synchronously & asynchronously Reactor & Proactor
Commonality & Variability in ACE Frameworks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Commonality  ,[object Object],[object Object],Reactor ,[object Object],[object Object],[object Object],Acceptor/ Connector Variability Framework ,[object Object],[object Object],Streams ,[object Object],[object Object],Task ,[object Object],[object Object],Service Configurator ,[object Object],Proactor
The Layered Architecture of ACE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],www.cs.wustl.edu/~schmidt/ACE.html
Networked Logging Service Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Patterns in the Networked Logging Service  Reactor Acceptor- Connector Component Configurator Monitor Object Active Object Proactor Pipes & Filters Wrapper Facade Strategized Locking Scoped Locking Thread-safe Interface Half-Sync/ Half-Async Leader/ Followers
Service/Server Design Dimensions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Short- versus Long-duration Services ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Internal vs. External Services ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Monolithic vs. Layered/Modular Services ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Single Service vs. Multiservice Servers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: Comparing Multiservice Server Frameworks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
One-shot vs. Standing Servers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE Reactor Framework ,[object Object],[object Object],[object Object],[object Object]
The ACE Reactor Framework ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE Reactor Framework ,[object Object]
The Reactor Pattern Participants ,[object Object],Handle owns dispatches * notifies * * handle set Reactor handle_events() register_handler() remove_handler() Event Handler handle_event () get_handle() Concrete Event Handler A handle_event () get_handle() Concrete Event Handler B handle_event () get_handle() Synchronous Event Demuxer select () <<uses>>
The Reactor Pattern Dynamics ,[object Object],[object Object],[object Object],: Main Program : Concrete Event Handler : Reactor : Synchronous  Event Demultiplexer register_handler() get_handle() handle_events() select() handle_event() Handle Handles Handles Con. Event Handler Events service() event
Pros & Cons of the Reactor Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_Time_Value Class (1/2) ,[object Object],[object Object],[object Object],[object Object]
The ACE_Time_Value Class (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_Time_Value Class API This class handles  variability  of time representation & manipulation across OS platforms via a  common  API
Sidebar: Relative vs. Absolute Timeouts  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the ACE_Time_Value Class (1/2) 1 #include &quot;ace/OS.h&quot; 2 3 const ACE_Time_Value max_interval (60 * 60); // 1 hour. 4 5 int main (int argc, char *argv[]) { 6  ACE_Time_Value expiration = ACE_OS::gettimeofday (); 7  ACE_Time_Value interval; 8 9  ACE_Get_Opt opt (argc, argv,  &quot; e:i: &quot; )); 10  for (int c; (c = opt ()) != -1;) 11  switch (c) { 12  'e': expiration += ACE_Time_Value (atoi (opt.opt_arg ())); 13  break; 14  'i': interval = ACE_Time_Value (atoi (opt.opt_arg ())); 15  break; 16  } ,[object Object],[object Object]
Using the ACE_Time_Value Class (2/2) 17  if (interval > max_interval) 18  cout << &quot;interval must be less than &quot;  19  << max_interval.sec () << endl; 20  else if (expiration > (ACE_Time_Value::max_time - interval)) 21  cout << &quot;expiration + interval must be less than &quot;  22  << ACE_Time_Value::max_time.sec () << endl; 23  return 0; 24 } Note the use of relational operators
Sidebar: ACE_Get_Opt ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_Event_Handler Class (1/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],function 1 function 2 function 3 data 1 data 2 data 3 Demultiplexer Event Sources
The ACE_Event_Handler Class (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_Event_Handler Class API This class handles  variability  of event processing behavior via a  common  event handler API
Types of Events & Event Handler Hooks ,[object Object],[object Object],[object Object],[object Object]
Event Handler Hook Method Return Values ,[object Object],[object Object],[object Object],[object Object],[object Object],Greater than zero (> 0) ,[object Object],Minus one ( - 1) ,[object Object],[object Object],Zero (0) Behavior Return value
Sidebar: Idioms for Designing Event Handlers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: Tracking Event Handler Registrations (1/2) class My_Event_Handler : public ACE_Event_Handler { private: // Keep track of the events the handler's registered for. ACE_Reactor_Mask mask_;  public: // ... class methods shown below ... }; My_Event_Handler (ACE_Reactor *r): ACE_Event_Handler (r) { ACE_SET_BITS (mask_, ACE_Event_Handler::READ_MASK  | ACE_Event_Handler::WRITE_MASK); reactor ()->register_handler (this, mask_); } ,[object Object],[object Object],[object Object]
Sidebar: Tracking Event Handler Registrations (2/2) virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask mask)  { if (mask == ACE_Event_Handler::READ_MASK) { ACE_CLR_BITS (mask_, ACE_Event_Handler::READ_MASK); // Perform READ_MASK cleanup logic... }  if (mask == ACE_Event_Handler::WRITE_MASK) { ACE_CLR_BITS (mask_, ACE_Event_Handler::WRITE_MASK); // Perform WRITE_MASK cleanup logic. } if (mask_ == 0) delete this; return 0; } ,[object Object],[object Object],[object Object]
Using the ACE_Event_Handler Class (1/8) ,[object Object],[object Object],[object Object],Logging  Event  Handler Logging  Event  Handler Logging  Acceptor ACE_Reactor
Using the ACE_Event_Handler Class (2/8) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the ACE_Event_Handler Class (3/8) class Logging_Acceptor : public ACE_Event_Handler { private: // Factory that connects <ACE_SOCK_Stream>s passively. ACE_SOCK_Acceptor acceptor_; public: // Simple constructor. Logging_Acceptor (ACE_Reactor *r = ACE_Reactor::instance ()) : ACE_Event_Handler (r) {} // Initialization method. virtual int open (const ACE_INET_Addr &local_addr); // Called by a reactor when there's a new connection to accept. virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE); ,[object Object],Note default use of reactor singleton   Key hook method dispatched by reactor
Sidebar: Singleton Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Be careful using Singleton – it can cause tightly coupled designs!
Using the ACE_Event_Handler Class (4/8) virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = 0); // Return the passive-mode socket's I/O handle. virtual ACE_HANDLE get_handle () const { return acceptor_.get_handle (); } }; int Logging_Acceptor::open (const ACE_INET_Addr &local_addr) { if (acceptor_.open (local_addr) == -1) return -1; return reactor ()->register_handler (this, ACE_Event_Handler::ACCEPT_MASK); } int Logging_Acceptor::handle_close (ACE_HANDLE,  ACE_Reactor_Mask) {  acceptor_.close (); delete this; return 0;  } Register ourselves with the reactor for accept events It’s ok to “delete this” in this context! Hook method called when object removed from Reactor
Using the ACE_Event_Handler Class (5/8) class Logging_Event_Handler : public ACE_Event_Handler { protected: // File where log records are written. ACE_FILE_IO log_file_; Logging_Handler logging_handler_; // Connection to remote peer. public: // Initialize the base class & logging handler. Logging_Event_Handler (ACE_Reactor *r) : ACE_Event_Handler (r), logging_handler_ (log_file_) {} virtual int open (); // Activate the object. // Called by a reactor when logging events arrive. virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE); // Called by a reactor when handler is closing. virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask); }; ,[object Object],Key hook method dispatched by reactor
Using the ACE_Event_Handler Class (6/8) 1 int Logging_Acceptor::handle_input (ACE_HANDLE) { 2  Logging_Event_Handler *peer_handler = 0; 3  ACE_NEW_RETURN (peer_handler, 4  Logging_Event_Handler (reactor ()), -1); 5  if (acceptor_.accept (peer_handler->peer ()) == -1) { 6  delete peer_handler; 7  return -1; 8  } else if (peer_handler->open () == -1) { 9  peer_handler->handle_close (); 10  return -1; 11  } 12  return 0; 13 } Factory method called back by reactor when a connection event occurs
Sidebar: ACE Memory Management Macros ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the ACE_Event_Handler Class (7/8) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Register with the reactor for input events Create the log file
Using the ACE_Event_Handler Class (8/8) int Logging_Event_Handler::handle_input (ACE_HANDLE)  {  return logging_handler_.log_record ();  } int Logging_Event_Handler::handle_close (ACE_HANDLE,  ACE_Reactor_Mask)  { logging_handler_.close (); log_file_.close (); delete this; return 0; } Called back by the reactor when a data event occurs Called back by the reactor when  handle_input()  returns  -1 Returns  -1  when client closes connection
Sidebar: Event Handler Memory Management (1/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: Event Handler Memory Management (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: Handling Silent Peers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE Timer Queue Classes (1/2) ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE Timer Queue Classes (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE Timer Queue Classes API This class handles  variability  of timer queue mechanisms via a  common  timer queue API
Scheduling ACE_Event_Handler for Timeouts ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Asynchronous Completion Token Pattern Structure & Participants ,[object Object],[object Object],schedule() ACE_Timer_Queue ACE_Event_Handler handle_timeout() Timer Queue Impl ,[object Object]
The Asynchronous Completion Token Pattern ,[object Object],ACE_Timer_Queue ACE_Event_Handler Timer Queue Impl handle_timeout() ,[object Object],Dynamic Interactions
Sidebar: ACE Time Sources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the ACE Timer Classes (1/4) class Logging_Acceptor_Ex : public Logging_Acceptor { public: typedef ACE_INET_Addr PEER_ADDR; // Simple constructor to pass <ACE_Reactor> to base class. Logging_Acceptor_Ex (ACE_Reactor *r = ACE_Reactor::instance ()) : Logging_Acceptor (r) {} int handle_input (ACE_HANDLE) { Logging_Event_Handler_Ex *peer_handler = 0; ACE_NEW_RETURN (peer_handler, Logging_Event_Handler_Ex (reactor ()), -1); // ... same as Logging_Acceptor::handle_input() } }; ,[object Object],[object Object],Only difference (variability) is the event handler type…
Using the ACE Timer Classes (2/4) class Logging_Event_Handler_Ex : public Logging_Event_Handler  { private: // Time when a client last sent a log record. ACE_Time_Value time_of_last_log_record_; // Maximum time to wait for a client log record. const ACE_Time_Value max_client_timeout_; public: typedef Logging_Event_Handler PARENT; // 3600 seconds == one hour. enum { MAX_CLIENT_TIMEOUT = 3600 }; Logging_Event_Handler_Ex  (ACE_Reactor *reactor, const ACE_Time_Value &max_client_timeout = ACE_Time_Value (MAX_CLIENT_TIMEOUT)) : Logging_Event_Handler (reactor), time_of_last_log_record (0), max_client_timeout_ (max_client_timeout) {}
Using the ACE Timer Classes (3/4) virtual int open (); // Activate the event handler. // Called by a reactor when logging events arrive. virtual int handle_input (ACE_HANDLE); // Called when a timeout expires to check if the client has // been idle for an excessive amount of time. virtual int handle_timeout (const ACE_Time_Value &tv, const void *act); }; 1 int Logging_Event_Handler_Ex::open () { 2  int result = PARENT::open (); 3  if (result != -1) { 4  ACE_Time_Value reschedule (max_client_timeout_.sec () / 4); 5  result = reactor ()->schedule_timer 6  (this, 0, 7  max_client_timeout_,  // Initial timeout. 8  reschedule);  // Subsequent timeouts. 9  } 10  return result; 11 } Creates an interval timer that fires every 15 minutes
Using the ACE Timer Classes (4/4) int Logging_Event_Handler_Ex::handle_input (ACE_HANDLE h)  { time_of_last_log_record_ = reactor ()->timer_queue ()->gettimeofday (); return PARENT::handle_input (h); } int Logging_Event_Handler_Ex::handle_timeout (const ACE_Time_Value &now, const void *)  { if (now - time_of_last_log_record_ >= max_client_timeout_) reactor ()->remove_handler (this, ACE_Event_Handler::READ_MASK); return 0; } Log the last time this client was active Evict the handler if client has been inactive too long
Sidebar: Using Timers in Real-time Apps ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: Minimizing ACE Timer Queue   Memory Allocation  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_Reactor Class (1/2) ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_Reactor Class (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_Reactor Class API This class handles  variability  of synchronous event demuxing mechanisms via a  common  API
Using the ACE_Reactor Class (1/4) template <class ACCEPTOR> class Reactor_Logging_Server : public ACCEPTOR { public: Reactor_Logging_Server (int argc, char *argv[], ACE_Reactor *); }; ,[object Object],Reactor Wrapper Facade Acceptor/Connector
Using the ACE_Reactor Class (2/4) Sequence Diagram for Reactive Logging Server
Using the ACE_Reactor Class (3/4) 1 template <class ACCEPTOR> 2 Reactor_Logging_Server<ACCEPTOR>::Reactor_Logging_Server 3  (int argc, char *argv[], ACE_Reactor *reactor) 4  : ACCEPTOR (reactor) { 5  u_short logger_port = argc > 1 ? atoi (argv[1]) : 0; 6  ACE_TYPENAME ACCEPTOR::PEER_ADDR server_addr; 7  int result; 8 9  if (logger_port != 0) 10  result = server_addr.set (logger_port, INADDR_ANY); 11  else 12  result = server_addr.set (&quot;ace_logger&quot;, INADDR_ANY); 13  if (result != -1)  14  result = ACCEPTOR::open (server_addr); 15  if (result == -1) reactor->end_reactor_event_loop (); 16 } Shutdown the reactor’s event loop if an error occurs
Using the ACE_Reactor Class (4/4) 1 typedef Reactor_Logging_Server<Logging_Acceptor_Ex>  2  Server_Logging_Daemon; 3  4 int main (int argc, char *argv[]) { 5  ACE_Reactor reactor; 6  Server_Logging_Daemon *server = 0; 7  ACE_NEW_RETURN (server, 8  Server_Logging_Daemon (argc, argv, &reactor), 9  1); 10 11  if (reactor.run_reactor_event_loop () == -1) 12  ACE_ERROR_RETURN ((LM_ERROR, &quot;%p&quot;, 13  &quot;run_reactor_event_loop()&quot;), 1); 14  return 0; 15 } Dynamic allocation ensures proper deletion semantics
Sidebar: Avoiding Reactor Deadlock  in Multithreaded Applications (1/2) ,[object Object],[object Object],[object Object],[object Object]
Sidebar: Avoiding Reactor Deadlock  in Multithreaded Applications (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ACE Reactor Implementations (1/2) ,[object Object],[object Object],[object Object]
ACE Reactor Implementations (2/2) ,[object Object],[object Object],[object Object],[object Object]
The ACE_Select_Reactor Class (1/2) ,[object Object],[object Object],[object Object],[object Object],int select (int width,  // Maximum handle plus 1 fd_set *read_fds,  // Set of &quot;read&quot; handles fd_set *write_fds,  // Set of &quot;write&quot; handles fd_set *except_fds,  // Set of &quot;exception&quot; handles struct timeval *timeout);// Time to wait for events
The ACE_Select_Reactor Class (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_Select_Reactor Class API
Sidebar: Controlling the Size of ACE_Select_Reactor (1/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: Controlling the Size of ACE_Select_Reactor (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_Select_Reactor Notification Mechanism ,[object Object],[object Object],[object Object]
The ACE_Select_Reactor Notification Mechanism ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: The ACE_Token Class (1/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: The ACE_Token Class (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the ACE_Select_Reactor Class (1/4) 7 // Forward declarations. 8 ACE_THR_FUNC_RETURN controller (void *); 9 ACE_THR_FUNC_RETURN event_loop (void *); 10 11 typedef Reactor_Logging_Server<Logging_Acceptor_Ex>  12  Server_Logging_Daemon; 13 ,[object Object]
Using the ACE_Select_Reactor Class (2/4) 14 int main (int argc, char *argv[]) { 15  ACE_Select_Reactor select_reactor; 16  ACE_Reactor reactor (&select_reactor); 17 18  Server_Logging_Daemon *server = 0; 19  ACE_NEW_RETURN (server, 20  Server_Logging_Daemon (argc, argv, &reactor), 21  1); 22  ACE_Thread_Manager::instance()->spawn (event_loop, &reactor); 23  ACE_Thread_Manager::instance()->spawn (controller, &reactor); 24  return ACE_Thread_Manager::instance ()->wait (); 25 } static ACE_THR_FUNC_RETURN event_loop (void *arg) { ACE_Reactor *reactor = ACE_static_cast (ACE_Reactor *, arg); reactor->owner (ACE_OS::thr_self ()); reactor->run_reactor_event_loop (); return 0; } Ensure we get the  ACE_Select_Reactor Barrier synchronization Become “owner” (only needed for  ACE_Select_Reactor )
Using the ACE_Select_Reactor Class (3/4) 1 static ACE_THR_FUNC_RETURN controller (void *arg) { 2  ACE_Reactor *reactor = ACE_static_cast (ACE_Reactor *, arg); 3  Quit_Handler *quit_handler = 0; 4  ACE_NEW_RETURN (quit_handler, Quit_Handler (reactor), 0); 5 6  for (;;) { 7  std::string user_input; 8  std::getline (cin, user_input, ''); 9  if (user_input == &quot;quit&quot;) { 10  reactor->notify (quit_handler); 11  break; 12  } 13  } 14  return 0; 15 } Use the notify pipe to wakeup the reactor & inform it to shut down by calling  handle_exception() Runs in a separate thread of control
Using the ACE_Select_Reactor Class (4/4) class Quit_Handler : public ACE_Event_Handler { public: Quit_Handler (ACE_Reactor *r): ACE_Event_Handler (r) {} virtual int handle_exception (ACE_HANDLE) { reactor ()->end_reactor_event_loop (); return -1;  } virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask)  {  delete this;  return 0;  } private: // Private destructor ensures dynamic allocation. virtual ~Quit_Handler () {} }; Trigger call to handle_close() method It’s ok to “delete this” in this context
Sidebar: Avoiding Reactor Notification Deadlock ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: Enlarging ACE_Select_Reactor’s Notifications ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Leader/Followers Pattern This pattern eliminates the need for—& the overhead of—a separate Reactor thread & synchronized request queue used in the Half-Sync/Half-Async pattern The Leader/Followers architectural pattern (P2) provides an efficient concurrency model where multiple threads take turns sharing event sources to detect, demux, dispatch, & process service requests that occur on the event sources TCP Sockets +  select() / poll() UDP Sockets +  select() / poll() Iterative  Handle Sets TCP Sockets +  WaitForMultpleObjects() UDP Sockets +  WaitForMultipleObjects() Concurrent  Handle Sets Iterative Handles Concurrent Handles Handles Handle Sets Handle uses demultiplexes * * Handle Set handle_events() deactivate_handle() reactivate_handle() select() Event Handler handle_event () get_handle() Concrete Event Handler B handle_event () get_handle() Concrete Event Handler A handle_event () get_handle() Thread Pool join() promote_new_leader() synchronizer
Leader/Followers Pattern Dynamics handle_events() new_leader() ,[object Object],[object Object],[object Object],[object Object],promote_ : Concrete Event Handler join() handle_event() : Thread Pool  : Handle Set join() thread 2 sleeps until it becomes the leader event thread 1 sleeps until it becomes the leader deactivate_ handle() join() Thread 1 Thread 2 handle_ events() reactivate_ handle() handle_event() event thread 2 waits for a new event, thread 1 processes current event deactivate_ handle()
Pros & Cons of Leader/Followers Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_TP_Reactor Class (1/2) ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_TP_Reactor Class (2/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_TP_Reactor Class API
Pros & Cons of ACE_TP_Reactor ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the ACE_TP_Reactor Class (1/2) 1 #include &quot;ace/streams.h&quot; 2 #include &quot;ace/Reactor.h&quot; 3 #include &quot;ace/TP_Reactor.h&quot; 4 #include &quot;ace/Thread_Manager.h“ 5 #include &quot;Reactor_Logging_Server.h&quot; 6 #include <string> 7 // Forward declarations 8 ACE_THR_FUNC_RETURN controller (void *); 9 ACE_THR_FUNC_RETURN event_loop (void *); 10 11 typedef Reactor_Logging_Server<Logging_Acceptor_Ex>  12  Server_Logging_Daemon; 13 ,[object Object],Note reuse
Using the ACE_TP_Reactor Class (2/2) 14 int main (int argc, char *argv[]) { 15  const size_t N_THREADS = 4; 16  ACE_TP_Reactor tp_reactor; 17  ACE_Reactor reactor (&tp_reactor); 18  auto_ptr<ACE_Reactor> delete_instance 19  (ACE_Reactor::instance (&reactor)); 20 21  Server_Logging_Daemon *server = 0; 22  ACE_NEW_RETURN (server, 23  Server_Logging_Daemon (argc, argv, 24  ACE_Reactor::instance ()), 1); 25  ACE_Thread_Manager::instance ()->spawn_n 26  (N_THREADS, event_loop, ACE_Reactor::instance ()); 27  ACE_Thread_Manager::instance ()->spawn 28  (controller, ACE_Reactor::instance ()); 29  return ACE_Thread_Manager::instance ()->wait (); 30 } Spawn multiple threads Ensure we get the ACE_TP_Reactor
The ACE_WFMO_Reactor Class (1/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE_WFMO_Reactor Class (2/2) ,[object Object],[object Object],[object Object],[object Object]
The ACE_WFMO_Reactor Class API
Sidebar: The WaitForMultipleObjects() Function ,[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: Why ACE_WFMO_Reactor is Windows Default ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the ACE_WFMO_Reactor Class (1/5) class Quit_Handler : public ACE_Event_Handler { private: // Keep track of when to shutdown. ACE_Manual_Event quit_seen_;  public: 1 Quit_Handler (ACE_Reactor *r): ACE_Event_Handler (r) { 2  SetConsoleMode (ACE_STDIN, 3  ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT 4  | ENABLE_PROCESSED_INPUT); 5  if (reactor ()->register_handler 6  (this, quit_seen_.handle ()) == -1 7  || ACE_Event_Handler::register_stdin_handler 8  (this, r, ACE_Thread_Manager::instance ()) == -1) 9  r->end_reactor_event_loop (); 10 } This method only works on Windows
Sidebar: ACE_Manual_Event & ACE_Auto_Event ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the ACE_WFMO_Reactor Class (2/5) virtual int handle_input (ACE_HANDLE h) { CHAR user_input[BUFSIZ]; DWORD count; if (!ReadFile (h, user_input, BUFSIZ, &count, 0)) return -1; user_input[count] = ''; if (ACE_OS_String::strncmp (user_input, &quot;quit&quot;, 4) == 0) return -1; return 0; } virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask)  { quit_seen_.signal (); return 0; } virtual int handle_signal (int, siginfo_t *, ucontext_t *)  { reactor ()->end_reactor_event_loop (); return 0; } 1 ~Quit_Handler () { 2  ACE_Event_Handler::remove_stdin_handler 3  (reactor (), ACE_Thread_Manager::instance ()); 4  reactor ()->remove_handler (quit_seen_.handle (), 5  ACE_Event_Handler::DONT_CALL); 6 } This hook method is called when a handle is signaled This is a Windows-specific function
Using the ACE_WFMO_Reactor Class (3/5) class Logging_Event_Handler_WFMO : public Logging_Event_Handler_Ex { public: Logging_Event_Handler_WFMO (ACE_Reactor *r) : Logging_Event_Handler_Ex (r) {} protected: int handle_input (ACE_HANDLE h) { ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, monitor, lock_, -1); return logging_handler_.log_record (); } ACE_Thread_Mutex lock_; // Serialize threads in thread pool. }; We need a lock since the  ACE_WFMO_Reactor  doesn’t suspend handles…
Sidebar: Why ACE_WFMO_Reactor Doesn’t Suspend Handlers (1/2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sidebar: Why ACE_WFMO_Reactor Doesn’t Suspend Handlers (2/2) ,[object Object],[object Object],[object Object],[object Object]
Using the ACE_WFMO_Reactor Class (4/5) class Logging_Acceptor_WFMO : public Logging_Acceptor_Ex { public: Logging_Acceptor_WFMO (ACE_Reactor *r = ACE_Reactor::instance ()) : Logging_Acceptor_Ex (r) {} protected: virtual int handle_input (ACE_HANDLE) { Logging_Event_Handler_WFMO *peer_handler = 0; ACE_NEW_RETURN (peer_handler, Logging_Event_Handler_WFMO (reactor ()), -1); if (acceptor_.accept (peer_handler->peer ()) == -1)  { delete peer_handler; return -1; }  else if (peer_handler->open () == -1)  { peer_handler->handle_close (); return -1; } return 0; } }; Note the canonical (common) form of this hook method
Using the ACE_WFMO_Reactor Class (5/5) ACE_THR_FUNC_RETURN event_loop (void *); // Forward declaration. typedef Reactor_Logging_Server<Logging_Acceptor_WFMO> Server_Logging_Daemon; int main (int argc, char *argv[]) { const size_t N_THREADS = 4; ACE_WFMO_Reactor wfmo_reactor; ACE_Reactor reactor (&wfmo_reactor); Server_Logging_Daemon *server = 0; ACE_NEW_RETURN (server, Server_Logging_Daemon (argc, argv, &reactor), 1); Quit_Handler quit_handler (&reactor); ACE_Thread_Manager::instance ()->spawn_n (N_THREADS, event_loop, &reactor); return ACE_Thread_Manager::instance ()->wait (); } Main program  Ensure we get the  ACE_WFMO_Reactor Constructor registers with reactor Barrier synchronization
Other Reactors Supported By ACE ,[object Object],[object Object],[object Object]
Challenges of Using Frameworks Effectively ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],www.cs.wustl.edu/~schmidt/PDF/Queue-04.pdf
Determining Framework Applicability & Quality ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Evaluating Economics of Frameworks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Effective Framework Debugging Techniques ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Identify Framework Time & Space Overheads ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Evaluating Effort of Developing New Framework ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Knowledge of patterns is essential!
Challenges of Using Frameworks Effectively ,[object Object],[object Object],[object Object],[object Object],Successful projects are therefore often organized using the “funnel” model
Configuration Design Dimensions ,[object Object],[object Object],[object Object],[object Object],[object Object]
Static vs. Dynamic Linking & Configuration ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE Service Configuration Framework ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ACE Service Configuration Framework ,[object Object],[object Object]
The Component Configurator Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Logger Processing Conn Mgmt Memory Mgmt Threading Demuxing File System I/O
The Component Configurator Pattern ,[object Object],[object Object],[object Object],[object Object]
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2
C++ N Pv2

Más contenido relacionado

La actualidad más candente

JDC2008 - Enterprise Integration and Service Oriented Design
JDC2008 - Enterprise Integration and Service Oriented DesignJDC2008 - Enterprise Integration and Service Oriented Design
JDC2008 - Enterprise Integration and Service Oriented DesignHossam Karim
 
A pattern based approach to the development of updm architectures
A pattern based approach to the development of updm architecturesA pattern based approach to the development of updm architectures
A pattern based approach to the development of updm architecturesGraham Bleakley
 
Agile in Action - Act 2: Development
Agile in Action - Act 2: DevelopmentAgile in Action - Act 2: Development
Agile in Action - Act 2: DevelopmentSpiffy
 
MY NEWEST RESUME
MY NEWEST RESUMEMY NEWEST RESUME
MY NEWEST RESUMEHan Yan
 
Practical DoDAF Presentation to INCOSE WMA
Practical DoDAF Presentation to INCOSE WMA Practical DoDAF Presentation to INCOSE WMA
Practical DoDAF Presentation to INCOSE WMA Elizabeth Steiner
 
IBM Rhapsody and MATLAB/Simulink
IBM Rhapsody and MATLAB/SimulinkIBM Rhapsody and MATLAB/Simulink
IBM Rhapsody and MATLAB/Simulinkgjuljo
 
M3 Modernization Case Study
M3 Modernization Case StudyM3 Modernization Case Study
M3 Modernization Case StudyADC Austin Tech
 
IBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt IntegrationIBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt Integrationgjuljo
 
DOD EA conference DoDAF in Action
DOD EA conference DoDAF in ActionDOD EA conference DoDAF in Action
DOD EA conference DoDAF in ActionPaul W. Johnson
 
SQL Server Modernization
SQL Server ModernizationSQL Server Modernization
SQL Server ModernizationGianluca Hotz
 
Sa 006 modifiability
Sa 006 modifiabilitySa 006 modifiability
Sa 006 modifiabilityFrank Gielen
 
MyMobileWeb Certification Part IV
MyMobileWeb Certification Part IVMyMobileWeb Certification Part IV
MyMobileWeb Certification Part IVcrdlc
 
Ronald E Curry (3)
Ronald E Curry (3)Ronald E Curry (3)
Ronald E Curry (3)rcurry720
 
Rhapsody Eclipse
Rhapsody EclipseRhapsody Eclipse
Rhapsody EclipseBill Duncan
 
Chapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration TechnologiesChapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration TechnologiesIt Academy
 

La actualidad más candente (20)

JDC2008 - Enterprise Integration and Service Oriented Design
JDC2008 - Enterprise Integration and Service Oriented DesignJDC2008 - Enterprise Integration and Service Oriented Design
JDC2008 - Enterprise Integration and Service Oriented Design
 
A pattern based approach to the development of updm architectures
A pattern based approach to the development of updm architecturesA pattern based approach to the development of updm architectures
A pattern based approach to the development of updm architectures
 
Agile in Action - Act 2: Development
Agile in Action - Act 2: DevelopmentAgile in Action - Act 2: Development
Agile in Action - Act 2: Development
 
MY NEWEST RESUME
MY NEWEST RESUMEMY NEWEST RESUME
MY NEWEST RESUME
 
Practical DoDAF Presentation to INCOSE WMA
Practical DoDAF Presentation to INCOSE WMA Practical DoDAF Presentation to INCOSE WMA
Practical DoDAF Presentation to INCOSE WMA
 
IBM Rhapsody and MATLAB/Simulink
IBM Rhapsody and MATLAB/SimulinkIBM Rhapsody and MATLAB/Simulink
IBM Rhapsody and MATLAB/Simulink
 
M3 Modernization Case Study
M3 Modernization Case StudyM3 Modernization Case Study
M3 Modernization Case Study
 
IBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt IntegrationIBM Rational Rhapsody and Qt Integration
IBM Rational Rhapsody and Qt Integration
 
DOD EA conference DoDAF in Action
DOD EA conference DoDAF in ActionDOD EA conference DoDAF in Action
DOD EA conference DoDAF in Action
 
SQL Server Modernization
SQL Server ModernizationSQL Server Modernization
SQL Server Modernization
 
Sa 006 modifiability
Sa 006 modifiabilitySa 006 modifiability
Sa 006 modifiability
 
MyMobileWeb Certification Part IV
MyMobileWeb Certification Part IVMyMobileWeb Certification Part IV
MyMobileWeb Certification Part IV
 
Ronald E Curry (3)
Ronald E Curry (3)Ronald E Curry (3)
Ronald E Curry (3)
 
Rmi
RmiRmi
Rmi
 
Rhapsody Eclipse
Rhapsody EclipseRhapsody Eclipse
Rhapsody Eclipse
 
Chapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration TechnologiesChapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration Technologies
 
Composite Application Library, Prism v2
Composite Application Library, Prism v2Composite Application Library, Prism v2
Composite Application Library, Prism v2
 
Software Engineering 101
Software Engineering 101Software Engineering 101
Software Engineering 101
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
FormFlow
FormFlowFormFlow
FormFlow
 

Destacado

Гибридные DVB-C + IP решения для операторов кабельного цифрового телевидения
Гибридные DVB-C + IP решения для операторов кабельного цифрового телевиденияГибридные DVB-C + IP решения для операторов кабельного цифрового телевидения
Гибридные DVB-C + IP решения для операторов кабельного цифрового телевиденияDenis Mishin
 
Individual and environment
Individual and environmentIndividual and environment
Individual and environmentSonia Mileva
 
Yabwap for VCCS
Yabwap for VCCSYabwap for VCCS
Yabwap for VCCSccosmato
 
Introductie Web 2.0
Introductie Web 2.0Introductie Web 2.0
Introductie Web 2.0Ivo Jansch
 
Using ICT Volunteers
Using ICT VolunteersUsing ICT Volunteers
Using ICT Volunteershavs
 
Presentation to CIPR local public services conference - October 2009
Presentation to CIPR local public services conference - October 2009Presentation to CIPR local public services conference - October 2009
Presentation to CIPR local public services conference - October 2009simonwakeman
 
Publizitatearen Historia3 (1/3)
Publizitatearen Historia3 (1/3)Publizitatearen Historia3 (1/3)
Publizitatearen Historia3 (1/3)katixa
 
Qt编程介绍
Qt编程介绍Qt编程介绍
Qt编程介绍easychen
 
Ict4volunteering Vb3
Ict4volunteering Vb3Ict4volunteering Vb3
Ict4volunteering Vb3havs
 
3rd Annual Souper Bowl
3rd Annual Souper Bowl3rd Annual Souper Bowl
3rd Annual Souper Bowlburnsc62
 
DataWikiを実現するWedataの構築と運用
DataWikiを実現するWedataの構築と運用DataWikiを実現するWedataの構築と運用
DataWikiを実現するWedataの構築と運用Koichiro Eto
 
10th Ceepus – Biomedicine Students’ Council Summer Eng
10th Ceepus – Biomedicine Students’ Council Summer Eng10th Ceepus – Biomedicine Students’ Council Summer Eng
10th Ceepus – Biomedicine Students’ Council Summer EngSU07
 
Jörissen, Benjamin (2009, Manuskript). Games, reflexivity, and governance
Jörissen, Benjamin (2009, Manuskript). Games, reflexivity, and governanceJörissen, Benjamin (2009, Manuskript). Games, reflexivity, and governance
Jörissen, Benjamin (2009, Manuskript). Games, reflexivity, and governanceBenjamin Jörissen
 

Destacado (20)

Гибридные DVB-C + IP решения для операторов кабельного цифрового телевидения
Гибридные DVB-C + IP решения для операторов кабельного цифрового телевиденияГибридные DVB-C + IP решения для операторов кабельного цифрового телевидения
Гибридные DVB-C + IP решения для операторов кабельного цифрового телевидения
 
test2
test2test2
test2
 
Individual and environment
Individual and environmentIndividual and environment
Individual and environment
 
Yabwap for VCCS
Yabwap for VCCSYabwap for VCCS
Yabwap for VCCS
 
Introductie Web 2.0
Introductie Web 2.0Introductie Web 2.0
Introductie Web 2.0
 
华文书展
华文书展华文书展
华文书展
 
Using ICT Volunteers
Using ICT VolunteersUsing ICT Volunteers
Using ICT Volunteers
 
Presentation to CIPR local public services conference - October 2009
Presentation to CIPR local public services conference - October 2009Presentation to CIPR local public services conference - October 2009
Presentation to CIPR local public services conference - October 2009
 
Publizitatearen Historia3 (1/3)
Publizitatearen Historia3 (1/3)Publizitatearen Historia3 (1/3)
Publizitatearen Historia3 (1/3)
 
Rulang Cooling Robot
Rulang Cooling RobotRulang Cooling Robot
Rulang Cooling Robot
 
Qt编程介绍
Qt编程介绍Qt编程介绍
Qt编程介绍
 
Ict4volunteering Vb3
Ict4volunteering Vb3Ict4volunteering Vb3
Ict4volunteering Vb3
 
Pie Eating Contest
Pie Eating ContestPie Eating Contest
Pie Eating Contest
 
3rd Annual Souper Bowl
3rd Annual Souper Bowl3rd Annual Souper Bowl
3rd Annual Souper Bowl
 
Prezentacia
PrezentaciaPrezentacia
Prezentacia
 
DataWikiを実現するWedataの構築と運用
DataWikiを実現するWedataの構築と運用DataWikiを実現するWedataの構築と運用
DataWikiを実現するWedataの構築と運用
 
Flickr Justgiving & MOO
Flickr Justgiving & MOOFlickr Justgiving & MOO
Flickr Justgiving & MOO
 
10th Ceepus – Biomedicine Students’ Council Summer Eng
10th Ceepus – Biomedicine Students’ Council Summer Eng10th Ceepus – Biomedicine Students’ Council Summer Eng
10th Ceepus – Biomedicine Students’ Council Summer Eng
 
Jörissen, Benjamin (2009, Manuskript). Games, reflexivity, and governance
Jörissen, Benjamin (2009, Manuskript). Games, reflexivity, and governanceJörissen, Benjamin (2009, Manuskript). Games, reflexivity, and governance
Jörissen, Benjamin (2009, Manuskript). Games, reflexivity, and governance
 
Digital Storytelling
Digital StorytellingDigital Storytelling
Digital Storytelling
 

Similar a C++ N Pv2

Pattern-Oriented Distributed Software Architectures
Pattern-Oriented Distributed Software Architectures Pattern-Oriented Distributed Software Architectures
Pattern-Oriented Distributed Software Architectures David Freitas
 
Enterprise Software Architecture
Enterprise Software ArchitectureEnterprise Software Architecture
Enterprise Software Architecturerahmed_sct
 
Unit 3-SOA Technologies
Unit 3-SOA TechnologiesUnit 3-SOA Technologies
Unit 3-SOA Technologiesssuser3a47cb
 
Service Oriented Development With Windows Communication Foundation 2003
Service Oriented Development With Windows Communication Foundation 2003Service Oriented Development With Windows Communication Foundation 2003
Service Oriented Development With Windows Communication Foundation 2003Jason Townsend, MBA
 
Experiences with Oracle WebCenter 11g: Implementing SOA with a User Interface
Experiences with Oracle WebCenter 11g: Implementing SOA with a User InterfaceExperiences with Oracle WebCenter 11g: Implementing SOA with a User Interface
Experiences with Oracle WebCenter 11g: Implementing SOA with a User InterfaceLucas Jellema
 
Introduction to SOFTWARE ARCHITECTURE
Introduction to SOFTWARE ARCHITECTUREIntroduction to SOFTWARE ARCHITECTURE
Introduction to SOFTWARE ARCHITECTUREIvano Malavolta
 
10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural stylesMajong DevJfu
 
Interoperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewInteroperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewJorgen Thelin
 
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...MSDEVMTL
 
Cloud native integration
Cloud native integrationCloud native integration
Cloud native integrationKim Clark
 
Notes On Software Development, Platform And Modernisation
Notes On Software Development, Platform And ModernisationNotes On Software Development, Platform And Modernisation
Notes On Software Development, Platform And ModernisationAlan McSweeney
 
COMPRO- WEB ALBUM & MOTION ANALYZER
COMPRO- WEB ALBUM  & MOTION ANALYZERCOMPRO- WEB ALBUM  & MOTION ANALYZER
COMPRO- WEB ALBUM & MOTION ANALYZERAshish Tanwer
 
What’s new in Rational collaborative lifecycle management 2011?
What’s new in Rational collaborative lifecycle management 2011?What’s new in Rational collaborative lifecycle management 2011?
What’s new in Rational collaborative lifecycle management 2011?IBM Danmark
 
Windows Azure AppFabric
Windows Azure AppFabricWindows Azure AppFabric
Windows Azure AppFabricDavid Chou
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksSunil Patil
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworksSunil Patil
 

Similar a C++ N Pv2 (20)

Pattern-Oriented Distributed Software Architectures
Pattern-Oriented Distributed Software Architectures Pattern-Oriented Distributed Software Architectures
Pattern-Oriented Distributed Software Architectures
 
soa1.ppt
soa1.pptsoa1.ppt
soa1.ppt
 
Enterprise Software Architecture
Enterprise Software ArchitectureEnterprise Software Architecture
Enterprise Software Architecture
 
Unit 3-SOA Technologies
Unit 3-SOA TechnologiesUnit 3-SOA Technologies
Unit 3-SOA Technologies
 
Dot net training bangalore
Dot net training bangaloreDot net training bangalore
Dot net training bangalore
 
Service Oriented Development With Windows Communication Foundation 2003
Service Oriented Development With Windows Communication Foundation 2003Service Oriented Development With Windows Communication Foundation 2003
Service Oriented Development With Windows Communication Foundation 2003
 
Experiences with Oracle WebCenter 11g: Implementing SOA with a User Interface
Experiences with Oracle WebCenter 11g: Implementing SOA with a User InterfaceExperiences with Oracle WebCenter 11g: Implementing SOA with a User Interface
Experiences with Oracle WebCenter 11g: Implementing SOA with a User Interface
 
Introduction to SOFTWARE ARCHITECTURE
Introduction to SOFTWARE ARCHITECTUREIntroduction to SOFTWARE ARCHITECTURE
Introduction to SOFTWARE ARCHITECTURE
 
10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles
 
Interoperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewInteroperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) Overview
 
Introduction To Cloud Computing
Introduction To Cloud ComputingIntroduction To Cloud Computing
Introduction To Cloud Computing
 
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
 
Si so product 1 day technical
Si so product 1 day technicalSi so product 1 day technical
Si so product 1 day technical
 
Cloud native integration
Cloud native integrationCloud native integration
Cloud native integration
 
Notes On Software Development, Platform And Modernisation
Notes On Software Development, Platform And ModernisationNotes On Software Development, Platform And Modernisation
Notes On Software Development, Platform And Modernisation
 
COMPRO- WEB ALBUM & MOTION ANALYZER
COMPRO- WEB ALBUM  & MOTION ANALYZERCOMPRO- WEB ALBUM  & MOTION ANALYZER
COMPRO- WEB ALBUM & MOTION ANALYZER
 
What’s new in Rational collaborative lifecycle management 2011?
What’s new in Rational collaborative lifecycle management 2011?What’s new in Rational collaborative lifecycle management 2011?
What’s new in Rational collaborative lifecycle management 2011?
 
Windows Azure AppFabric
Windows Azure AppFabricWindows Azure AppFabric
Windows Azure AppFabric
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source Frameworks
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
 

Último

(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607dollysharma2066
 
Darshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdfDarshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdfShashank Mehta
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Riya Pathan
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckHajeJanKamps
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy Verified Accounts
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environmentelijahj01012
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMintel Group
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfRbc Rbcua
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdfKhaled Al Awadi
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Kirill Klimov
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfrichard876048
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?Olivia Kresic
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607dollysharma2066
 
TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024Adnet Communications
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCRashishs7044
 
Entrepreneurship lessons in Philippines
Entrepreneurship lessons in  PhilippinesEntrepreneurship lessons in  Philippines
Entrepreneurship lessons in PhilippinesDavidSamuel525586
 
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptxThe-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptxmbikashkanyari
 
8447779800, Low rate Call girls in Dwarka mor Delhi NCR
8447779800, Low rate Call girls in Dwarka mor Delhi NCR8447779800, Low rate Call girls in Dwarka mor Delhi NCR
8447779800, Low rate Call girls in Dwarka mor Delhi NCRashishs7044
 

Último (20)

(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
 
Darshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdfDarshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdf
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail Accounts
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environment
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 Edition
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdf
 
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCREnjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdf
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
 
TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
 
Entrepreneurship lessons in Philippines
Entrepreneurship lessons in  PhilippinesEntrepreneurship lessons in  Philippines
Entrepreneurship lessons in Philippines
 
Japan IT Week 2024 Brochure by 47Billion (English)
Japan IT Week 2024 Brochure by 47Billion (English)Japan IT Week 2024 Brochure by 47Billion (English)
Japan IT Week 2024 Brochure by 47Billion (English)
 
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptxThe-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
 
8447779800, Low rate Call girls in Dwarka mor Delhi NCR
8447779800, Low rate Call girls in Dwarka mor Delhi NCR8447779800, Low rate Call girls in Dwarka mor Delhi NCR
8447779800, Low rate Call girls in Dwarka mor Delhi NCR
 

C++ N Pv2

  • 1. C++ Network Programming Systematic Reuse with ACE & Frameworks Dr. Douglas C. Schmidt [email_address] www.dre.vanderbilt.edu/~schmidt/ Professor of EECS Vanderbilt University Nashville, Tennessee
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. Taxonomy of Reuse Techniques Class Libraries Frameworks Macro-level Meso-level Micro-level Borrow caller’s thread Inversion of control Borrow caller’s thread Domain-specific or Domain-independent Domain-specific Domain-independent Stand-alone composition entities “ Semi-complete” applications Stand-alone language entities Components
  • 14. The Frameworks in ACE Acceptor Connector Component Configurator Stream Reactor Proactor Task Application- specific functionality ACE frameworks are a product-line architecture for domain of network applications Calls back to service handlers to initialize them after they are connected Acceptor/Connector Inversion of Control & Hook Methods ACE Framework Calls back to initialize & finalize tasks when they are pushed & popped from a stream Streams Calls back to an application-supplied hook method to perform processing in one or more threads of control Task Calls back to application-supplied service objects to initialize, suspend, resume, & finalize them Service Configurator Calls back to application-supplied event handlers to perform processing when events occur synchronously & asynchronously Reactor & Proactor
  • 15.
  • 16.
  • 17.
  • 18. Patterns in the Networked Logging Service Reactor Acceptor- Connector Component Configurator Monitor Object Active Object Proactor Pipes & Filters Wrapper Facade Strategized Locking Scoped Locking Thread-safe Interface Half-Sync/ Half-Async Leader/ Followers
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34. The ACE_Time_Value Class API This class handles variability of time representation & manipulation across OS platforms via a common API
  • 35.
  • 36.
  • 37. Using the ACE_Time_Value Class (2/2) 17 if (interval > max_interval) 18 cout << &quot;interval must be less than &quot; 19 << max_interval.sec () << endl; 20 else if (expiration > (ACE_Time_Value::max_time - interval)) 21 cout << &quot;expiration + interval must be less than &quot; 22 << ACE_Time_Value::max_time.sec () << endl; 23 return 0; 24 } Note the use of relational operators
  • 38.
  • 39.
  • 40.
  • 41. The ACE_Event_Handler Class API This class handles variability of event processing behavior via a common event handler API
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51. Using the ACE_Event_Handler Class (4/8) virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = 0); // Return the passive-mode socket's I/O handle. virtual ACE_HANDLE get_handle () const { return acceptor_.get_handle (); } }; int Logging_Acceptor::open (const ACE_INET_Addr &local_addr) { if (acceptor_.open (local_addr) == -1) return -1; return reactor ()->register_handler (this, ACE_Event_Handler::ACCEPT_MASK); } int Logging_Acceptor::handle_close (ACE_HANDLE, ACE_Reactor_Mask) { acceptor_.close (); delete this; return 0; } Register ourselves with the reactor for accept events It’s ok to “delete this” in this context! Hook method called when object removed from Reactor
  • 52.
  • 53. Using the ACE_Event_Handler Class (6/8) 1 int Logging_Acceptor::handle_input (ACE_HANDLE) { 2 Logging_Event_Handler *peer_handler = 0; 3 ACE_NEW_RETURN (peer_handler, 4 Logging_Event_Handler (reactor ()), -1); 5 if (acceptor_.accept (peer_handler->peer ()) == -1) { 6 delete peer_handler; 7 return -1; 8 } else if (peer_handler->open () == -1) { 9 peer_handler->handle_close (); 10 return -1; 11 } 12 return 0; 13 } Factory method called back by reactor when a connection event occurs
  • 54.
  • 55.
  • 56. Using the ACE_Event_Handler Class (8/8) int Logging_Event_Handler::handle_input (ACE_HANDLE) { return logging_handler_.log_record (); } int Logging_Event_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) { logging_handler_.close (); log_file_.close (); delete this; return 0; } Called back by the reactor when a data event occurs Called back by the reactor when handle_input() returns -1 Returns -1 when client closes connection
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62. The ACE Timer Queue Classes API This class handles variability of timer queue mechanisms via a common timer queue API
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68. Using the ACE Timer Classes (2/4) class Logging_Event_Handler_Ex : public Logging_Event_Handler { private: // Time when a client last sent a log record. ACE_Time_Value time_of_last_log_record_; // Maximum time to wait for a client log record. const ACE_Time_Value max_client_timeout_; public: typedef Logging_Event_Handler PARENT; // 3600 seconds == one hour. enum { MAX_CLIENT_TIMEOUT = 3600 }; Logging_Event_Handler_Ex (ACE_Reactor *reactor, const ACE_Time_Value &max_client_timeout = ACE_Time_Value (MAX_CLIENT_TIMEOUT)) : Logging_Event_Handler (reactor), time_of_last_log_record (0), max_client_timeout_ (max_client_timeout) {}
  • 69. Using the ACE Timer Classes (3/4) virtual int open (); // Activate the event handler. // Called by a reactor when logging events arrive. virtual int handle_input (ACE_HANDLE); // Called when a timeout expires to check if the client has // been idle for an excessive amount of time. virtual int handle_timeout (const ACE_Time_Value &tv, const void *act); }; 1 int Logging_Event_Handler_Ex::open () { 2 int result = PARENT::open (); 3 if (result != -1) { 4 ACE_Time_Value reschedule (max_client_timeout_.sec () / 4); 5 result = reactor ()->schedule_timer 6 (this, 0, 7 max_client_timeout_, // Initial timeout. 8 reschedule); // Subsequent timeouts. 9 } 10 return result; 11 } Creates an interval timer that fires every 15 minutes
  • 70. Using the ACE Timer Classes (4/4) int Logging_Event_Handler_Ex::handle_input (ACE_HANDLE h) { time_of_last_log_record_ = reactor ()->timer_queue ()->gettimeofday (); return PARENT::handle_input (h); } int Logging_Event_Handler_Ex::handle_timeout (const ACE_Time_Value &now, const void *) { if (now - time_of_last_log_record_ >= max_client_timeout_) reactor ()->remove_handler (this, ACE_Event_Handler::READ_MASK); return 0; } Log the last time this client was active Evict the handler if client has been inactive too long
  • 71.
  • 72.
  • 73.
  • 74.
  • 75. The ACE_Reactor Class API This class handles variability of synchronous event demuxing mechanisms via a common API
  • 76.
  • 77. Using the ACE_Reactor Class (2/4) Sequence Diagram for Reactive Logging Server
  • 78. Using the ACE_Reactor Class (3/4) 1 template <class ACCEPTOR> 2 Reactor_Logging_Server<ACCEPTOR>::Reactor_Logging_Server 3 (int argc, char *argv[], ACE_Reactor *reactor) 4 : ACCEPTOR (reactor) { 5 u_short logger_port = argc > 1 ? atoi (argv[1]) : 0; 6 ACE_TYPENAME ACCEPTOR::PEER_ADDR server_addr; 7 int result; 8 9 if (logger_port != 0) 10 result = server_addr.set (logger_port, INADDR_ANY); 11 else 12 result = server_addr.set (&quot;ace_logger&quot;, INADDR_ANY); 13 if (result != -1) 14 result = ACCEPTOR::open (server_addr); 15 if (result == -1) reactor->end_reactor_event_loop (); 16 } Shutdown the reactor’s event loop if an error occurs
  • 79. Using the ACE_Reactor Class (4/4) 1 typedef Reactor_Logging_Server<Logging_Acceptor_Ex> 2 Server_Logging_Daemon; 3 4 int main (int argc, char *argv[]) { 5 ACE_Reactor reactor; 6 Server_Logging_Daemon *server = 0; 7 ACE_NEW_RETURN (server, 8 Server_Logging_Daemon (argc, argv, &reactor), 9 1); 10 11 if (reactor.run_reactor_event_loop () == -1) 12 ACE_ERROR_RETURN ((LM_ERROR, &quot;%p&quot;, 13 &quot;run_reactor_event_loop()&quot;), 1); 14 return 0; 15 } Dynamic allocation ensures proper deletion semantics
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94. Using the ACE_Select_Reactor Class (2/4) 14 int main (int argc, char *argv[]) { 15 ACE_Select_Reactor select_reactor; 16 ACE_Reactor reactor (&select_reactor); 17 18 Server_Logging_Daemon *server = 0; 19 ACE_NEW_RETURN (server, 20 Server_Logging_Daemon (argc, argv, &reactor), 21 1); 22 ACE_Thread_Manager::instance()->spawn (event_loop, &reactor); 23 ACE_Thread_Manager::instance()->spawn (controller, &reactor); 24 return ACE_Thread_Manager::instance ()->wait (); 25 } static ACE_THR_FUNC_RETURN event_loop (void *arg) { ACE_Reactor *reactor = ACE_static_cast (ACE_Reactor *, arg); reactor->owner (ACE_OS::thr_self ()); reactor->run_reactor_event_loop (); return 0; } Ensure we get the ACE_Select_Reactor Barrier synchronization Become “owner” (only needed for ACE_Select_Reactor )
  • 95. Using the ACE_Select_Reactor Class (3/4) 1 static ACE_THR_FUNC_RETURN controller (void *arg) { 2 ACE_Reactor *reactor = ACE_static_cast (ACE_Reactor *, arg); 3 Quit_Handler *quit_handler = 0; 4 ACE_NEW_RETURN (quit_handler, Quit_Handler (reactor), 0); 5 6 for (;;) { 7 std::string user_input; 8 std::getline (cin, user_input, ''); 9 if (user_input == &quot;quit&quot;) { 10 reactor->notify (quit_handler); 11 break; 12 } 13 } 14 return 0; 15 } Use the notify pipe to wakeup the reactor & inform it to shut down by calling handle_exception() Runs in a separate thread of control
  • 96. Using the ACE_Select_Reactor Class (4/4) class Quit_Handler : public ACE_Event_Handler { public: Quit_Handler (ACE_Reactor *r): ACE_Event_Handler (r) {} virtual int handle_exception (ACE_HANDLE) { reactor ()->end_reactor_event_loop (); return -1; } virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask) { delete this; return 0; } private: // Private destructor ensures dynamic allocation. virtual ~Quit_Handler () {} }; Trigger call to handle_close() method It’s ok to “delete this” in this context
  • 97.
  • 98.
  • 99. The Leader/Followers Pattern This pattern eliminates the need for—& the overhead of—a separate Reactor thread & synchronized request queue used in the Half-Sync/Half-Async pattern The Leader/Followers architectural pattern (P2) provides an efficient concurrency model where multiple threads take turns sharing event sources to detect, demux, dispatch, & process service requests that occur on the event sources TCP Sockets + select() / poll() UDP Sockets + select() / poll() Iterative Handle Sets TCP Sockets + WaitForMultpleObjects() UDP Sockets + WaitForMultipleObjects() Concurrent Handle Sets Iterative Handles Concurrent Handles Handles Handle Sets Handle uses demultiplexes * * Handle Set handle_events() deactivate_handle() reactivate_handle() select() Event Handler handle_event () get_handle() Concrete Event Handler B handle_event () get_handle() Concrete Event Handler A handle_event () get_handle() Thread Pool join() promote_new_leader() synchronizer
  • 100.
  • 101.
  • 102.
  • 103.
  • 105.
  • 106.
  • 107. Using the ACE_TP_Reactor Class (2/2) 14 int main (int argc, char *argv[]) { 15 const size_t N_THREADS = 4; 16 ACE_TP_Reactor tp_reactor; 17 ACE_Reactor reactor (&tp_reactor); 18 auto_ptr<ACE_Reactor> delete_instance 19 (ACE_Reactor::instance (&reactor)); 20 21 Server_Logging_Daemon *server = 0; 22 ACE_NEW_RETURN (server, 23 Server_Logging_Daemon (argc, argv, 24 ACE_Reactor::instance ()), 1); 25 ACE_Thread_Manager::instance ()->spawn_n 26 (N_THREADS, event_loop, ACE_Reactor::instance ()); 27 ACE_Thread_Manager::instance ()->spawn 28 (controller, ACE_Reactor::instance ()); 29 return ACE_Thread_Manager::instance ()->wait (); 30 } Spawn multiple threads Ensure we get the ACE_TP_Reactor
  • 108.
  • 109.
  • 111.
  • 112.
  • 113. Using the ACE_WFMO_Reactor Class (1/5) class Quit_Handler : public ACE_Event_Handler { private: // Keep track of when to shutdown. ACE_Manual_Event quit_seen_; public: 1 Quit_Handler (ACE_Reactor *r): ACE_Event_Handler (r) { 2 SetConsoleMode (ACE_STDIN, 3 ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT 4 | ENABLE_PROCESSED_INPUT); 5 if (reactor ()->register_handler 6 (this, quit_seen_.handle ()) == -1 7 || ACE_Event_Handler::register_stdin_handler 8 (this, r, ACE_Thread_Manager::instance ()) == -1) 9 r->end_reactor_event_loop (); 10 } This method only works on Windows
  • 114.
  • 115. Using the ACE_WFMO_Reactor Class (2/5) virtual int handle_input (ACE_HANDLE h) { CHAR user_input[BUFSIZ]; DWORD count; if (!ReadFile (h, user_input, BUFSIZ, &count, 0)) return -1; user_input[count] = ''; if (ACE_OS_String::strncmp (user_input, &quot;quit&quot;, 4) == 0) return -1; return 0; } virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask) { quit_seen_.signal (); return 0; } virtual int handle_signal (int, siginfo_t *, ucontext_t *) { reactor ()->end_reactor_event_loop (); return 0; } 1 ~Quit_Handler () { 2 ACE_Event_Handler::remove_stdin_handler 3 (reactor (), ACE_Thread_Manager::instance ()); 4 reactor ()->remove_handler (quit_seen_.handle (), 5 ACE_Event_Handler::DONT_CALL); 6 } This hook method is called when a handle is signaled This is a Windows-specific function
  • 116. Using the ACE_WFMO_Reactor Class (3/5) class Logging_Event_Handler_WFMO : public Logging_Event_Handler_Ex { public: Logging_Event_Handler_WFMO (ACE_Reactor *r) : Logging_Event_Handler_Ex (r) {} protected: int handle_input (ACE_HANDLE h) { ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, monitor, lock_, -1); return logging_handler_.log_record (); } ACE_Thread_Mutex lock_; // Serialize threads in thread pool. }; We need a lock since the ACE_WFMO_Reactor doesn’t suspend handles…
  • 117.
  • 118.
  • 119. Using the ACE_WFMO_Reactor Class (4/5) class Logging_Acceptor_WFMO : public Logging_Acceptor_Ex { public: Logging_Acceptor_WFMO (ACE_Reactor *r = ACE_Reactor::instance ()) : Logging_Acceptor_Ex (r) {} protected: virtual int handle_input (ACE_HANDLE) { Logging_Event_Handler_WFMO *peer_handler = 0; ACE_NEW_RETURN (peer_handler, Logging_Event_Handler_WFMO (reactor ()), -1); if (acceptor_.accept (peer_handler->peer ()) == -1) { delete peer_handler; return -1; } else if (peer_handler->open () == -1) { peer_handler->handle_close (); return -1; } return 0; } }; Note the canonical (common) form of this hook method
  • 120. Using the ACE_WFMO_Reactor Class (5/5) ACE_THR_FUNC_RETURN event_loop (void *); // Forward declaration. typedef Reactor_Logging_Server<Logging_Acceptor_WFMO> Server_Logging_Daemon; int main (int argc, char *argv[]) { const size_t N_THREADS = 4; ACE_WFMO_Reactor wfmo_reactor; ACE_Reactor reactor (&wfmo_reactor); Server_Logging_Daemon *server = 0; ACE_NEW_RETURN (server, Server_Logging_Daemon (argc, argv, &reactor), 1); Quit_Handler quit_handler (&reactor); ACE_Thread_Manager::instance ()->spawn_n (N_THREADS, event_loop, &reactor); return ACE_Thread_Manager::instance ()->wait (); } Main program Ensure we get the ACE_WFMO_Reactor Constructor registers with reactor Barrier synchronization
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.