TAO  2.1.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
TAO_Leader_Follower Class Reference

TAO_Leader_Follower. More...

#include <Leader_Follower.h>

Collaboration diagram for TAO_Leader_Follower:
Collaboration graph

Classes

class  Deferred_Event
 Class used to register deferred event handlers. More...
 

Public Member Functions

 TAO_Leader_Follower (TAO_ORB_Core *orb_core, TAO_New_Leader_Generator *new_leader_generator=0)
 Constructor. More...
 
 ~TAO_Leader_Follower (void)
 Destructor. More...
 
int set_event_loop_thread (ACE_Time_Value *max_wait_time)
 
void reset_event_loop_thread (void)
 
void set_upcall_thread (void)
 
bool leader_available (void) const
 Is there any thread running as a leader? More...
 
void set_client_thread (void)
 A server thread is making a request. More...
 
void reset_client_thread (void)
 A server thread has finished is making a request. More...
 
int wait_for_event (TAO_LF_Event *event, TAO_Transport *transport, ACE_Time_Value *max_wait_time)
 Wait on the Leader/Followers loop until one event happens. More...
 
void set_client_leader_thread (void)
 
void reset_client_leader_thread (void)
 
void set_client_leader_thread (ACE_thread_t thread_ID)
 
bool is_client_leader_thread (void) const
 Checks if we are a leader thread. More...
 
void set_avoid_client_leader (void)
 
int elect_new_leader (void)
 
TAO_SYNCH_MUTEXlock (void)
 Get a reference to the underlying mutex. More...
 
ACE_Reverse_Lock
< TAO_SYNCH_MUTEX > & 
reverse_lock (void)
 
bool has_clients (void) const
 Check if there are any client threads running. More...
 
ACE_Reactorreactor (void)
 Accesor to the reactor. More...
 
bool no_leaders_available (void)
 Called when we are out of leaders. More...
 
void set_new_leader_generator (TAO_New_Leader_Generator *new_leader_generator)
 Set the new leader generator. More...
 
int defer_event (ACE_Event_Handler *)
 
Follower creation/destruction

The Leader/Followers set acts as a factory for the Follower objects. Followers are used to represent a thread blocked waiting in the Follower set.

The Leader/Followers abstraction keeps a list of the waiting followers, so it can wake up one when the leader thread stops handling events.

For performance reasons the Leader/Followers set uses a pool (or free-list) to keep Follower objects unattached to any thread. It could be tempting to use TSS to keep such followers, after all a thread can only need one such Follower object, however, that does not work with multiple Leader/Followers sets, consult this bug report for more details:

http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=296

TAO_LF_Followerallocate_follower (void)
 Allocate a new follower to the caller. More...
 
void release_follower (TAO_LF_Follower *)
 The caller has finished using a follower. More...
 

Private Types

typedef ACE_Intrusive_List
< TAO_LF_Follower
Follower_Set
 Implement the Leader/Followers set using an intrusive list. More...
 
typedef ACE_Intrusive_List
< Deferred_Event
Deferred_Event_Set
 The set of deferred event handlers. More...
 

Private Member Functions

TAO_ORB_Core_TSS_Resourcesget_tss_resources (void) const
 Shortcut to obtain the TSS resources of the orb core. More...
 
int wait_for_client_leader_to_complete (ACE_Time_Value *max_wait_time)
 Wait for the client leader to complete. More...
 
void reset_event_loop_thread_i (TAO_ORB_Core_TSS_Resources *tss)
 
void resume_events ()
 

Private Attributes

TAO_ORB_Coreorb_core_
 The orb core. More...
 
TAO_SYNCH_MUTEX lock_
 To synchronize access to the members. More...
 
ACE_Reverse_Lock< TAO_SYNCH_MUTEXreverse_lock_
 Do protect the access to the following three members. More...
 
Follower_Set follower_set_
 
Follower_Set follower_free_list_
 Use a free list to allocate and release Follower objects. More...
 
int leaders_
 
int clients_
 
ACE_Reactorreactor_
 The reactor. More...
 
bool avoid_client_leader_
 
int client_thread_is_leader_
 Is a client thread the current leader? More...
 
int event_loop_threads_waiting_
 Are server threads waiting for the client leader to complete? More...
 
TAO_SYNCH_CONDITION event_loop_threads_condition_
 
TAO_New_Leader_Generatornew_leader_generator_
 
Deferred_Event_Set deferred_event_set_
 

Follower Set Operations

void add_follower (TAO_LF_Follower *follower)
 Add a new follower to the set. More...
 
void remove_follower (TAO_LF_Follower *follower)
 Removes a follower from the leader-follower set. More...
 
bool follower_available (void) const
 Checks if there are any followers available. More...
 
int elect_new_leader_i (void)
 

Detailed Description

TAO_Leader_Follower.

TAO_Leader_Follower

Member Typedef Documentation

The set of deferred event handlers.

Implement the Leader/Followers set using an intrusive list.

Constructor & Destructor Documentation

TAO_Leader_Follower::TAO_Leader_Follower ( TAO_ORB_Core orb_core,
TAO_New_Leader_Generator new_leader_generator = 0 
)

Constructor.

TAO_Leader_Follower::~TAO_Leader_Follower ( void  )

Destructor.

Member Function Documentation

void TAO_Leader_Follower::add_follower ( TAO_LF_Follower follower)

Add a new follower to the set.

TAO_LF_Follower * TAO_Leader_Follower::allocate_follower ( void  )

Allocate a new follower to the caller.

int TAO_Leader_Follower::defer_event ( ACE_Event_Handler eh)

Method to support deffering an event till later (f.i. in cases where transport()->wait_strategy()->can_process_upcalls() returns false).

int TAO_Leader_Follower::elect_new_leader ( void  )

A leader thread is relinquishing its role, unless there are more leader threads running pick up a follower (if there is any) to play the leader role.

int TAO_Leader_Follower::elect_new_leader_i ( void  )
private

Remove a follower from the Followers set and promote it to the leader role. This is a helper routine for elect_new_leader(), after verifying that all the pre-conditions are satisfied the Follower set is changed and the promoted Follower is signaled.

bool TAO_Leader_Follower::follower_available ( void  ) const

Checks if there are any followers available.

Returns
true if there follower set is not empty
TAO_ORB_Core_TSS_Resources * TAO_Leader_Follower::get_tss_resources ( void  ) const
private

Shortcut to obtain the TSS resources of the orb core.

bool TAO_Leader_Follower::has_clients ( void  ) const

Check if there are any client threads running.

bool TAO_Leader_Follower::is_client_leader_thread ( void  ) const

Checks if we are a leader thread.

bool TAO_Leader_Follower::leader_available ( void  ) const

Is there any thread running as a leader?

TAO_SYNCH_MUTEX & TAO_Leader_Follower::lock ( void  )

Get a reference to the underlying mutex.

bool TAO_Leader_Follower::no_leaders_available ( void  )

Called when we are out of leaders.

ACE_Reactor * TAO_Leader_Follower::reactor ( void  )

Accesor to the reactor.

void TAO_Leader_Follower::release_follower ( TAO_LF_Follower follower)

The caller has finished using a follower.

void TAO_Leader_Follower::remove_follower ( TAO_LF_Follower follower)

Removes a follower from the leader-follower set.

void TAO_Leader_Follower::reset_client_leader_thread ( void  )

The current thread is no longer the leader thread in the client side leader-follower set.

void TAO_Leader_Follower::reset_client_thread ( void  )

A server thread has finished is making a request.

void TAO_Leader_Follower::reset_event_loop_thread ( void  )

The current thread is not a server thread anymore, reset any flags and counters.

void TAO_Leader_Follower::reset_event_loop_thread_i ( TAO_ORB_Core_TSS_Resources tss)
private

Implement the reset_event_loop_thread() method, once the TSS resources have been acquired. Also used in the set_upcall_thread.

void TAO_Leader_Follower::resume_events ( )
private

Method to allow the Leader_Follower to resume deferred events when it is opportune to do so.

ACE_Reverse_Lock< TAO_SYNCH_MUTEX > & TAO_Leader_Follower::reverse_lock ( void  )

Provide a pre-initialized reverse lock for the Leader/Followers set. The Leader/Followers set mutex must be release during some long running operations. This helper class simplifies the process of releasing and reacquiring said mutex.

void TAO_Leader_Follower::set_avoid_client_leader ( void  )

Sets the client leader avoidance flag true. This is used with the noupcall wait strategy to allow the creation of dynamic threads when possible

void TAO_Leader_Follower::set_client_leader_thread ( void  )

The current thread has become the leader thread in the client side leader-follower set.

void TAO_Leader_Follower::set_client_leader_thread ( ACE_thread_t  thread_ID)

Sets the thread ID of the leader thread in the leader-follower model

void TAO_Leader_Follower::set_client_thread ( void  )

A server thread is making a request.

int TAO_Leader_Follower::set_event_loop_thread ( ACE_Time_Value max_wait_time)

The current thread has become a server thread (i.e. called ORB::run), update any flags and counters.

void TAO_Leader_Follower::set_new_leader_generator ( TAO_New_Leader_Generator new_leader_generator)

Set the new leader generator.

void TAO_Leader_Follower::set_upcall_thread ( void  )

This thread is going to perform an upcall, it will no longer be an event loop thread.

int TAO_Leader_Follower::wait_for_client_leader_to_complete ( ACE_Time_Value max_wait_time)
private

Wait for the client leader to complete.

int TAO_Leader_Follower::wait_for_event ( TAO_LF_Event event,
TAO_Transport transport,
ACE_Time_Value max_wait_time 
)

Wait on the Leader/Followers loop until one event happens.

Parameters
eventThe event we wait for, the loop iterates until the event is successful, or it fails due to timeout, and error or a connection closed.
transportThe transport attached to the event
max_wait_timeLimit the time spent on the loop
Returns
Returns -1 on error, 0 or non-zero value otherwise.
Todo:
Document this better, split the Follower code to the TAO_LF_Follower class, we probably don't need the transport object.

There should be no reason to reset the value of result here. If there was an error in handle_events () that the leader saw, I (Bala) believe it should be propagated to the clients. result = 0;

Member Data Documentation

bool TAO_Leader_Follower::avoid_client_leader_
private

Flag to indicate that it is preferable to start a new thread, if possible rather than become a client leader. In particular when using the no-upcall wait strategy along with the dynamic thread pool, this is the case. It is still possible for a client leader to emerge in the case when no additional threads may be generated.

int TAO_Leader_Follower::client_thread_is_leader_
private

Is a client thread the current leader?

int TAO_Leader_Follower::clients_
private

Count the number of active clients, this is useful to know when to deactivate the reactor

Deferred_Event_Set TAO_Leader_Follower::deferred_event_set_
private
TAO_SYNCH_CONDITION TAO_Leader_Follower::event_loop_threads_condition_
private

Condition variable for server threads waiting for the client leader to complete.

int TAO_Leader_Follower::event_loop_threads_waiting_
private

Are server threads waiting for the client leader to complete?

Follower_Set TAO_Leader_Follower::follower_free_list_
private

Use a free list to allocate and release Follower objects.

Follower_Set TAO_Leader_Follower::follower_set_
private
int TAO_Leader_Follower::leaders_
private

Count the number of active leaders. There could be many leaders in the thread pool (i.e. calling ORB::run), and the same leader could show up multiple times as it receives nested upcalls and sends more requests.

TAO_SYNCH_MUTEX TAO_Leader_Follower::lock_
private

To synchronize access to the members.

TAO_New_Leader_Generator* TAO_Leader_Follower::new_leader_generator_
private

Leader/Follower class uses this method to notify the system that we are out of leaders.

TAO_ORB_Core* TAO_Leader_Follower::orb_core_
private

The orb core.

ACE_Reactor* TAO_Leader_Follower::reactor_
private

The reactor.

ACE_Reverse_Lock<TAO_SYNCH_MUTEX> TAO_Leader_Follower::reverse_lock_
private

Do protect the access to the following three members.


The documentation for this class was generated from the following files: