Dripline-Cpp  v2.4.2
Dripline Implementation in C++
service.hh
Go to the documentation of this file.
1 /*
2  * service.hh
3  *
4  * Created on: Jan 5, 2016
5  * Author: N.S. Oblath
6  */
7 
8 #ifndef DRIPLINE_SERVICE_HH_
9 #define DRIPLINE_SERVICE_HH_
10 
11 #include "core.hh"
12 #include "endpoint.hh"
13 #include "heartbeater.hh"
14 #include "scheduler.hh"
15 #include "listener.hh"
16 #include "receiver.hh"
17 
18 #include "dripline_exceptions.hh"
19 #include "uuid.hh"
20 
21 #include <map>
22 #include <memory>
23 #include <set>
24 #include <vector>
25 
26 namespace dripline
27 {
28 
73  public core,
74  public endpoint,
75  public listener_receiver,
76  public heartbeater,
77  public scheduler<>,
78  public std::enable_shared_from_this< service >
79  {
80  protected:
81  enum class status
82  {
83  nothing = 0,
84  channel_created = 10,
85  exchange_declared = 20,
86  queue_declared = 30,
87  queue_bound = 40,
88  consuming = 50,
89  listening = 60,
90  processing = 70
91  };
92 
93  public:
94  service( const scarab::param_node& a_config = scarab::param_node(), const std::string& a_queue_name = "", const std::string& a_broker_address = "", unsigned a_port = 0, const std::string& a_auth_file = "", const bool a_make_connection = true );
95  service( const bool a_make_connection, const scarab::param_node& a_config = scarab::param_node() );
96  service( const service& ) = delete;
97  service( service&& a_orig );
98  virtual ~service();
99 
100  service& operator=( const service& ) = delete;
101  service& operator=( service&& a_orig );
102 
103  mv_accessible( status, status );
104  mv_accessible( bool, enable_scheduling );
105 
106  public:
108  bool add_child( endpoint_ptr_t a_endpoint_ptr );
109 
111  bool add_async_child( endpoint_ptr_t a_endpoint_ptr );
112 
113  public:
115  virtual sent_msg_pkg_ptr send( request_ptr_t a_request ) const;
116 
118  virtual sent_msg_pkg_ptr send( reply_ptr_t a_reply ) const;
119 
121  virtual sent_msg_pkg_ptr send( alert_ptr_t a_alert ) const;
122 
123  public:
126  bool start();
127 
130  bool listen();
131 
134  bool stop();
135 
136  protected:
137  virtual bool open_channels();
138 
139  virtual bool setup_queues();
140 
141  virtual bool bind_keys();
142 
143  virtual bool start_consuming();
144 
145  virtual bool stop_consuming();
146 
147  virtual bool remove_queue();
148 
149  public:
151  virtual bool listen_on_queue();
152 
154  virtual void submit_message( message_ptr_t a_message );
155 
157  virtual void send_reply( reply_ptr_t a_reply ) const;
158 
159  mv_accessible( uuid_t, id );
160 
161  public:
162  typedef std::map< std::string, endpoint_ptr_t > sync_map_t;
163  mv_referrable( sync_map_t, sync_children );
164 
165  typedef std::map< std::string, lr_ptr_t > async_map_t;
166  mv_referrable( async_map_t, async_children );
167 
168  mv_referrable( std::string, broadcast_key );
169 
170  protected:
171  virtual reply_ptr_t on_request_message( const request_ptr_t a_request );
172 
173  private:
174  virtual void do_cancellation( int a_code );
175  };
176 
177  inline sent_msg_pkg_ptr service::send( request_ptr_t a_request ) const
178  {
179  a_request->sender_service_name() = f_name;
180  return core::send( a_request );
181  }
182 
184  {
185  a_reply->sender_service_name() = f_name ;
186  return core::send( a_reply );
187  }
188 
190  {
191  a_alert->sender_service_name() = f_name;
192  return core::send( a_alert );
193  }
194 
195 } /* namespace dripline */
196 
197 #endif /* DRIPLINE_SERVICE_HH_ */
virtual sent_msg_pkg_ptr send(request_ptr_t a_request) const
Definition: core.cc:180
std::shared_ptr< sent_msg_pkg > sent_msg_pkg_ptr
Definition: dripline_fwd.hh:27
std::shared_ptr< msg_request > request_ptr_t
Definition: dripline_fwd.hh:23
std::shared_ptr< msg_alert > alert_ptr_t
Definition: dripline_fwd.hh:25
virtual sent_msg_pkg_ptr send(request_ptr_t a_request) const
Sends a request message and returns a channel on which to listen for a reply.
Definition: service.hh:177
Consumer of Dripline messages on a particular queue.
Definition: service.hh:72
Executes scheduled events.
Definition: scheduler.hh:93
#define DRIPLINE_API
Definition: dripline_api.hh:34
Convenience class to bring together listener and concurrent_receiver.
Definition: listener.hh:75
boost::uuids::uuid uuid_t
Universally-unique-identifier type containing 16 hexadecimal characters.
Definition: uuid.hh:26
std::shared_ptr< endpoint > endpoint_ptr_t
Definition: dripline_fwd.hh:39
std::map< std::string, endpoint_ptr_t > sync_map_t
Definition: service.hh:162
std::shared_ptr< msg_reply > reply_ptr_t
Definition: dripline_fwd.hh:24
Basic AMQP interactions, including sending messages and interacting with AMQP channels.
Definition: core.hh:72
std::map< std::string, lr_ptr_t > async_map_t
Definition: service.hh:165
std::shared_ptr< message > message_ptr_t
Definition: dripline_fwd.hh:20
Basic Dripline object capable of receiving and acting on messages.
Definition: endpoint.hh:95
A heartbeater repeatedly sends an alert on a particular time interval.
Definition: heartbeater.hh:52