3 //=============================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //=============================================================================
11 #ifndef ACE_STRATEGIES_T_H
12 #define ACE_STRATEGIES_T_H
14 #include /**/ "ace/pre.h"
16 #include "ace/Hash_Map_Manager_T.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/Reactor.h"
23 #include "ace/Thread_Manager.h"
24 #include "ace/Connection_Recycling_Strategy.h"
25 #include "ace/Refcountable_T.h"
26 #include "ace/Hashable.h"
27 #include "ace/Recyclable.h"
28 #include "ace/Reverse_Lock_T.h"
30 // Needed for broken linkers that can't grok long symbols.
31 #define ACE_Refcounted_Hash_Recyclable ARHR
33 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
35 class ACE_Service_Repository
;
38 * @class ACE_Recycling_Strategy
40 * @brief Defines the interface (and default implementation) for
41 * specifying a recycling strategy for a SVC_HANDLER.
43 * Acts as a consular to the Svc_Handler, preparing it for the
44 * tough times ahead when the Svc_Handler will be recycled.
46 template<class SVC_HANDLER
>
47 class ACE_Recycling_Strategy
50 // Useful STL-style traits.
51 typedef typename
SVC_HANDLER::addr_type addr_type
;
52 typedef SVC_HANDLER handler_type
;
53 typedef typename
SVC_HANDLER::stream_type stream_type
;
55 /// Virtual Destructor
56 virtual ~ACE_Recycling_Strategy ();
58 /// Tell the Svc_Handler something about the recycler, so that it can
59 /// reach the recycler when necessary.
60 virtual int assign_recycler (SVC_HANDLER
*svc_handler
,
61 ACE_Connection_Recycling_Strategy
*recycler
,
62 const void *recycling_act
);
64 /// This allows us to prepare the svc_handler for recycling.
65 virtual int prepare_for_recycling (SVC_HANDLER
*svc_handler
);
69 * @class ACE_Creation_Strategy
71 * @brief Defines the interface for specifying a creation strategy for
74 * The default behavior is to make a new SVC_HANDLER. However,
75 * subclasses can override this strategy to perform SVC_HANDLER
76 * creation in any way that they like (such as creating subclass
77 * instances of SVC_HANDLER, using a singleton, dynamically
78 * linking the handler, etc.).
80 template <class SVC_HANDLER
>
81 class ACE_Creation_Strategy
84 // Useful STL-style traits.
85 typedef typename
SVC_HANDLER::addr_type addr_type
;
86 typedef SVC_HANDLER handler_type
;
87 typedef typename
SVC_HANDLER::stream_type stream_type
;
89 /// Default constructor.
90 ACE_Creation_Strategy (ACE_Thread_Manager
* = 0,
91 ACE_Reactor
* = ACE_Reactor::instance ());
93 /// An ACE_Thread_Manager is useful when creating active objects and
94 /// the ACE_Reactor is used to initialize the service handler's reactor.
95 int open (ACE_Thread_Manager
* = 0,
96 ACE_Reactor
* = ACE_Reactor::instance ());
98 virtual ~ACE_Creation_Strategy ();
102 * Create a SVC_HANDLER with the appropriate creation strategy. The
103 * default behavior of this method is to make a new SVC_HANDLER if
104 * @a sh == 0 (passing in the Thread_Manager), else @a sh is
105 * unchanged. Returns -1 on failure, else 0.
107 virtual int make_svc_handler (SVC_HANDLER
*&sh
);
109 /// Dump the state of an object.
112 /// Declare the dynamic allocation hooks.
113 ACE_ALLOC_HOOK_DECLARE
;
116 /// Pointer to a thread manager.
117 ACE_Thread_Manager
*thr_mgr_
;
119 /// Pointer to an ACE_Reactor.
120 ACE_Reactor
*reactor_
;
124 * @class ACE_Singleton_Strategy
126 * @brief Defines the interface for specifying a creation strategy for
127 * a SVC_HANDLER that always returns the same SVC_HANDLER (i.e.,
130 * Note that this class takes over the ownership of the
131 * SVC_HANDLER passed into it as a parameter and it becomes
132 * responsible for deleting this object.
134 template <class SVC_HANDLER
>
135 class ACE_Singleton_Strategy
: public ACE_Creation_Strategy
<SVC_HANDLER
>
138 // Useful STL-style traits.
139 typedef ACE_Creation_Strategy
<SVC_HANDLER
> base_type
;
141 ACE_Singleton_Strategy (SVC_HANDLER
* = 0,
142 ACE_Thread_Manager
* = 0);
143 int open (SVC_HANDLER
*,
144 ACE_Thread_Manager
* = 0);
145 virtual ~ACE_Singleton_Strategy ();
148 /// Create a Singleton SVC_HANDLER by always returning the same
149 /// SVC_HANDLER. Returns -1 on failure, else 0.
150 virtual int make_svc_handler (SVC_HANDLER
*&);
152 /// Dump the state of an object.
155 /// Declare the dynamic allocation hooks.
156 ACE_ALLOC_HOOK_DECLARE
;
159 /// Pointer to the Singleton svc_handler.
160 SVC_HANDLER
*svc_handler_
;
162 /// Keep track of whether we need to delete the SVC_HANDLER.
163 bool delete_svc_handler_
;
167 * @class ACE_DLL_Strategy
169 * @brief Defines the interface for specifying a creation strategy for
170 * a SVC_HANDLER based on dynamic linking of the SVC_HANDLER.
172 template <class SVC_HANDLER
>
173 class ACE_DLL_Strategy
: public ACE_Creation_Strategy
<SVC_HANDLER
>
176 // Useful STL-style traits.
177 typedef ACE_Creation_Strategy
<SVC_HANDLER
> base_type
;
179 // = Intialization and termination methods.
181 /// "Do-nothing" constructor.
184 /// Initialize the DLL strategy based upon the service's DLL
185 /// information contained in the <svc_dll_info> string.
186 ACE_DLL_Strategy (const ACE_TCHAR dll_name
[],
187 const ACE_TCHAR factory_function
[],
188 const ACE_TCHAR svc_name
[],
189 ACE_Service_Repository
*,
190 ACE_Thread_Manager
* = 0);
192 /// Initialize the DLL strategy based upon the service's DLL
193 /// information contained in the <svc_dll_info> string.
194 int open (const ACE_TCHAR dll_name
[],
195 const ACE_TCHAR factory_function
[],
196 const ACE_TCHAR svc_name
[],
197 ACE_Service_Repository
*,
198 ACE_Thread_Manager
* = 0);
201 /// Create a SVC_HANDLER by dynamically linking it from a DLL.
202 /// Returns -1 on failure, else 0.
203 virtual int make_svc_handler (SVC_HANDLER
*&);
205 /// Dump the state of an object.
208 /// Declare the dynamic allocation hooks.
209 ACE_ALLOC_HOOK_DECLARE
;
212 typedef ACE_Creation_Strategy
<SVC_HANDLER
> inherited
;
214 /// Name of the DLL to dynamically link.
215 ACE_TCHAR dll_name_
[MAXPATHLEN
+ 1];
217 /// Name of the factory function in the shared library to use to
218 /// obtain a pointer to the new SVC_HANDLER.
219 ACE_TCHAR factory_function_
[MAXPATHLEN
+ 1];
221 /// Name of the service.
222 ACE_TCHAR svc_name_
[MAXNAMELEN
+ 1];
224 /// Pointer to the <Service_Repository>.
225 ACE_Service_Repository
*svc_rep_
;
229 * @class ACE_Concurrency_Strategy
231 * @brief Defines the interface for specifying a concurrency strategy
234 * Default behavior is to activate the SVC_HANDLER by calling
235 * its <open> method (which allows the SVC_HANDLER to define its
236 * own concurrency strategy). However, subclasses can override
237 * this default strategy to do more sophisticated concurrency
238 * activations (such as creating the SVC_HANDLER as an active
239 * object via multi-threading or multi-processing).
241 template <class SVC_HANDLER
>
242 class ACE_Concurrency_Strategy
245 // Useful STL-style traits.
246 typedef typename
SVC_HANDLER::addr_type addr_type
;
247 typedef SVC_HANDLER handler_type
;
248 typedef typename
SVC_HANDLER::stream_type stream_type
;
251 ACE_Concurrency_Strategy (int flags
= 0);
255 * Activate the @a svc_handler with an appropriate concurrency
256 * strategy. The default behavior of this method is to activate the
257 * SVC_HANDLER by calling its <open> method (which allows the
258 * SVC_HANDLER to define its own concurrency strategy).
260 virtual int activate_svc_handler (SVC_HANDLER
*svc_handler
,
263 virtual ~ACE_Concurrency_Strategy ();
265 /// Dump the state of an object.
268 /// Declare the dynamic allocation hooks.
269 ACE_ALLOC_HOOK_DECLARE
;
272 /// Flags that are parsed to set options for the connected
278 * @class ACE_Reactive_Strategy
280 * @brief Defines the interface for specifying a reactive concurrency
281 * strategy for a SVC_HANDLER, where all upcalls to @c handle_*()
282 * methods run in the reactor's thread of control.
284 * This class provides a strategy that registers the
285 * SVC_HANDLER with a <Reactor>.
287 template <class SVC_HANDLER
>
288 class ACE_Reactive_Strategy
: public ACE_Concurrency_Strategy
<SVC_HANDLER
>
291 // Useful STL-style traits.
292 typedef ACE_Concurrency_Strategy
<SVC_HANDLER
> base_type
;
294 // = Intialization and termination methods.
295 /// "Do-nothing constructor"
296 ACE_Reactive_Strategy (int flags
= 0);
298 /// Initialize the strategy.
299 ACE_Reactive_Strategy (ACE_Reactor
*reactor
,
300 ACE_Reactor_Mask
= ACE_Event_Handler::READ_MASK
,
303 /// Initialize the strategy.
304 virtual int open (ACE_Reactor
*reactor
,
305 ACE_Reactor_Mask
= ACE_Event_Handler::READ_MASK
,
309 virtual ~ACE_Reactive_Strategy ();
312 /// Activate the @a svc_handler by registering it with the <Reactor>
313 /// and then calling it's <open> hook.
314 virtual int activate_svc_handler (SVC_HANDLER
*svc_handler
,
317 /// Dump the state of an object.
320 /// Declare the dynamic allocation hooks.
321 ACE_ALLOC_HOOK_DECLARE
;
324 typedef ACE_Concurrency_Strategy
<SVC_HANDLER
> inherited
;
326 /// Pointer to the Reactor we'll use to register the SVC_HANDLER.
327 ACE_Reactor
*reactor_
;
329 /// The mask that we pass to the <Reactor> when we register the
331 ACE_Reactor_Mask mask_
;
335 * @class ACE_Thread_Strategy
337 * @brief Defines the interface for specifying a concurrency strategy
338 * for a SVC_HANDLER based on multithreading.
340 * This class provides a strategy that manages the creation of threads
341 * to handle requests from clients concurrently via a
342 * thread-per-connection model. It behaves as a "thread factory",
343 * spawning threads "on-demand" to run the service specified by a
344 * user-supplied SVC_HANDLER.
346 template <class SVC_HANDLER
>
347 class ACE_Thread_Strategy
: public ACE_Concurrency_Strategy
<SVC_HANDLER
>
350 // Useful STL-style traits.
351 typedef ACE_Concurrency_Strategy
<SVC_HANDLER
> base_type
;
353 // = Intialization and termination methods.
354 /// "Do-nothing constructor"
355 ACE_Thread_Strategy (int flags
= 0);
357 /// Initialize the strategy.
358 ACE_Thread_Strategy (ACE_Thread_Manager
*tm
,
363 /// Initialize the strategy.
364 virtual int open (ACE_Thread_Manager
*tm
,
369 virtual ~ACE_Thread_Strategy ();
373 * Activate the @a svc_handler with an appropriate concurrency
374 * strategy. This method activates the SVC_HANDLER by first calling
375 * its <open> method and then calling its <activate> method to turn
376 * it into an active object.
378 virtual int activate_svc_handler (SVC_HANDLER
*svc_handler
,
381 /// Dump the state of an object.
384 /// Declare the dynamic allocation hooks.
385 ACE_ALLOC_HOOK_DECLARE
;
388 typedef ACE_Concurrency_Strategy
<SVC_HANDLER
> inherited
;
390 /// Thread manager for this class (must be provided).
391 ACE_Thread_Manager
*thr_mgr_
;
393 /// Flags to pass into the <SVC_HANDLER::activate> method.
396 /// Number of threads to spawn.
401 * @class ACE_Process_Strategy
403 * @brief Defines the interface for specifying a concurrency strategy
404 * for a @c SVC_HANDLER based on multiprocessing.
406 * This class provides a strategy that manages the creation of
407 * processes to handle requests from clients concurrently using a
408 * process-per-connection model. It behaves as a "process factory",
409 * using @c ACE::fork() to fork threads "on-demand" to run the service
410 * specified by a user-supplied @c SVC_HANDLER in a separate process.
412 template <class SVC_HANDLER
>
413 class ACE_Process_Strategy
: public ACE_Concurrency_Strategy
<SVC_HANDLER
>
416 // Useful STL-style traits.
417 typedef ACE_Concurrency_Strategy
<SVC_HANDLER
> base_type
;
419 // = Intialization and termination methods.
421 /// Initialize the strategy. If @a avoid_zombies is non-0 then set a
422 /// flag to ACE::fork() to avoid zombies.
423 ACE_Process_Strategy (size_t n_processes
= 1,
424 ACE_Event_Handler
*acceptor
= 0,
426 int avoid_zombies
= 0);
428 /// Initialize the strategy. If @a avoid_zombies is non-0 then set a
429 /// flag to ACE::fork() to avoid zombies.
430 virtual int open (size_t n_processes
= 1,
431 ACE_Event_Handler
*acceptor
= 0,
433 int avoid_zombies
= 0);
435 virtual ~ACE_Process_Strategy ();
439 * Activate the @a svc_handler with an appropriate concurrency
440 * strategy. This method activates the SVC_HANDLER by first forking
441 * and then calling the @c open() method of the SVC_HANDLER in the
444 virtual int activate_svc_handler (SVC_HANDLER
*svc_handler
,
447 /// Dump the state of an object.
450 /// Declare the dynamic allocation hooks.
451 ACE_ALLOC_HOOK_DECLARE
;
454 typedef ACE_Concurrency_Strategy
<SVC_HANDLER
> inherited
;
456 /// Number of processes to spawn.
460 * This is the @c Acceptor in the parent is listening on. We need to
461 * make sure that we remove it from the Reactor and close it down in
464 ACE_Event_Handler
*acceptor_
;
467 * This is the reactor the child is using in conjunction with the
468 * acceptor. We need to remove the acceptor from this reactor
471 ACE_Reactor
*reactor_
;
475 * @class ACE_Accept_Strategy
477 * @brief Defines the interface for specifying a passive connection
478 * acceptance strategy for a SVC_HANDLER.
480 * This class provides a strategy that manages passive
481 * connection acceptance of a client.
483 template <class SVC_HANDLER
, ACE_PEER_ACCEPTOR_1
>
484 class ACE_Accept_Strategy
487 // Useful STL-style traits.
488 typedef ACE_PEER_ACCEPTOR_ADDR addr_type
;
489 typedef ACE_PEER_ACCEPTOR acceptor_type
;
490 typedef SVC_HANDLER handler_type
;
491 typedef typename
SVC_HANDLER::stream_type stream_type
;
493 /// Default constructor.
494 ACE_Accept_Strategy (ACE_Reactor
*reactor
= ACE_Reactor::instance ());
496 /// Initialize the @c peer_acceptor_ with @a local_addr.
497 ACE_Accept_Strategy (const ACE_PEER_ACCEPTOR_ADDR
&local_addr
,
498 bool restart
= false,
499 ACE_Reactor
*reactor
= ACE_Reactor::instance ());
501 /// Initialize the <peer_acceptor_> with @a local_addr, indicating
502 /// whether to @a reuse_addr if it's already in use.
503 virtual int open (const ACE_PEER_ACCEPTOR_ADDR
&local_addr
,
504 bool reuse_addr
= false);
506 /// Return the underlying ACE_HANDLE of the <peer_acceptor_>.
507 virtual ACE_HANDLE
get_handle () const;
509 /// Return a reference to the <peer_acceptor_>.
510 virtual ACE_PEER_ACCEPTOR
&acceptor () const;
512 virtual ~ACE_Accept_Strategy ();
515 /// The default behavior delegates to the <accept> method of the
517 virtual int accept_svc_handler (SVC_HANDLER
*);
519 /// Dump the state of an object.
522 /// Declare the dynamic allocation hooks.
523 ACE_ALLOC_HOOK_DECLARE
;
526 /// Factory that establishes connections passively.
527 ACE_PEER_ACCEPTOR peer_acceptor_
;
529 /// Pointer to the reactor used by the Acceptor.
530 ACE_Reactor
*reactor_
;
532 /// Needed to reopen the socket if <accept> fails.
535 /// Needed to reopen the socket if <accept> fails.
536 ACE_PEER_ACCEPTOR_ADDR peer_acceptor_addr_
;
540 * @class ACE_Connect_Strategy
542 * @brief Defines the interface for specifying an active
543 * connection establishment strategy for a SVC_HANDLER.
545 * This class provides a strategy that manages active
546 * connection establishment to a server.
548 template <class SVC_HANDLER
, ACE_PEER_CONNECTOR_1
>
549 class ACE_Connect_Strategy
552 // Useful STL-style traits.
553 typedef ACE_PEER_CONNECTOR_ADDR addr_type
;
554 typedef ACE_PEER_CONNECTOR connector_type
;
555 typedef SVC_HANDLER handler_type
;
556 typedef typename
SVC_HANDLER::stream_type stream_type
;
558 /// Default constructor.
559 ACE_Connect_Strategy ();
561 /// Return a reference to the <peer_connector_>.
562 virtual ACE_PEER_CONNECTOR
&connector () const;
564 virtual ~ACE_Connect_Strategy ();
567 /// The default behavior delegates to the <connect> method of the
568 /// <PEER_CONNECTOR::connect>.
569 virtual int connect_svc_handler (SVC_HANDLER
*&sh
,
570 const ACE_PEER_CONNECTOR_ADDR
&remote_addr
,
571 ACE_Time_Value
*timeout
,
572 const ACE_PEER_CONNECTOR_ADDR
&local_addr
,
578 * The default behavior delegates to the <connect> method of the
579 * <PEER_CONNECTOR::connect>.
580 * Please check the documentation in Connector.h for more details.
582 virtual int connect_svc_handler (SVC_HANDLER
*&sh
,
583 SVC_HANDLER
*&sh_copy
,
584 const ACE_PEER_CONNECTOR_ADDR
&remote_addr
,
585 ACE_Time_Value
*timeout
,
586 const ACE_PEER_CONNECTOR_ADDR
&local_addr
,
591 /// Dump the state of an object.
594 /// Declare the dynamic allocation hooks.
595 ACE_ALLOC_HOOK_DECLARE
;
598 /// Factory that establishes connections actively.
599 ACE_PEER_CONNECTOR connector_
;
603 * @class ACE_Scheduling_Strategy
605 * @brief Defines the interface for specifying how to suspend and
608 * This class provides a strategy that allows arbitrarily
609 * sophisticated service suspension and resumption. The default
610 * behavior is to do nothing...
612 template <class SVC_HANDLER
>
613 class ACE_Scheduling_Strategy
616 // Useful STL-style traits.
617 typedef typename
SVC_HANDLER::addr_type addr_type
;
618 typedef SVC_HANDLER handler_type
;
619 typedef typename
SVC_HANDLER::stream_type stream_type
;
622 ACE_Scheduling_Strategy (SVC_HANDLER
* = 0);
625 virtual ~ACE_Scheduling_Strategy ();
627 // = Scheduling methods
630 virtual int suspend ();
633 virtual int resume ();
635 /// Dump the state of the object.
636 virtual void dump () const;
640 * @class ACE_Schedule_All_Reactive_Strategy
642 * @brief Defines the interface for specifying how to suspend and
643 * resume a single-threaded reactive service .
645 * This class provides a strategy that suspends and resumes all
646 * the Event_Handlers in a Reactor in one fell swoop.
648 template <class SVC_HANDLER
>
649 class ACE_Schedule_All_Reactive_Strategy
650 : public ACE_Scheduling_Strategy
<SVC_HANDLER
>
653 // Useful STL-style traits.
654 typedef ACE_Scheduling_Strategy
<SVC_HANDLER
> base_type
;
657 ACE_Schedule_All_Reactive_Strategy (SVC_HANDLER
* = 0);
659 // = Scheduling methods
662 virtual int suspend ();
665 virtual int resume ();
667 /// Dump the state of the object.
668 virtual void dump () const;
672 ACE_Reactor
*reactor_
;
676 * @class ACE_Schedule_All_Threaded_Strategy
678 * @brief Defines the interface for specifying how to suspend and
679 * resume a multithreaded service .
681 * This class provides a strategy that suspends and resumes all
682 * the Event_Handlers controlled by a Thread_Manager in one fell swoop.
684 template <class SVC_HANDLER
>
685 class ACE_Schedule_All_Threaded_Strategy
686 : public ACE_Scheduling_Strategy
<SVC_HANDLER
>
689 // Useful STL-style traits.
690 typedef ACE_Scheduling_Strategy
<SVC_HANDLER
> base_type
;
693 ACE_Schedule_All_Threaded_Strategy (SVC_HANDLER
* = 0);
695 // = Scheduling methods
698 virtual int suspend ();
701 virtual int resume ();
703 /// Dump the state of the object.
704 virtual void dump () const;
708 ACE_Thread_Manager
*thr_mgr_
;
712 * @class ACE_NOOP_Creation_Strategy
714 * @brief Implements a no-op creation strategy in order to defer
715 * decisions regarding creation to some later point in time, such
716 * as in connect or accept strategy.
718 * An example of the use of this is in the
719 * ACE_Cached_Connect_Strategy, which only returns a single
720 * connection for a given endpoint.
722 template <class SVC_HANDLER
>
723 class ACE_NOOP_Creation_Strategy
: public ACE_Creation_Strategy
<SVC_HANDLER
>
726 // Useful STL-style traits.
727 typedef ACE_Creation_Strategy
<SVC_HANDLER
> base_type
;
730 virtual int make_svc_handler (SVC_HANDLER
*&);
734 * @class ACE_NOOP_Concurrency_Strategy
736 * @brief Implements a no-op activation strategy in order to avoid
737 * calling open on a svc_handler multiple times.
739 * An example of the use of this is in the
740 * ACE_Cached_Connect_Strategy, which reuses svc_handlers.
741 * Therefore we don't want to call open on the recycled
742 * svc_handler more than once.
744 template <class SVC_HANDLER
>
745 class ACE_NOOP_Concurrency_Strategy
746 : public ACE_Concurrency_Strategy
<SVC_HANDLER
>
749 // Useful STL-style traits.
750 typedef ACE_Concurrency_Strategy
<SVC_HANDLER
> base_type
;
754 virtual int activate_svc_handler (SVC_HANDLER
*svc_handler
,
759 class ACE_Refcounted_Hash_Recyclable
: public ACE_Refcountable_T
<ACE_Null_Mutex
>,
761 public ACE_Recyclable
764 /// Default constructor.
765 ACE_Refcounted_Hash_Recyclable ();
768 ACE_Refcounted_Hash_Recyclable (const T
&t
,
770 ACE_Recyclable_State state
= ACE_RECYCLABLE_UNKNOWN
);
773 virtual ~ACE_Refcounted_Hash_Recyclable ();
775 /// Compares two instances.
776 bool operator== (const ACE_Refcounted_Hash_Recyclable
<T
> &rhs
) const;
777 bool operator!= (const ACE_Refcounted_Hash_Recyclable
<T
> &rhs
) const;
782 /// Computes and returns hash value.
783 u_long
hash_i () const;
789 * @class ACE_Cached_Connect_Strategy
791 * @brief A connection strategy which caches connections to peers
792 * (represented by SVC_HANDLER instances), thereby allowing
793 * subsequent re-use of unused, but available, connections.
795 * <ACE_Cached_Connect_Strategy> is intended to be used as a
796 * plug-in connection strategy for ACE_Strategy_Connector.
797 * It's added value is re-use of established connections.
799 template <class SVC_HANDLER
, ACE_PEER_CONNECTOR_1
, class MUTEX
>
800 class ACE_Cached_Connect_Strategy
801 : public ACE_Connection_Recycling_Strategy
,
802 public ACE_Connect_Strategy
<SVC_HANDLER
, ACE_PEER_CONNECTOR_2
>
805 // Useful STL-style traits.
806 typedef ACE_Creation_Strategy
<SVC_HANDLER
>
807 creation_strategy_type
;
808 typedef ACE_Connect_Strategy
<SVC_HANDLER
, ACE_PEER_CONNECTOR_2
>
809 connect_strategy_type
;
810 typedef ACE_Concurrency_Strategy
<SVC_HANDLER
>
811 concurrency_strategy_type
;
812 typedef ACE_Recycling_Strategy
<SVC_HANDLER
> recycling_strategy_type
;
814 // = Define some useful (old style) traits.
815 typedef ACE_Creation_Strategy
<SVC_HANDLER
>
817 typedef ACE_Concurrency_Strategy
<SVC_HANDLER
>
818 CONCURRENCY_STRATEGY
;
819 typedef ACE_Recycling_Strategy
<SVC_HANDLER
>
823 typedef ACE_Connect_Strategy
<SVC_HANDLER
, ACE_PEER_CONNECTOR_2
>
827 typedef ACE_Cached_Connect_Strategy
<SVC_HANDLER
, ACE_PEER_CONNECTOR_2
, MUTEX
> SELF
;
830 ACE_Cached_Connect_Strategy (ACE_Creation_Strategy
<SVC_HANDLER
> *cre_s
= 0,
831 ACE_Concurrency_Strategy
<SVC_HANDLER
> *con_s
= 0,
832 ACE_Recycling_Strategy
<SVC_HANDLER
> *rec_s
= 0,
834 bool delete_lock
= false);
837 virtual ~ACE_Cached_Connect_Strategy ();
839 /// This methods allow you to change the strategies used by the
840 /// cached connector.
841 virtual int open (ACE_Creation_Strategy
<SVC_HANDLER
> *cre_s
,
842 ACE_Concurrency_Strategy
<SVC_HANDLER
> *con_s
,
843 ACE_Recycling_Strategy
<SVC_HANDLER
> *rec_s
);
845 /// Template method for making a new <svc_handler>
846 virtual int make_svc_handler (SVC_HANDLER
*&sh
);
848 /// Template method for activating a new @a svc_handler
849 virtual int activate_svc_handler (SVC_HANDLER
*svc_handler
);
851 /// Template method for setting the recycler information of the
853 virtual int assign_recycler (SVC_HANDLER
*svc_handler
,
854 ACE_Connection_Recycling_Strategy
*recycler
,
855 const void *recycling_act
);
857 /// Template method for preparing the svc_handler for recycling.
858 virtual int prepare_for_recycling (SVC_HANDLER
*svc_handler
);
861 * Checks to see if there is already a <SVC_HANDLER> in the cache
862 * connected to the <remote_addr>. If so, we return this pointer.
863 * Otherwise we establish the connection, put it into the cache, and
864 * return the SVC_HANDLER pointer. <[NOTE]>: the <{reuse_addr}>
865 * argument does NOT control re-use of addresses in the cache.
866 * Rather, if the underlying protocol requires a "dead time" prior
867 * to re-use of its addresses (TCP is a classic example of this),
868 * <{and}> the protocol provides a means by which to defeat the dead
869 * time, setting this argument to non-zero will defeat the dead-time
870 * requirement. <{Dev. Note: We might want to consider enhancing
871 * the interface at some point so that this also controls re-use of
874 virtual int connect_svc_handler (SVC_HANDLER
*&sh
,
875 const ACE_PEER_CONNECTOR_ADDR
&remote_addr
,
876 ACE_Time_Value
*timeout
,
877 const ACE_PEER_CONNECTOR_ADDR
&local_addr
,
881 virtual int connect_svc_handler (SVC_HANDLER
*&sh
,
882 SVC_HANDLER
*&sh_copy
,
883 const ACE_PEER_CONNECTOR_ADDR
&remote_addr
,
884 ACE_Time_Value
*timeout
,
885 const ACE_PEER_CONNECTOR_ADDR
&local_addr
,
890 /// Remove from cache.
891 virtual int purge (const void *recycling_act
);
894 virtual int cache (const void *recycling_act
);
896 /// Get/Set <recycle_state>.
897 virtual int recycle_state (const void *recycling_act
,
898 ACE_Recyclable_State new_state
);
899 virtual ACE_Recyclable_State
recycle_state (const void *recycling_act
) const;
902 virtual int mark_as_closed (const void *recycling_act
);
905 * Mark as closed (non-locking version). This method needs to be public
906 * as it is used in the cleanup of handlers where teh locked version causes
909 virtual int mark_as_closed_i (const void *recycling_act
);
911 /// Cleanup hint and reset <*act_holder> to zero if <act_holder != 0>.
912 virtual int cleanup_hint (const void *recycling_act
,
913 void **act_holder
= 0);
915 // = Traits for managing the map
916 typedef ACE_Refcounted_Hash_Recyclable
<ACE_PEER_CONNECTOR_ADDR
>
917 REFCOUNTED_HASH_RECYCLABLE_ADDRESS
;
918 typedef ACE_Hash_Map_Manager_Ex
<REFCOUNTED_HASH_RECYCLABLE_ADDRESS
, SVC_HANDLER
*, ACE_Hash
<REFCOUNTED_HASH_RECYCLABLE_ADDRESS
>, ACE_Equal_To
<REFCOUNTED_HASH_RECYCLABLE_ADDRESS
>, ACE_Null_Mutex
>
921 typedef typename
CONNECTION_MAP::ITERATOR CONNECTION_MAP_ITERATOR
;
922 typedef typename
CONNECTION_MAP::ENTRY CONNECTION_MAP_ENTRY
;
924 typedef ACE_Reverse_Lock
<MUTEX
> REVERSE_MUTEX
;
926 // = Strategy accessors
927 virtual ACE_Creation_Strategy
<SVC_HANDLER
> *creation_strategy () const;
928 virtual ACE_Recycling_Strategy
<SVC_HANDLER
> *recycling_strategy () const;
929 virtual ACE_Concurrency_Strategy
<SVC_HANDLER
> *concurrency_strategy () const;
932 /// Creates a new connection.
933 virtual int new_connection (SVC_HANDLER
*&sh
,
934 const ACE_PEER_CONNECTOR_ADDR
&remote_addr
,
935 ACE_Time_Value
*timeout
,
936 const ACE_PEER_CONNECTOR_ADDR
&local_addr
,
941 /// Find an idle handle.
942 int find (REFCOUNTED_HASH_RECYCLABLE_ADDRESS
&search_addr
,
943 CONNECTION_MAP_ENTRY
*&entry
);
945 /// Remove from cache (non-locking version).
946 virtual int purge_i (const void *recycling_act
);
948 /// Add to cache (non-locking version).
949 virtual int cache_i (const void *recycling_act
);
951 /// Set <recycle_state> (non-locking version).
952 virtual int recycle_state_i (const void *recycling_act
,
953 ACE_Recyclable_State new_state
);
955 /// Get <recycle_state> (non-locking version).
956 virtual ACE_Recyclable_State
recycle_state_i (const void *recycling_act
) const;
958 /// Cleanup hint and reset <*act_holder> to zero if <act_holder != 0>.
959 virtual int cleanup_hint_i (const void *recycling_act
,
963 int check_hint_i (SVC_HANDLER
*&sh
,
964 const ACE_PEER_CONNECTOR_ADDR
&remote_addr
,
965 ACE_Time_Value
*timeout
,
966 const ACE_PEER_CONNECTOR_ADDR
&local_addr
,
970 CONNECTION_MAP_ENTRY
*&entry
,
973 int find_or_create_svc_handler_i (SVC_HANDLER
*&sh
,
974 const ACE_PEER_CONNECTOR_ADDR
&remote_addr
,
975 ACE_Time_Value
*timeout
,
976 const ACE_PEER_CONNECTOR_ADDR
&local_addr
,
980 CONNECTION_MAP_ENTRY
*&entry
,
983 virtual int connect_svc_handler_i (
985 const ACE_PEER_CONNECTOR_ADDR
&remote_addr
,
986 ACE_Time_Value
*timeout
,
987 const ACE_PEER_CONNECTOR_ADDR
&local_addr
,
993 /// Table that maintains the cache of connected SVC_HANDLERs.
994 CONNECTION_MAP connection_map_
;
996 /// Mutual exclusion for this object.
999 /// Mutual exclusion for this object.
1003 REVERSE_MUTEX
*reverse_lock_
;
1005 // = Strategy objects.
1007 /// Creation strategy for an <Connector>.
1008 CREATION_STRATEGY
*creation_strategy_
;
1010 /// true if <Connector> created the creation strategy and thus should
1011 /// delete it, else false.
1012 bool delete_creation_strategy_
;
1014 /// Concurrency strategy for an <Connector>.
1015 CONCURRENCY_STRATEGY
*concurrency_strategy_
;
1017 /// true if <Connector> created the concurrency strategy and thus should
1018 /// delete it, else false.
1019 bool delete_concurrency_strategy_
;
1021 /// Recycling strategy for an <Connector>.
1022 RECYCLING_STRATEGY
*recycling_strategy_
;
1024 /// true if <Connector> created the recycling strategy and thus should
1025 /// delete it, else false.
1026 bool delete_recycling_strategy_
;
1029 ACE_END_VERSIONED_NAMESPACE_DECL
1031 #if defined (__ACE_INLINE__)
1032 #include "ace/Strategies_T.inl"
1033 #endif /* __ACE_INLINE__ */
1035 #include "ace/Strategies_T.cpp"
1037 #include /**/ "ace/post.h"
1039 #endif /* ACE_STRATEGIES_T_H */