#include <Leader_Follower.h>
Collaboration diagram for TAO_Leader_Follower:
Public Member Functions | |
TAO_Leader_Follower (TAO_ORB_Core *orb_core, TAO_New_Leader_Generator *new_leader_generator=0) | |
Constructor. | |
~TAO_Leader_Follower (void) | |
Destructor. | |
int | set_event_loop_thread (ACE_Time_Value *max_wait_time) |
void | reset_event_loop_thread (void) |
void | set_upcall_thread (void) |
int | leader_available (void) const |
Is there any thread running as a leader? | |
void | set_client_thread (void) |
A server thread is making a request. | |
void | reset_client_thread (void) |
A server thread has finished is making a request. | |
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. | |
void | set_client_leader_thread (void) |
void | reset_client_leader_thread (void) |
void | set_client_leader_thread (ACE_thread_t thread_ID) |
int | is_client_leader_thread (void) const |
checks if we are a leader thread | |
int | elect_new_leader (void) |
TAO_SYNCH_MUTEX & | lock (void) |
Get a reference to the underlying mutex. | |
ACE_Reverse_Lock< TAO_SYNCH_MUTEX > & | reverse_lock (void) |
int | has_clients (void) const |
Check if there are any client threads running. | |
ACE_Reactor * | reactor (void) |
Accesor to the reactor. | |
void | no_leaders_available (void) |
Called when we are out of leaders. | |
Follower creation/destructions | |
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: | |
TAO_LF_Follower * | allocate_follower (void) |
Allocate a new follower to the caller. | |
void | release_follower (TAO_LF_Follower *) |
The caller has finished using a follower. | |
Follower Set Operations | |
void | add_follower (TAO_LF_Follower *follower) |
Add a new follower to the set. | |
void | remove_follower (TAO_LF_Follower *follower) |
Removes a follower from the leader-follower set. | |
int | follower_available (void) const |
Checks if there are any followers available. | |
Private Types | |
typedef ACE_Intrusive_List< TAO_LF_Follower > | Follower_Set |
Implement the Leader/Followers set using an intrusive list. | |
Private Member Functions | |
TAO_ORB_Core_TSS_Resources * | get_tss_resources (void) const |
Shortcut to obtain the TSS resources of the orb core. | |
int | wait_for_client_leader_to_complete (ACE_Time_Value *max_wait_time) |
Wait for the client leader to complete. | |
void | reset_event_loop_thread_i (TAO_ORB_Core_TSS_Resources *tss) |
Follower Set Operations | |
int | elect_new_leader_i (void) |
Private Attributes | |
TAO_ORB_Core * | orb_core_ |
The orb core. | |
TAO_SYNCH_MUTEX | lock_ |
To synchronize access to the members. | |
ACE_Reverse_Lock< TAO_SYNCH_MUTEX > | reverse_lock_ |
do protect the access to the following three members | |
Follower_Set | follower_set_ |
Follower_Set | follower_free_list_ |
Use a free list to allocate and release Follower objects. | |
int | leaders_ |
int | clients_ |
ACE_Reactor * | reactor_ |
The reactor. | |
int | client_thread_is_leader_ |
Is a client thread the current leader? | |
int | event_loop_threads_waiting_ |
Are server threads waiting for the client leader to complete? | |
TAO_SYNCH_CONDITION | event_loop_threads_condition_ |
TAO_New_Leader_Generator * | new_leader_generator_ |
TAO_Leader_Follower
|
Implement the Leader/Followers set using an intrusive list.
|
|
Constructor.
|
|
Destructor.
|
|
Add a new follower to the set.
|
|
Allocate a new follower to the caller.
|
|
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. |
|
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. |
|
Checks if there are any followers available.
|
|
Shortcut to obtain the TSS resources of the orb core.
|
|
Check if there are any client threads running.
|
|
checks if we are a leader thread
|
|
Is there any thread running as a leader?
|
|
Get a reference to the underlying mutex.
|
|
Called when we are out of leaders.
|
|
Accesor to the reactor.
|
|
The caller has finished using a follower.
|
|
Removes a follower from the leader-follower set.
|
|
The current thread is no longer the leader thread in the client side leader-follower set. |
|
A server thread has finished is making a request.
|
|
The current thread is not a server thread anymore, reset any flags and counters. |
|
Implement the reset_event_loop_thread() method, once the TSS resources have been acquired. Also used in the set_upcall_thread. |
|
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. |
|
sets the thread ID of the leader thread in the leader-follower model |
|
The current thread has become the leader thread in the client side leader-follower set. |
|
A server thread is making a request.
|
|
The current thread has become a server thread (i.e. called ORB::run), update any flags and counters. |
|
This thread is going to perform an upcall, it will no longer be an event loop thread. |
|
Wait for the client leader to complete.
|
|
Wait on the Leader/Followers loop until one event happens.
|
|
Is a client thread the current leader?
|
|
Count the number of active clients, this is useful to know when to deactivate the reactor |
|
Condition variable for server threads waiting for the client leader to complete. |
|
Are server threads waiting for the client leader to complete?
|
|
Use a free list to allocate and release Follower objects.
|
|
|
|
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. |
|
To synchronize access to the members.
|
|
Leader/Follower class uses this method to notify the system that we are out of leaders. |
|
The orb core.
|
|
The reactor.
|
|
do protect the access to the following three members
|