YAMI4 C++ Library 2.0.0
Messaging Solution for Distributed Systems
Loading...
Searching...
No Matches
agent.h
1// Copyright Maciej Sobczak 2008-2022.
2// This file is part of YAMI4.
3// See the package-level LICENSE.txt file.
4
5#ifndef YAMICPP_AGENT_H_INCLUDED
6#define YAMICPP_AGENT_H_INCLUDED
7
8#include "agent_impl_base.h"
9#include "connection_event_generic_dispatcher.h"
10#include "event_callback.h"
11#include "incoming_message_generic_dispatcher.h"
12#include "io_error_generic_dispatcher.h"
13#include "outgoing_message.h"
14#include "outgoing_message_generic_dispatcher.h"
15#include "parameters.h"
16#include <yami4-core/dll.h>
17#include <memory>
18#include <string>
19
20namespace yami
21{
22
23class value_publisher;
24
25namespace details
26{
27class agent_impl;
28} // namespace details
29
44class DLL agent
45{
46public:
47
49 typedef long long outgoing_message_id;
50
55 agent(const parameters & options = parameters());
56
61 agent(event_callback & event_listener,
62 const parameters & options = parameters());
63
74
94 std::string add_listener(const std::string & listener);
95
103 void remove_listener(const std::string & listener);
104
115 template <typename functor>
116 void register_object(const std::string & object_name, functor & f)
117 {
118 std::unique_ptr<details::incoming_message_dispatcher_base> object(
120
121 pimpl_base_->register_object(object_name, object);
122 }
123
124 void register_raw_object(const std::string & object_name,
125 void (* callback)(incoming_message & im, void * hint), void * hint);
126
133 void register_value_publisher(const std::string & object_name,
134 value_publisher & publisher);
135
156 void unregister_object(const std::string & object_name);
157
168 void open_connection(const std::string & target);
169
183 void open_connection(const std::string & target,
184 const parameters & options);
185
193
218 std::unique_ptr<outgoing_message> send(
219 const std::string & target,
220 const std::string & object_name,
221 const std::string & message_name,
222 const serializable & content = parameters(),
223 std::size_t priority = 0,
224 bool auto_connect = true);
225
233 void send(
234 outgoing_message & message,
235 const std::string & target,
236 const std::string & object_name,
237 const std::string & message_name,
238 const serializable & content = parameters(),
239 std::size_t priority = 0,
240 bool auto_connect = true);
241
252 template <typename functor>
254 functor & f,
255 const std::string & target,
256 const std::string & object_name,
257 const std::string & message_name,
258 const serializable & content = parameters(),
259 std::size_t priority = 0,
260 bool auto_connect = true)
261 {
262 std::unique_ptr<details::outgoing_message_dispatcher_base>
263 outgoing_message_callback(
265
266 return pimpl_base_->send(outgoing_message_callback,
267 target, object_name, message_name,
268 content, priority, auto_connect);
269 }
270
297 std::unique_ptr<outgoing_message> send(
298 const std::string & target,
299 const serializable & header,
300 const serializable & content,
301 outgoing_message_id message_id,
302 std::size_t priority = 0,
303 bool auto_connect = true);
304
312 void send(
313 outgoing_message & message,
314 const std::string & target,
315 const serializable & header,
316 const serializable & content,
317 outgoing_message_id message_id,
318 std::size_t priority = 0,
319 bool auto_connect = true);
320
331 template <typename functor>
332 void send(
333 functor & f,
334 const std::string & target,
335 const serializable & header,
336 const serializable & content,
337 outgoing_message_id message_id,
338 std::size_t priority = 0,
339 bool auto_connect = true)
340 {
341 std::unique_ptr<details::outgoing_message_dispatcher_base>
342 outgoing_message_callback(
344
345 pimpl_base_->send(outgoing_message_callback,
346 target, header, content, message_id,
347 priority, auto_connect);
348 }
349
359
366 void send_one_way(const std::string & target,
367 const serializable & header,
368 const serializable & content,
369 outgoing_message_id message_id,
370 std::size_t priority = 0,
371 bool auto_connect = true);
372
380 void send_one_way(const std::string & target,
381 const std::string & object_name,
382 const std::string & message_name,
383 const serializable & content = parameters(),
384 std::size_t priority = 0,
385 bool auto_connect = true);
386
404 void close_connection(const std::string & target,
405 std::size_t priority = 0);
406
416 void hard_close_connection(const std::string & target);
417
430 template <typename functor>
432 {
433 std::unique_ptr<details::connection_event_dispatcher_base> monitor(
435
436 pimpl_base_->register_connection_event_monitor(monitor);
437 }
438
451 template <typename functor>
452 void register_io_error_logger(functor & f)
453 {
454 std::unique_ptr<details::io_error_dispatcher_base> logger(
456
457 pimpl_base_->register_io_error_logger(logger);
458 }
459
471 void get_outgoing_flow_state(std::size_t & current_level,
472 std::size_t & high_water_mark, std::size_t & low_water_mark) const;
473
483 void get_channel_usage(std::size_t & max_allowed, std::size_t & used);
484
489 std::size_t get_pending_outgoing_bytes(const std::string & target);
490
500
514 void run_dispatcher(std::size_t dispatcher_index);
515
516private:
517 agent(const agent &);
518 void operator=(const agent &);
519
520 details::agent_impl * pimpl_;
521 details::agent_impl_base * pimpl_base_;
522};
523
524} // namespace yami
525
526#endif // YAMICPP_AGENT_H_INCLUDED
Message broker.
Definition: agent.h:45
void register_object(const std::string &object_name, functor &f)
Registers the new logical destination object.
Definition: agent.h:116
void register_connection_event_monitor(functor &f)
Registers the monitor for connection-related events.
Definition: agent.h:431
void remove_listener(const std::string &listener)
Removes existing listener.
void register_io_error_logger(functor &f)
Registers the logger for I/O errors.
Definition: agent.h:452
std::unique_ptr< outgoing_message > send(const std::string &target, const std::string &object_name, const std::string &message_name, const serializable &content=parameters(), std::size_t priority=0, bool auto_connect=true)
Sends the new outgoing message.
void send_one_way(const std::string &target, const std::string &object_name, const std::string &message_name, const serializable &content=parameters(), std::size_t priority=0, bool auto_connect=true)
Sends the new outgoing message with custom header.
void send(functor &f, const std::string &target, const serializable &header, const serializable &content, outgoing_message_id message_id, std::size_t priority=0, bool auto_connect=true)
Sends the outgoing message with a custom header.
Definition: agent.h:332
void send_one_way(const std::string &target, const serializable &header, const serializable &content, outgoing_message_id message_id, std::size_t priority=0, bool auto_connect=true)
Sends the new outgoing message.
void close_connection(const std::string &target, std::size_t priority=0)
Closes the given communication channel.
void unregister_object(const std::string &object_name)
Unregisters the logical destination object.
void run_worker()
Runs the internal worker activities.
agent(event_callback &event_listener, const parameters &options=parameters())
Constructor.
long long outgoing_message_id
Outgoing message identifier type.
Definition: agent.h:49
outgoing_message_id get_next_message_id()
Obtains unique message id.
std::size_t get_pending_outgoing_bytes(const std::string &target)
Returns the size of outgoing queue for the given channel.
agent(const parameters &options=parameters())
Constructor.
void get_outgoing_flow_state(std::size_t &current_level, std::size_t &high_water_mark, std::size_t &low_water_mark) const
Obtains the state of overall outgoing flow.
void get_channel_usage(std::size_t &max_allowed, std::size_t &used)
Returns the selector's channel usage counters.
void hard_close_connection(const std::string &target)
Immediately closes the given communication channel.
void register_value_publisher(const std::string &object_name, value_publisher &publisher)
Registers the value publisher as a new logical object.
void open_connection(const std::string &target)
Opens the new connection.
void clean_outgoing_message_callback(outgoing_message_id id)
Cleans internal resources for the given message callback.
outgoing_message_id send(functor &f, const std::string &target, const std::string &object_name, const std::string &message_name, const serializable &content=parameters(), std::size_t priority=0, bool auto_connect=true)
Sends the outgoing message.
Definition: agent.h:253
std::unique_ptr< outgoing_message > send(const std::string &target, const serializable &header, const serializable &content, outgoing_message_id message_id, std::size_t priority=0, bool auto_connect=true)
Sends the new outgoing message with a custom header.
void send(outgoing_message &message, const std::string &target, const serializable &header, const serializable &content, outgoing_message_id message_id, std::size_t priority=0, bool auto_connect=true)
Sends the outgoing message with a custom header.
void open_connection(const std::string &target, const parameters &options)
Opens the new connection with overriding options.
~agent()
Destructor.
void send(outgoing_message &message, const std::string &target, const std::string &object_name, const std::string &message_name, const serializable &content=parameters(), std::size_t priority=0, bool auto_connect=true)
Sends the outgoing message.
void run_dispatcher(std::size_t dispatcher_index)
Runs the message dispatching activities.
std::string add_listener(const std::string &listener)
Adds new listener.
Definition: agent_impl_base.h:26
Definition: connection_event_generic_dispatcher.h:20
Definition: incoming_message_generic_dispatcher.h:23
Definition: io_error_generic_dispatcher.h:19
Definition: outgoing_message_generic_dispatcher.h:22
Event notification callback interface.
Definition: event_callback.h:26
Incoming message.
Definition: incoming_message.h:37
Outgoing message.
Definition: outgoing_message.h:33
Collection of message parameters.
Definition: parameters.h:62
Common interface for serializable data source.
Definition: serializable.h:21
Simple subscription publisher.
Definition: value_publisher.h:36
Namespace devoted to everything related to YAMI4.
Definition: agent.h:21