2 #ifndef JAWS_CONCURRENCY_H
3 #define JAWS_CONCURRENCY_H
5 #include "ace/Singleton.h"
7 #if !defined (ACE_LACKS_PRAGMA_ONCE)
9 #endif /* ACE_LACKS_PRAGMA_ONCE */
12 #include "ace/Synch_Traits.h"
14 #include "JAWS/Export.h"
15 #include "JAWS/Jaws_IO.h"
17 class JAWS_Data_Block
;
18 class JAWS_Dispatch_Policy
;
21 class JAWS_Export JAWS_Concurrency_Base
: public ACE_Task
<ACE_SYNCH
>
23 // Base class for different concurrency models
26 // Provides a default implementaion of the virtual put() method
27 // which calls putq(), but can be overloaded to do something
28 // synchronously, such as call put_next().
32 JAWS_Concurrency_Base ();
33 ~JAWS_Concurrency_Base ();
35 virtual int put (ACE_Message_Block
*mb
, ACE_Time_Value
*tv
= 0);
38 virtual int svc_loop (JAWS_Data_Block
*db
);
39 // in thread pool, this is an infinite loop
40 // in thread per request, it is a single iteration
42 virtual int svc_hook (JAWS_Data_Block
*db
);
43 // does the work of following the pipeline tasks
45 virtual int activate_hook ();
46 // callback for IO_Handler when accept completes
48 virtual ACE_Message_Block
*singleton_mb ();
52 ACE_Message_Block
*mb_
;
54 ACE_SYNCH_MUTEX lock_
;
57 class JAWS_Export JAWS_Dispatcher
59 // The class that is responsible to delivering events to the
60 // appropriate concurrency mechanism.
63 // JAWS_IO_Handler calls into the dispatcher so that the completed
64 // IO can find a thread to take care of it.
69 int dispatch (ACE_Message_Block
*mb
);
70 JAWS_Dispatch_Policy
*policy ();
71 JAWS_Dispatch_Policy
*policy (JAWS_Dispatch_Policy
*p
);
74 JAWS_Dispatch_Policy
*policy_
;
77 class JAWS_Export JAWS_Thread_Pool_Task
: public JAWS_Concurrency_Base
79 // Used to implement Thread Pool Concurrency Strategy
82 // This task is created to hold a pool of threads that receive
83 // requests through the message queue.
86 virtual int make (long flags
, int nthreads
, int maxthreads
);
87 // Initiate the thread_pool task
95 class JAWS_Export JAWS_Thread_Per_Task
: public JAWS_Concurrency_Base
97 // Used to implement Thread Per Request Concurrency Strategy
100 // As each new message arrives from the queue, a new thread is
101 // spawned to handle it. This is done by overloading put to call
105 virtual int make (long flags
, int maxthreads
);
106 // Initiate the thread_per task
108 virtual int put (ACE_Message_Block
*mb
, ACE_Time_Value
*tv
= 0);
110 virtual int svc_loop (JAWS_Data_Block
*db
);
111 // a single iteration
113 virtual int activate_hook ();
114 // callback for IO_Handler when accept completes
121 typedef ACE_Singleton
<JAWS_Dispatcher
, ACE_SYNCH_MUTEX
>
122 JAWS_Dispatcher_Singleton
;
124 typedef ACE_Singleton
<JAWS_Thread_Pool_Task
, ACE_SYNCH_MUTEX
>
125 JAWS_Thread_Pool_Singleton
;
127 typedef ACE_Singleton
<JAWS_Thread_Per_Task
, ACE_SYNCH_MUTEX
>
128 JAWS_Thread_Per_Singleton
;
130 #endif /* !defined (JAWS_CONCURRENCY_H) */