StreamBase C++ API  7.7.1.3
DequeueResult.hpp
1 // Copyright (c) 2004-2017 Cloud Software Group, Inc. All rights reserved.
2 
3 #ifndef DEQUEUE_RESULT_H
4 #define DEQUEUE_RESULT_H
5 
6 #include "StreamBase.hpp"
7 
8 #include "StreamProperties.hpp"
9 #include "Tuple.hpp"
10 #include "TupleList.hpp"
11 #include "StreamBaseURI.hpp"
12 #include "StreamBaseConstants.hpp"
13 
14 SB_INTERNAL_FWD(DequeueResultUtil);
15 
16 SB_NAMESPACE_BEGIN;
17 
18 /// Null value encountered
19 STREAMBASE_EXCEPTION_TYPE(ArgumentOutOfRange, sb_internal::Errors::NON_FATAL_ERROR);
20 
21 /// Encapsulates the data returned from a dequeue() operation.
22 /// Contains a stream name and a list of tuples.
24 public:
25 #ifndef SWIG // not supported by SWIG, and not especially useful in scripting languages anyway
26  ///
27  /// A callback interface that can be implemented by an object that is associated with
28  /// a StreamBaseClient and which gets used in the course of dequeuing tuples.
29  ///
30  class Interceptor {
31  public:
32  /// SUPPRESSED is a flag used to signify that the results from processResult should
33  /// be suppressed.
34  static const DequeueResult SUPPRESSED;
35 
36  virtual ~Interceptor() {}
37  ///
38  /// Take a DequeueResult and modify it. Returns the same object if
39  /// there are no changes. Returns SUPPRESSED if results should
40  /// be suppressed.
41  /// May return a different DequeueResult object.
42  ///
43  virtual DequeueResult processResult(const DequeueResult &results) {
44  // do nothing
45  return results;
46  }
47  };
48 #endif
49 
50  /// Possible Dequeue results status
51  enum Status {
52  UNINITIALIZED = 0,
53  GOOD = 1,
54  TIMEOUT = 2,
55  CLOSED = 3,
56  };
57 
58  /// Default (null) Constructor
59  DequeueResult() : _status(UNINITIALIZED), _leadershipStatus(LEADER) {};
60 
61  /// Create a Dequeue Result with a list of tuples, with the given LeadershipStatus
62  DequeueResult(const StreamProperties &props,
63  const TupleList& tuples,
64  const StreamBaseURI &serverURI,
65  LeadershipStatus _leadershipStatus);
66 
67  virtual ~DequeueResult();
68 
69  /// Currently a no-op maintained for backwards compatibility
70  /// @deprecated
71  void reuseTuple() { }
72 
73  /// Return the status of this DequeueResult.
74  /// DequeueResult::GOOD means the DequeueResult contains tuples.
75  /// @return the status of this DequeueResult
76  const DequeueResult::Status getStatus() const;
77 
78  /// Returns the name of the stream on which tuples were dequeued.
79  const std::string& getStreamName() const;
80 
81  /// Returns the number of tuples dequeued.
82  int getTupleCount() const;
83 
84  /// Returns the StreamProperties for this DequeueResult
85  const StreamProperties& getStreamProperties() const;
86 
87  /// Returns the index'th tuple.
88  const Tuple& getTuple(int index) const;
89 
90  /// Returns the list of tuples
91  const TupleList& getTuples() const;
92 
93  /// Return the leadership status of the server that produced this dequeue result.
94  LeadershipStatus getLeadershipStatus() const {
95  return _leadershipStatus;
96  }
97 
98  /// return the server that produced these results
99  const StreamBaseURI &getServerURI() const {
100  return _serverURI;
101  }
102 private:
103  /// create a DequeueResult with the given DequeueResult status and LeadershipStatus
104  DequeueResult(DequeueResult::Status status, LeadershipStatus leadershipStatus);
105 
106  friend class sb_internal::DequeueResultUtil;
107 
108  TupleList _tuples;
109  StreamProperties _props;
110  bool _isLogicalControlStreamMessage;
111  DequeueResult::Status _status;
112  LeadershipStatus _leadershipStatus;
113  StreamBaseURI _serverURI;
114 };
115 
116 SB_NAMESPACE_END;
117 #endif
118