Skip to content

Commit 1888d19

Browse files
author
Petr Matousek
committed
wip: initial version
1 parent aa57569 commit 1888d19

File tree

5 files changed

+121
-4
lines changed

5 files changed

+121
-4
lines changed

src/api/qpid-proton/reactor/SendingClient.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,19 @@ int SendingClient::run(int argc, char **argv) const
556556
);
557557

558558
handler.setMessage(msg);
559-
559+
560560
int count = 1;
561561
if (options.is_set("count")) {
562562
count = static_cast<int> (options.get("count"));
563563
}
564564
handler.setCount(count);
565565

566+
int tx_size = 1;
567+
if (options.is_set("tx-size")) {
568+
tx_size = static_cast<int> (options.get("tx-size"));
569+
}
570+
handler.setBatchSize(tx_size);
571+
566572
try {
567573
container(handler).run();
568574

src/api/qpid-proton/reactor/handler/CommonHandler.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <proton/connection.hpp>
2020
#include <proton/connection_options.hpp>
2121
#include <proton/reconnect_options.hpp>
22-
22+
#include <proton/transaction.hpp>
2323

2424
#include <proton/function.hpp>
2525

@@ -35,6 +35,8 @@
3535
#include "logger/LoggerWrapper.h"
3636

3737
using proton::messaging_handler;
38+
using proton::transaction_handler;
39+
using proton::transaction;
3840
using proton::container;
3941
using proton::void_function0;
4042
using proton::duration;
@@ -58,7 +60,7 @@ using dtests::common::UriParser;
5860
* An abstract proton message handler providing a common interface for other
5961
* client handlers
6062
*/
61-
class CommonHandler : public messaging_handler {
63+
class CommonHandler : public messaging_handler, transaction_handler {
6264
public:
6365
/**
6466
* Constructor
@@ -121,6 +123,8 @@ class CommonHandler : public messaging_handler {
121123

122124
virtual void timerEvent() = 0;
123125

126+
transaction_handler th;
127+
124128
protected:
125129

126130

src/api/qpid-proton/reactor/handler/SenderHandler.cpp

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ SenderHandler::SenderHandler(
8888
duration_mode(duration_mode),
8989
sent(0),
9090
confirmedSent(0),
91+
batch_size(1),
92+
current_batch(0),
93+
committed(0),
94+
confirmed(0),
95+
total(0),
9196
m(),
9297
timer_event(*this),
9398
interval(duration::IMMEDIATE)
@@ -205,6 +210,11 @@ void SenderHandler::on_container_start(container &c)
205210
work_q->schedule(duration::IMMEDIATE, make_work(&SenderHandler::checkIfCanSend, this));
206211
}
207212
#endif
213+
// TODO Transactions
214+
tx = NULL;
215+
cont = &c;
216+
// currently causes seqfault
217+
// c.declare_transaction(conn, th);
208218
}
209219

210220
void SenderHandler::on_sendable(sender &s)
@@ -258,6 +268,14 @@ void SenderHandler::on_tracker_reject(tracker &t)
258268
void SenderHandler::on_connection_close(connection &c)
259269
{
260270
logger(debug) << "Closing connection";
271+
// TODO debug remove
272+
// logger(info) << "Transactions";
273+
// logger(info) << "Transaction total: " << total;
274+
// logger(info) << "Transaction sent: " << sent;
275+
// logger(info) << "Transaction batch size: " << batch_size;
276+
// logger(info) << "Transaction current batch: " << current_batch;
277+
// logger(info) << "Transaction confirmed: " << confirmed;
278+
// logger(info) << "Transaction committed: " << committed;
261279
}
262280

263281
void SenderHandler::on_connection_error(connection &c)
@@ -269,7 +287,6 @@ void SenderHandler::on_connection_error(connection &c)
269287
}
270288
}
271289

272-
273290
void SenderHandler::setCount(int count)
274291
{
275292
this->count = count;
@@ -280,6 +297,16 @@ int SenderHandler::getCount() const
280297
return count;
281298
}
282299

300+
void SenderHandler::setBatchSize(int batchSize)
301+
{
302+
this->batch_size = batchSize;
303+
}
304+
305+
int SenderHandler::getBatchSize() const
306+
{
307+
return batch_size;
308+
}
309+
283310
void SenderHandler::setMessage(message &msg)
284311
{
285312
this->m = msg;
@@ -361,6 +388,34 @@ void SenderHandler::send()
361388
ready = false;
362389
}
363390

391+
// TODO VIP TRANSACTIONS
392+
393+
void SenderHandler::on_transaction_declared(transaction &t) {
394+
tx = &t;
395+
send();
396+
}
397+
398+
void SenderHandler::on_transaction_committed(transaction &t) {
399+
committed += current_batch;
400+
connection conn = sndr.connection();
401+
if(committed == total) {
402+
std::cout << "All messages committed";
403+
conn.close();
404+
}
405+
else {
406+
current_batch = 0;
407+
cont->declare_transaction(conn, th);
408+
}
409+
}
410+
411+
void SenderHandler::on_sender_close(sender &s) {
412+
current_batch = 0;
413+
}
414+
415+
// override
416+
// void SenderHandler::on_sendable(sender &s) override {}
417+
// void SenderHandler::on_tracker_accept(tracker &t) override {}
418+
364419
} /* namespace reactor */
365420
} /* namespace proton */
366421
} /* namespace dtests */

src/api/qpid-proton/reactor/handler/SenderHandler.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <proton/connection_options.hpp>
2323
#include <proton/sender_options.hpp>
2424
#include <proton/thread_safe.hpp>
25+
#include <proton/transaction.hpp>
2526

2627
#include "CommonHandler.h"
2728
#include "Timer.h"
@@ -36,6 +37,9 @@ using proton::source_options;
3637
using proton::transport;
3738
using proton::tracker;
3839
using proton::connection_options;
40+
using proton::sender;
41+
using proton::transaction;
42+
using proton::transaction_handler;
3943

4044
namespace dtests {
4145
namespace proton {
@@ -124,6 +128,11 @@ class SenderHandler : public CommonHandler {
124128
void on_transport_error(transport &t);
125129
void on_transport_close(transport &t);
126130

131+
// TODO TX Support
132+
void on_sender_close(sender &s);
133+
void on_transaction_declared(transaction &t);
134+
void on_transaction_committed(transaction &t);
135+
127136
/**
128137
* Sets the message count
129138
* @param count the message count
@@ -136,6 +145,18 @@ class SenderHandler : public CommonHandler {
136145
*/
137146
int getCount() const;
138147

148+
/**
149+
* Sets the transaction batch size
150+
* @param batch_size the transaction batch size
151+
*/
152+
void setBatchSize(int batchSize);
153+
154+
/**
155+
* Gets the transaction batch size
156+
* @return the transaction batch size
157+
*/
158+
int getBatchSize() const;
159+
139160
/**
140161
* Sets the message to send
141162
* @param m the message to send
@@ -159,7 +180,17 @@ class SenderHandler : public CommonHandler {
159180
string duration_mode;
160181
int sent;
161182
int confirmedSent;
183+
184+
// transactions
185+
int batch_size = 0;
186+
int current_batch = 0;
187+
int committed = 0;
188+
int confirmed = 0;
189+
int total = 0;
190+
162191
sender sndr;
192+
transaction *tx;
193+
container *cont;
163194

164195
message m;
165196

src/common/options/modern/ModernOptionsParser.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,27 @@ ModernOptionsParser::ModernOptionsParser()
126126
.help("client reconnect TIMEOUT (default: -1)")
127127
.metavar("TIMEOUT");
128128

129+
// transactions
130+
add_option("--tx-size")
131+
.dest("tx-size")
132+
.help("transactional mode: batch message count size (default: 0)")
133+
.metavar("TX_SIZE");
134+
135+
char const* const choices[] = { "commit", "rollback", "none" };
136+
add_option("--tx-action")
137+
.dest("tx-action")
138+
.help("transactional action at the end of tx batch (default: commit)")
139+
.type("choice")
140+
.choices(std::begin(choices), std::end(choices))
141+
.metavar("TX_ACTION");
142+
143+
add_option("--tx-endloop-action")
144+
.dest("tx-endloop-action")
145+
.help("transactional action after sending all messages in loop")
146+
.type("choice")
147+
.choices(std::begin(choices), std::end(choices))
148+
.metavar("TX_ENDLOOP_ACTION");
149+
129150
/*********************** Reactive C++ API client extras ***********************/
130151
add_option("--conn-reconnect-first")
131152
.dest("conn-reconnect-first")

0 commit comments

Comments
 (0)