Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Future_Set Class Template Reference

This class implements a mechanism which allows the values of a collection of ACE_Future objects to be accessed by reader threads as they become available. The caller(s) provide the ACE_Future_Set (i.e. the observer...) with the collection of ACE_Future objects (i.e. the subjects...) that are to be observed using the the ACE_Future_Set::insert() method. The caller(s) may then iterate over the collection in the order in which they become readable using the ACE_Future_Set::next_readable() method. More...

#include <Future_Set.h>

Inheritance diagram for ACE_Future_Set:

Inheritance graph
[legend]
Collaboration diagram for ACE_Future_Set:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Future_Set (ACE_Message_Queue< ACE_SYNCH > *future_notification_queue_=0)
 Constructor. More...

 ~ACE_Future_Set (void)
 Destructor. More...

int is_empty (void) const
int insert (ACE_Future< T > &future)
int next_readable (ACE_Future< T > &result, ACE_Time_Value *tv=0)
virtual void update (const ACE_Future< T > &future)
 Called by the ACE_Future subject in which we are subscribed to when its value is written to. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Private Types

typedef ACE_Future< T > FUTURE
typedef ACE_Future_Rep< T > FUTURE_REP
typedef ACE_Future_Holder< T > FUTURE_HOLDER
typedef ACE_Pointer_Hash<
FUTURE_REP * > 
FUTURE_REP_HASH
typedef ACE_Equal_To< FUTURE_REP * > FUTURE_REP_COMPARE
typedef ACE_Hash_Map_Manager_Ex<
FUTURE_REP *, FUTURE_HOLDER *,
FUTURE_REP_HASH, FUTURE_REP_COMPARE,
ACE_Null_Mutex
FUTURE_HASH_MAP

Private Methods

void operator= (const ACE_Future_Set< T > &)
 ACE_Future_Set (const ACE_Future_Set< T > &)

Private Attributes

FUTURE_HASH_MAP future_map_
 Map of <ACE_Futures>, subjects, which have not been written to by client's writer thread. More...

ACE_Message_Queue< ACE_SYNCH > * future_notification_queue_
 Message queue for notifying the reader thread of <ACE_Futures> which have been written to by client's writer thread. More...

int delete_queue_
 Keeps track of whether we need to delete the message queue. More...


Detailed Description

template<class T>
class ACE_Future_Set< T >

This class implements a mechanism which allows the values of a collection of ACE_Future objects to be accessed by reader threads as they become available. The caller(s) provide the ACE_Future_Set (i.e. the observer...) with the collection of ACE_Future objects (i.e. the subjects...) that are to be observed using the the ACE_Future_Set::insert() method. The caller(s) may then iterate over the collection in the order in which they become readable using the ACE_Future_Set::next_readable() method.

Definition at line 41 of file Future_Set.h.


Member Typedef Documentation

template<class T>
typedef ACE_Future<T> ACE_Future_Set::FUTURE [private]
 

Definition at line 103 of file Future_Set.h.

template<class T>
typedef ACE_Hash_Map_Manager_Ex<FUTURE_REP *, FUTURE_HOLDER *, FUTURE_REP_HASH, FUTURE_REP_COMPARE, ACE_Null_Mutex> ACE_Future_Set::FUTURE_HASH_MAP [private]
 

Definition at line 117 of file Future_Set.h.

template<class T>
typedef ACE_Future_Holder<T> ACE_Future_Set::FUTURE_HOLDER [private]
 

Definition at line 107 of file Future_Set.h.

template<class T>
typedef ACE_Future_Rep<T> ACE_Future_Set::FUTURE_REP [private]
 

Definition at line 105 of file Future_Set.h.

template<class T>
typedef ACE_Equal_To<FUTURE_REP *> ACE_Future_Set::FUTURE_REP_COMPARE [private]
 

Definition at line 111 of file Future_Set.h.

template<class T>
typedef ACE_Pointer_Hash<FUTURE_REP *> ACE_Future_Set::FUTURE_REP_HASH [private]
 

Definition at line 109 of file Future_Set.h.


Constructor & Destructor Documentation

template<class T>
ACE_Future_Set< T >::ACE_Future_Set ACE_Message_Queue< ACE_SYNCH > *    future_notification_queue_ = 0
 

Constructor.

Definition at line 18 of file Future_Set.cpp.

References ACE_NEW, delete_queue_, and future_notification_queue_.

00019   : delete_queue_ (0)
00020 {
00021   if (new_queue)
00022     this->future_notification_queue_ = new_queue;
00023   else
00024     {
00025       ACE_NEW (this->future_notification_queue_,
00026                ACE_Message_Queue<ACE_SYNCH>);
00027       this->delete_queue_ = 1;
00028     }
00029 }

template<class T>
ACE_Future_Set< T >::~ACE_Future_Set void   
 

Destructor.

Definition at line 32 of file Future_Set.cpp.

References ACE_TYPENAME, ACE_Hash_Map_Manager_Ex< FUTURE_REP *, FUTURE_HOLDER *, FUTURE_REP_HASH, FUTURE_REP_COMPARE, ACE_Null_Mutex >::begin, delete_queue_, ACE_Hash_Map_Manager_Ex< FUTURE_REP *, FUTURE_HOLDER *, FUTURE_REP_HASH, FUTURE_REP_COMPARE, ACE_Null_Mutex >::end, future_map_, future_notification_queue_, and ACE_Future_Holder::item_.

00033 {
00034   // Detach ourselves from all remaining futures, if any, in our map.
00035   ACE_TYPENAME FUTURE_HASH_MAP::iterator iterator =
00036     this->future_map_.begin ();
00037 
00038   ACE_TYPENAME FUTURE_HASH_MAP::iterator end =
00039     this->future_map_.end ();
00040 
00041   for (;
00042        iterator != end;
00043        ++iterator)
00044     {
00045       FUTURE_HOLDER *future_holder = (*iterator).int_id_;
00046       future_holder->item_.detach (this);
00047       delete future_holder;
00048     }
00049 
00050   if (this->delete_queue_ != 0)
00051     delete this->future_notification_queue_;
00052 }

template<class T>
ACE_Future_Set< T >::ACE_Future_Set const ACE_Future_Set< T > &    [private]
 


Member Function Documentation

template<class T>
int ACE_Future_Set< T >::insert ACE_Future< T > &    future
 

Enqueus the given ACE_Future into this objects queue when it is readable.

Returns 0 if the future is successfully inserted, 1 if the future is already inserted, and -1 if failures occur.

Definition at line 61 of file Future_Set.cpp.

References ACE_NEW_RETURN, ACE_Hash_Map_Manager_Ex< FUTURE_REP *, FUTURE_HOLDER *, FUTURE_REP_HASH, FUTURE_REP_COMPARE, ACE_Null_Mutex >::bind, and future_map_.

00062 {
00063   FUTURE_HOLDER *future_holder;
00064   ACE_NEW_RETURN (future_holder,
00065                   FUTURE_HOLDER (future),
00066                   -1);
00067 
00068   FUTURE_REP *future_rep = future.get_rep ();
00069   int result = this->future_map_.bind (future_rep,
00070                                        future_holder);
00071 
00072   // If a new map entry was created, then attach to the future,
00073   // otherwise we were already attached to the future or some error
00074   // occurred so just delete the future holder.
00075   if ( result == 0 )
00076     // Attach ourself to the ACE_Futures list of observer
00077     future.attach (this);
00078   else
00079     delete future_holder;
00080 
00081   return result;
00082 }

template<class T>
int ACE_Future_Set< T >::is_empty void    const
 

Return 1 if their are no ACE_Future objects left on its queue and 0 otherwise.

When an ACE_Future_Set has no ACE_Future>subjects to observe it is empty. The ACE_Future_Set is in the empty state when either the caller(s) have retrieved every readable ACE_Future subject assigned the ACE_Future_Set via the ACE_Future_Set::next_readable() method, or when the ACE_Future_Set has not been assigned any subjects.

Definition at line 55 of file Future_Set.cpp.

Referenced by next_readable.

00056 {
00057   return (((ACE_Future_Set<T>*)this)->future_map_.current_size () == 0 );
00058 }

template<class T>
int ACE_Future_Set< T >::next_readable ACE_Future< T > &    result,
ACE_Time_Value   tv = 0
 

Wait up to <tv> time to get the <value>. Note that <tv> must be specified in absolute time rather than relative time.); get the next <ACE_Future> that is readable. If <tv> = 0, the will block forever.

If a readable future becomes available, then the input <ACE_Future> object param will be assigned with it and 1 will be returned. If the <ACE_Future_Set> is empty (i.e. see definition of <ACE_Future_Set::is_empty>), then 0 is returned.

When a readable <ACE_Future> object is retrieved via the <ACE_Future_Set::next_readable> method, the <ACE_Future_Set> will remove that <ACE_Future> object from its list of subjects.

Definition at line 98 of file Future_Set.cpp.

References ACE_Message_Block::base, ACE_Message_Queue< ACE_SYNCH >::dequeue_head, ACE_Hash_Map_Manager_Ex< FUTURE_REP *, FUTURE_HOLDER *, FUTURE_REP_HASH, FUTURE_REP_COMPARE, ACE_Null_Mutex >::find, future_map_, future_notification_queue_, is_empty, ACE_Future_Holder::item_, ACE_Message_Block::release, and ACE_Hash_Map_Manager_Ex< FUTURE_REP *, FUTURE_HOLDER *, FUTURE_REP_HASH, FUTURE_REP_COMPARE, ACE_Null_Mutex >::unbind.

00100 {
00101   if (this->is_empty ())
00102     return 0;
00103 
00104   ACE_Message_Block *mb = 0;
00105   FUTURE_REP *future_rep = 0;
00106 
00107   // Wait for a "readable future" signal from the message queue.
00108   if (this->future_notification_queue_->dequeue_head (mb,
00109                                                       tv) != -1)
00110     {
00111       // Extract future rep from the message block.
00112       future_rep =
00113         ACE_reinterpret_cast (FUTURE_REP *,
00114                               mb->base ());
00115 
00116       // Delete the message block.
00117       mb->release ();
00118     }
00119   else
00120     return 0;
00121 
00122   // Remove the hash map entry with the specified future rep from our map.
00123   FUTURE_HOLDER *future_holder;
00124   if ( this->future_map_.find (future_rep,
00125                                future_holder) != -1 )
00126     {
00127       future = future_holder->item_;
00128       this->future_map_.unbind (future_rep);
00129       delete future_holder;
00130       return 1;
00131     }
00132 
00133   return 0;
00134 }

template<class T>
void ACE_Future_Set< T >::operator= const ACE_Future_Set< T > &    [private]
 

template<class T>
void ACE_Future_Set< T >::update const ACE_Future< T > &    future [virtual]
 

Called by the ACE_Future subject in which we are subscribed to when its value is written to.

Implements ACE_Future_Observer.

Definition at line 85 of file Future_Set.cpp.

References ACE_NEW, ACE_Message_Queue< ACE_SYNCH >::enqueue, future_notification_queue_, and ACE_Future::get_rep.

00086 {
00087   ACE_Message_Block *mb;
00088   FUTURE &local_future = ACE_const_cast (ACE_Future<T> &, future);
00089 
00090   ACE_NEW (mb,
00091            ACE_Message_Block ((char *) local_future.get_rep (), 0));
00092 
00093   // Enqueue in priority order.
00094   this->future_notification_queue_->enqueue (mb, 0);
00095 }


Member Data Documentation

template<class T>
ACE_Future_Set::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_Future_Observer.

Definition at line 96 of file Future_Set.h.

template<class T>
int ACE_Future_Set::delete_queue_ [private]
 

Keeps track of whether we need to delete the message queue.

Definition at line 128 of file Future_Set.h.

Referenced by ACE_Future_Set, and ~ACE_Future_Set.

template<class T>
FUTURE_HASH_MAP ACE_Future_Set::future_map_ [private]
 

Map of <ACE_Futures>, subjects, which have not been written to by client's writer thread.

Definition at line 121 of file Future_Set.h.

Referenced by insert, next_readable, and ~ACE_Future_Set.

template<class T>
ACE_Message_Queue<ACE_SYNCH>* ACE_Future_Set::future_notification_queue_ [private]
 

Message queue for notifying the reader thread of <ACE_Futures> which have been written to by client's writer thread.

Definition at line 125 of file Future_Set.h.

Referenced by ACE_Future_Set, next_readable, update, and ~ACE_Future_Set.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:48:14 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002