summaryrefslogtreecommitdiff
path: root/TAO/tao/Sync_Strategies.h
blob: d04bad05eeb4bbbbc6543e617ff8939c6d5b9b66 (plain)
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
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Sync_Strategies.h
 *
 *  $Id$
 *
 *   Sync Strategies for the ORB Messaging layer.
 *
 *
 *  @author  Irfan Pyarali
 */
//=============================================================================


#ifndef TAO_SYNC_STRATEGIES_H
#define TAO_SYNC_STRATEGIES_H
#include "ace/pre.h"

#include "tao/corbafwd.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "tao/Transport.h"
#include "tao/TAOC.h"

/// Define the interface for the Queueing Strategy
/**
 * The low-level I/O components in the ORB use this strategy to
 * determine when messages must be queued, immediately sent or
 * flushed.
 *
 * The strategy isolates this low-level components from the higher
 * level strategies used by the application developer.
 *
 * @todo The class name (Sync_Strategy) is inherited from the policies
 * (SyncScopePolicy), but Queueing_Strategy probably captures its
 * intent better.  It should be changed in a future revision of the
 * ORB.
 */
class TAO_Export TAO_Sync_Strategy
{
public:
  /// Destructor
  virtual ~TAO_Sync_Strategy (void);

  /// Return 1 if a message must be queued
  virtual int must_queue (int queue_empty) = 0;

  /// Return 1 if it is time to start
  /**
   * @param stub The object used to make the request, this is used to
   *        obtain the policies currently in effect for the request
   * @param msg_count The number of messages currently queued
   * @param total_bytes Number of bytes currently queued
   * @param set_timer Returns 1 if a timer should be set to drain the
   *        queue
   * @param interval If set_timer returns 1, this parameter contains
   *        the timer interval
   */
  virtual int buffering_constraints_reached (TAO_Stub *stub,
                                             size_t msg_count,
                                             size_t total_bytes,
                                             int &must_flush,
                                             int &set_timer,
                                             ACE_Time_Value &interval) = 0;
};

class TAO_Export TAO_Transport_Sync_Strategy : public TAO_Sync_Strategy
{
public:
  virtual int must_queue (int queue_empty);

  virtual int buffering_constraints_reached (TAO_Stub *stub,
                                             size_t msg_count,
                                             size_t total_bytes,
                                             int &must_flush,
                                             int &set_timer,
                                             ACE_Time_Value &interval);
};

#if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)

class TAO_Export TAO_Eager_Buffering_Sync_Strategy : public TAO_Sync_Strategy
{
public:
  virtual int must_queue (int queue_empty);

  virtual int buffering_constraints_reached (TAO_Stub *stub,
                                             size_t msg_count,
                                             size_t total_bytes,
                                             int &must_flush,
                                             int &set_timer,
                                             ACE_Time_Value &interval);

private:
  /// Check if the buffering constraint includes any timeouts and
  /// compute the right timeout interval if needed.
  /**
   * @param buffering_constraint The constraints defined by the
   *        application
   * @param set_timer Return 1 if the timer should be set
   * @param interval Return the timer interval value
   */
  void timer_check (const TAO::BufferingConstraint &buffering_constraint,
                    int &set_timer,
                    ACE_Time_Value &interval);

  /// Convert from standard CORBA time units to seconds/microseconds.
  ACE_Time_Value time_conversion (const TimeBase::TimeT &time);
};

/// Delay the buffering decision until the transport blocks
/**
 * If the queue is empty the transport will try to send immediately.
 */
class TAO_Export TAO_Delayed_Buffering_Sync_Strategy : public TAO_Eager_Buffering_Sync_Strategy
{
public:
  virtual int must_queue (int queue_empty);
};

#endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */

#if defined (__ACE_INLINE__)
# include "tao/Sync_Strategies.i"
#endif /* __ACE_INLINE__ */

#include "ace/post.h"
#endif /* TAO_SYNC_STRATEGIES_H */