1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
|
/* -*- C++ -*- */
// $Id$
// ============================================================================
//
// = LIBRARY
// ace
//
// = FILENAME
// ACE_Strategies_T.h
//
// = AUTHOR
// Doug Schmidt
//
// ============================================================================
#if !defined (ACE_STRATEGIES_T_H)
#define ACE_STRATEGIES_T_H
#include "ace/Service_Config.h"
#include "ace/Synch_Options.h"
template <class SVC_HANDLER>
class ACE_Creation_Strategy
// = TITLE
// Defines the interface for specifying a creation strategy for
// a SVC_HANDLER.
//
// = DESCRIPTION
// The default behavior is to make a new SVC_HANDLER. However,
// subclasses can override this strategy to perform SVC_HANDLER
// creation in any way that they like (such as creating subclass
// instances of SVC_HANDLER, using a singleton, dynamically
// linking the handler, etc.).
{
public:
// = Initialization and termination methods.
ACE_Creation_Strategy (ACE_Thread_Manager * = 0);
// Default constructor.
int open (ACE_Thread_Manager * = 0);
// A <Thread_Manager> is useful when creating active objects.
virtual ~ACE_Creation_Strategy (void);
// = Factory method.
virtual int make_svc_handler (SVC_HANDLER *&sh);
// Create a SVC_HANDLER with the appropriate creation strategy. The
// default behavior of this method is to make a new <SVC_HANDLER> if
// <sh> == 0 (passing in the <Thread_Manager>), else <sh> is
// unchanged. Returns -1 on failure, else 0.
void dump (void) const;
// Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
protected:
ACE_Thread_Manager *thr_mgr_;
// Pointer to a thread manager.
};
template <class SVC_HANDLER>
class ACE_Singleton_Strategy : public ACE_Creation_Strategy<SVC_HANDLER>
// = TITLE
// Defines the interface for specifying a creation strategy for
// a <SVC_HANDLER> that always returns the same <SVC_HANDLER> (i.e.,
// it's a Singleton).
//
// = DESCRIPTION
// Note that this class takes over the ownership of the
// SVC_HANDLER passed into it as a parameter and it becomes
// responsible for deleting this object.
{
public:
// = Initialization and termination methods.
ACE_Singleton_Strategy (SVC_HANDLER * = 0,
ACE_Thread_Manager * = 0);
int open (SVC_HANDLER *,
ACE_Thread_Manager * = 0);
virtual ~ACE_Singleton_Strategy (void);
// = Factory method.
virtual int make_svc_handler (SVC_HANDLER *&);
// Create a Singleton SVC_HANDLER by always returning the same
// SVC_HANDLER. Returns -1 on failure, else 0.
void dump (void) const;
// Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
protected:
SVC_HANDLER *svc_handler_;
// Pointer to the Singleton svc_handler.
};
template <class SVC_HANDLER>
class ACE_DLL_Strategy : public ACE_Creation_Strategy<SVC_HANDLER>
// = TITLE
// Defines the interface for specifying a creation strategy for
// a SVC_HANDLER based on dynamic linking of the SVC_HANDLER.
{
public:
// = Intialization and termination methods.
ACE_DLL_Strategy (void);
// "Do-nothing" constructor.
ACE_DLL_Strategy (const char svc_dll_info[],
ACE_Service_Config *,
ACE_Thread_Manager * = 0);
// Initialize the DLL strategy based upon the service's DLL
// information contained in the <svc_dll_info> string.
int open (const char svc_dll_info[],
ACE_Service_Config *,
ACE_Thread_Manager * = 0);
// Initialize the DLL strategy based upon the service's DLL
// information contained in the <svc_dll_info> string.
// = Factory method.
virtual int make_svc_handler (SVC_HANDLER *&);
// Create a SVC_HANDLER by dynamically linking it from a DLL.
// Returns -1 on failure, else 0.
void dump (void) const;
// Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
protected:
typedef ACE_Creation_Strategy<SVC_HANDLER> inherited;
char shared_library_[MAXPATHLEN];
// Name of the shared library to dynamically link.
char factory_function_[MAXPATHLEN];
// Name of the factory function in the shared library to use to
// obtain a pointer to the new SVC_HANDLER.
char svc_name[MAXNAMELEN];
// Name of the service.
ACE_Service_Config *svc_config_;
// Pointer to the Service_Configurator.
};
template <class SVC_HANDLER>
class ACE_Concurrency_Strategy
// = TITLE
// Defines the interface for specifying a concurrency strategy
// for a SVC_HANDLER.
//
// = DESCRIPTION
// Default behavior is to activate the SVC_HANDLER by calling
// its open() method (which allows the SVC_HANDLER to define its
// own concurrency strategy). However, subclasses can override
// this default strategy to do more sophisticated concurrency
// activations (such as creating the SVC_HANDLER as an active
// object via multi-threading or multi-processing).
{
public:
// = Factory method.
virtual int activate_svc_handler (SVC_HANDLER *svc_handler,
void *arg = 0);
// Activate the <svc_handler> with an appropriate concurrency
// strategy. The default behavior of this method is to activate the
// SVC_HANDLER by calling its open() method (which allows the
// SVC_HANDLER to define its own concurrency strategy).
virtual ~ACE_Concurrency_Strategy (void);
void dump (void) const;
// Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
};
template <class SVC_HANDLER>
class ACE_Reactive_Strategy : public ACE_Concurrency_Strategy <SVC_HANDLER>
// = TITLE
// Defines the interface for specifying a Reactive concurrency
// strategy for a SVC_HANDLER.
//
// = DESCRIPTION
// This class provides a strategy that registers the
// <SVC_HANDLER> with a <Reactor>.
{
public:
// = Intialization and termination methods.
ACE_Reactive_Strategy (void);
// "Do-nothing constructor"
ACE_Reactive_Strategy (ACE_Reactor *reactor,
ACE_Reactor_Mask = ACE_Event_Handler::READ_MASK);
// Initialize the strategy.
virtual int open (ACE_Reactor *reactor,
ACE_Reactor_Mask = ACE_Event_Handler::READ_MASK);
// Initialize the strategy.
virtual ~ACE_Reactive_Strategy (void);
// Destructor.
// = Factory method.
virtual int activate_svc_handler (SVC_HANDLER *svc_handler,
void *arg = 0);
// Activate the <svc_handler> by registering it with the <Reactor>
// and then calling it's <open> hook.
void dump (void) const;
// Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
protected:
typedef ACE_Concurrency_Strategy<SVC_HANDLER> inherited;
ACE_Reactor *reactor_;
// Pointer to the Reactor we'll use to register the <SVC_HANDLER>.
ACE_Reactor_Mask mask_;
// The mask that we pass to the <Reactor> when we register the
// <SVC_HANDLER>.
};
template <class SVC_HANDLER>
class ACE_Thread_Strategy : public ACE_Concurrency_Strategy<SVC_HANDLER>
// = TITLE
// Defines the interface for specifying a concurrency strategy
// for a <SVC_HANDLER> based on multithreading.
//
// = DESCRIPTION
// This class provides a strategy that manages the creation of
// threads to handle requests from clients concurrently. It
// behaves as a "thread factory", spawning threads "on-demand"
// to run the service specified by a user-supplied
// <SVC_HANDLER>.
{
public:
// = Intialization and termination methods.
ACE_Thread_Strategy (void);
// "Do-nothing constructor"
ACE_Thread_Strategy (ACE_Thread_Manager *tm,
long thr_flags,
size_t n_threads = 1);
// Initialize the strategy.
virtual int open (ACE_Thread_Manager *tm,
long thr_flags,
size_t n_threads = 1);
// Initialize the strategy.
virtual ~ACE_Thread_Strategy (void);
// = Factory method.
virtual int activate_svc_handler (SVC_HANDLER *svc_handler,
void *arg = 0);
// Activate the <svc_handler> with an appropriate concurrency
// strategy. This method activates the SVC_HANDLER by first calling
// its open() method and then calling its activate() method to turn
// it into an active object.
void dump (void) const;
// Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
protected:
typedef ACE_Concurrency_Strategy<SVC_HANDLER> inherited;
ACE_Thread_Manager *thr_mgr_;
// Thread manager for this class (must be provided).
long thr_flags_;
// Flags to pass into the SVC_HANDLER::activate() method.
size_t n_threads_;
// Number of threads to spawn.
};
template <class SVC_HANDLER>
class ACE_Process_Strategy : public ACE_Concurrency_Strategy<SVC_HANDLER>
// = TITLE
// Defines the interface for specifying a concurrency strategy
// for a <SVC_HANDLER> based on multiprocessing.
//
// = DESCRIPTION
// This class provides a strategy that manages the creation of
// processes to handle requests from clients concurrently. It
// behaves as a "process factory", forking threads "on-demand"
// to run the service specified by a user-supplied
// <SVC_HANDLER>.
{
public:
// = Intialization and termination methods.
ACE_Process_Strategy (size_t n_processes = 1,
ACE_Event_Handler *acceptor = 0,
ACE_Reactor * = 0);
// Initialize the strategy.
virtual int open (size_t n_processes = 1,
ACE_Event_Handler *acceptor = 0,
ACE_Reactor * = 0);
// Initialize the strategy.
virtual ~ACE_Process_Strategy (void);
// = Factory method.
virtual int activate_svc_handler (SVC_HANDLER *svc_handler,
void *arg = 0);
// Activate the <svc_handler> with an appropriate concurrency
// strategy. This method activates the SVC_HANDLER by first forking
// and then calling the open() method of the SVC_HANDLER in the
// child.
void dump (void) const;
// Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
protected:
typedef ACE_Concurrency_Strategy<SVC_HANDLER> inherited;
size_t n_processes_;
// Number of processes to spawn.
ACE_Event_Handler *acceptor_;
// This is the <Acceptor> in the parent is listening on. We need to
// make sure that we remove it from the Reactor and close it down in
// the child.
ACE_Reactor *reactor_;
// This is the <Reactor> the child is using in conjunction with the
// <Acceptor>. We need to remove the <Acceptor> from this <Reactor>
// in the child.
};
template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1>
class ACE_Accept_Strategy
// = TITLE
// Defines the interface for specifying a passive connection
// acceptance strategy for a SVC_HANDLER.
//
// = DESCRIPTION
// This class provides a strategy that manages passive
// connection acceptance of a client.
{
public:
// = Initialization and termination methods.
ACE_Accept_Strategy (void);
// Default constructor.
ACE_Accept_Strategy (const ACE_PEER_ACCEPTOR_ADDR &local_addr,
int restart = 0);
// Initialize the <peer_acceptor_> with <local_addr>.
virtual int open (const ACE_PEER_ACCEPTOR_ADDR &local_addr,
int restart = 0);
// Initialize the <peer_acceptor_> with <local_addr>.
virtual ACE_HANDLE get_handle (void) const;
// Return the underlying ACE_HANDLE of the <peer_acceptor_>.
virtual ACE_PEER_ACCEPTOR &acceptor (void) const;
// Return a reference to the <peer_acceptor_>.
virtual ~ACE_Accept_Strategy (void);
// = Factory method.
virtual int accept_svc_handler (SVC_HANDLER *);
// The default behavior delegates to the <accept> method of the
// PEER_ACCEPTOR.
void dump (void) const;
// Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
protected:
ACE_PEER_ACCEPTOR acceptor_;
// Factory that establishes connections passively.
};
template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1>
class ACE_Connect_Strategy
// = TITLE
// Defines the interface for specifying an active
// connection establishment strategy for a SVC_HANDLER.
//
// = DESCRIPTION
// This class provides a strategy that manages active
// connection establishment to a server.
{
public:
// = Initialization and termination methods.
ACE_Connect_Strategy (void);
// Default constructor.
virtual ACE_PEER_CONNECTOR &connector (void) const;
// Return a reference to the <peer_connector_>.
virtual ~ACE_Connect_Strategy (void);
// = Factory method.
virtual int connect_svc_handler (SVC_HANDLER *&sh,
const ACE_PEER_CONNECTOR_ADDR &remote_addr,
ACE_Time_Value *timeout,
const ACE_PEER_CONNECTOR_ADDR &local_addr,
int reuse_addr,
int flags,
int perms);
// The default behavior delegates to the <connect> method of the
// <PEER_CONNECTOR::connect>.
void dump (void) const;
// Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
protected:
ACE_PEER_CONNECTOR connector_;
// Factory that establishes connections actively.
};
template <class SVC_HANDLER>
class ACE_Scheduling_Strategy
// = TITLE
// Defines the interface for specifying how to suspend and
// resume a service .
//
// = DESCRIPTION
// This class provides a strategy that allows arbitrarily
// sophisticated service suspension and resumption. The default
// behavior is to do nothing...
{
public:
// = Initialization and termination methods.
ACE_Scheduling_Strategy (SVC_HANDLER * = 0);
// Constructor
virtual ~ACE_Scheduling_Strategy (void);
// Destructor
// = Scheduling methods
virtual int suspend (void);
// Suspend hook.
virtual int resume (void);
// Resume hook.
virtual void dump (void) const;
// Dump the state of the object.
protected:
SVC_HANDLER *scheduler_;
// Points to the scheduler strategy object...
int delete_scheduler_;
// Keeps track of whether we need to delete this or not...
};
template <class SVC_HANDLER>
class ACE_Schedule_All_Reactive_Strategy : public ACE_Scheduling_Strategy<SVC_HANDLER>
// = TITLE
// Defines the interface for specifying how to suspend and
// resume a single-threaded reactive service .
//
// = DESCRIPTION
// This class provides a strategy that suspends and resumes all
// the Event_Handlers in a Reactor in one fell swoop.
{
public:
// = Initialization and termination methods.
ACE_Schedule_All_Reactive_Strategy (SVC_HANDLER * = 0);
// Constructor
// = Scheduling methods
virtual int suspend (void);
// Suspend hook.
virtual int resume (void);
// Resume hook.
virtual void dump (void) const;
// Dump the state of the object.
};
template <class SVC_HANDLER>
class ACE_Schedule_All_Threaded_Strategy : public ACE_Scheduling_Strategy<SVC_HANDLER>
// = TITLE
// Defines the interface for specifying how to suspend and
// resume a multithreaded service .
//
// = DESCRIPTION
// This class provides a strategy that suspends and resumes all
// the Event_Handlers controlled by a Thread_Manager in one fell swoop.
{
public:
// = Initialization and termination methods.
ACE_Schedule_All_Threaded_Strategy (SVC_HANDLER * = 0);
// Constructor
// = Scheduling methods
virtual int suspend (void);
// Suspend hook.
virtual int resume (void);
// Resume hook.
virtual void dump (void) const;
// Dump the state of the object.
};
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "ace/Strategies_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Strategies_T.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
#endif /* ACE_STRATEGIES_T_H */
|