Skip to content

Commit 578445f

Browse files
committed
Removed coordinator class and improved STATES handling.
1 parent 4c795ef commit 578445f

12 files changed

+78
-319
lines changed

cpp/examples/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ foreach(example
6161
service_bus
6262
multithreaded_client
6363
multithreaded_client_flow_control
64-
tx_send
65-
tx_recv)
64+
tx_send)
6665
add_executable(${example} ${example}.cpp)
6766
target_link_libraries(${example} Proton::cpp Threads::Threads)
6867
endforeach()

cpp/examples/simple_recv.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ class simple_recv : public proton::messaging_handler {
4343
proton::receiver receiver;
4444
int expected;
4545
int received;
46+
bool verbose;
4647

4748
public:
48-
simple_recv(const std::string &s, const std::string &u, const std::string &p, int c) :
49-
url(s), user(u), password(p), expected(c), received(0) {}
49+
simple_recv(const std::string &s, const std::string &u, const std::string &p, int c, bool verbose) :
50+
url(s), user(u), password(p), expected(c), received(0), verbose(verbose) {}
5051

5152
void on_container_start(proton::container &c) override {
5253
proton::connection_options co;
@@ -61,6 +62,9 @@ class simple_recv : public proton::messaging_handler {
6162
}
6263

6364
if (expected == 0 || received < expected) {
65+
if (verbose) {
66+
std::cout << msg << ": ";
67+
}
6468
std::cout << msg.body() << std::endl;
6569
received++;
6670

@@ -77,18 +81,20 @@ int main(int argc, char **argv) {
7781
std::string user;
7882
std::string password;
7983
int message_count = 100;
84+
bool verbose;
8085
example::options opts(argc, argv);
8186

8287
opts.add_value(address, 'a', "address", "connect to and receive from URL", "URL");
8388
opts.add_value(message_count, 'm', "messages", "receive COUNT messages", "COUNT");
8489
opts.add_value(user, 'u', "user", "authenticate as USER", "USER");
8590
opts.add_value(password, 'p', "password", "authenticate with PASSWORD", "PASSWORD");
91+
opts.add_flag(verbose, 'v', "verbose", "show whole message contents");
8692

8793

8894
try {
8995
opts.parse();
9096

91-
simple_recv recv(address, user, password, message_count);
97+
simple_recv recv(address, user, password, message_count, verbose);
9298
proton::container(recv).run();
9399

94100
return 0;

cpp/examples/tx_recv.cpp

Lines changed: 0 additions & 129 deletions
This file was deleted.

cpp/examples/tx_send.cpp

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,14 @@
3838

3939
class tx_send : public proton::messaging_handler, proton::transaction_handler {
4040
private:
41-
proton::sender sender;
41+
proton::sender sender;
4242
std::string url;
4343
int total;
4444
int batch_size;
4545
int sent;
4646
int batch_index = 0;
4747
int current_batch = 0;
4848
int committed = 0;
49-
int confirmed = 0;
50-
51-
proton::session session;
5249

5350
public:
5451
tx_send(const std::string &s, int c, int b):
@@ -59,35 +56,34 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
5956
}
6057

6158
void on_session_open(proton::session &s) override {
62-
session = s;
63-
std::cout << " [on_session_open] declare_txn started..." << std::endl;
59+
std::cout << "New session is open, declaring transaction now..." << std::endl;
6460
s.declare_transaction(*this);
65-
std::cout << " [on_session_open] declare_txn ended..." << std::endl;
6661
}
6762

68-
void on_transaction_declare_failed(proton::session) {}
63+
void on_transaction_declare_failed(proton::session s) {
64+
std::cout << "Transaction declarion failed" << std::endl;
65+
s.connection().close();
66+
exit(-1);
67+
}
68+
6969
void on_transaction_commit_failed(proton::session s) {
70-
std::cout << "Transaction Commit Failed" << std::endl;
70+
std::cout << "Transaction commit failed!" << std::endl;
7171
s.connection().close();
7272
exit(-1);
7373
}
7474

7575
void on_transaction_declared(proton::session s) override {
76-
std::cout << "[on_transaction_declared] Session: " << (&s)
77-
<< std::endl;
78-
std::cout << "[on_transaction_declared] txn is_empty " << (s.txn_is_empty())
79-
<< "\t" << std::endl;
80-
send(sender);
76+
std::cout << "Transaction is declared" << std::endl;
77+
send();
8178
}
8279

83-
void on_sendable(proton::sender &s) override {
84-
std::cout << " [OnSendable] session: " << &session
85-
<< std::endl;
86-
send(s);
80+
void on_sendable(proton::sender&) override {
81+
send();
8782
}
8883

89-
void send(proton::sender &s) {
84+
void send() {
9085
static int unique_id = 10000;
86+
proton::session session = sender.session();
9187
while (session.txn_is_declared() && sender.credit() &&
9288
(committed + current_batch) < total) {
9389
proton::message msg;
@@ -96,47 +92,42 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
9692

9793
msg.id(unique_id++);
9894
msg.body(m);
99-
std::cout << "##### [example] transaction send msg: " << msg
100-
<< std::endl;
95+
std::cout << "Sending: " << msg << std::endl;
10196
session.txn_send(sender, msg);
10297
current_batch += 1;
10398
if(current_batch == batch_size)
10499
{
105-
std::cout << " >> Txn attempt commit" << std::endl;
106100
if (batch_index % 2 == 0) {
101+
std::cout << "Commiting transaction..." << std::endl;
107102
session.txn_commit();
108103
} else {
104+
std::cout << "Aborting transaction..." << std::endl;
109105
session.txn_abort();
110-
}
106+
}
111107
batch_index++;
112108
}
113109
}
114110
}
115111

116-
void on_tracker_accept(proton::tracker &t) override {
117-
confirmed += 1;
118-
std::cout << " [example] on_tracker_accept:" << confirmed
119-
<< std::endl;
120-
}
121-
122112
void on_transaction_committed(proton::session s) override {
123113
committed += current_batch;
124114
current_batch = 0;
125-
std::cout<<" [OnTxnCommitted] Committed:"<< committed<< std::endl;
115+
std::cout << "Transaction commited" << std::endl;
126116
if(committed == total) {
127-
std::cout << "All messages committed" << std::endl;
117+
std::cout << "All messages committed, closing connection." << std::endl;
128118
s.connection().close();
129119
}
130120
else {
131-
std::cout << "redlcaring txn " << std::endl;
132-
session.declare_transaction(*this);
121+
std::cout << "Re-declaring transaction now..." << std::endl;
122+
s.declare_transaction(*this);
133123
}
134124
}
135125

136126
void on_transaction_aborted(proton::session s) override {
137-
std::cout << "Meesages Aborted ....." << std::endl;
127+
std::cout << "Transaction aborted!" << std::endl;
128+
std::cout << "Re-delaring transaction now..." << std::endl;
138129
current_batch = 0;
139-
session.declare_transaction(*this);
130+
s.declare_transaction(*this);
140131
}
141132

142133
void on_sender_close(proton::sender &s) override {

cpp/include/proton/session.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ PN_CPP_CLASS_EXTERN session : public internal::object<pn_session_t>, public endp
131131
};
132132

133133
/// @cond INTERNAL
134-
134+
135135
/// An iterator of sessions.
136136
class session_iterator : public internal::iter_base<session, session_iterator> {
137137
public:
@@ -145,7 +145,7 @@ class session_iterator : public internal::iter_base<session, session_iterator> {
145145
typedef internal::iter_range<session_iterator> session_range;
146146

147147
/// @endcond
148-
148+
149149
} // proton
150150

151151
#endif // PROTON_SESSION_HPP

cpp/include/proton/target.hpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,6 @@ class target : public terminus {
6565
/// @endcond
6666
};
6767

68-
class coordinator : public terminus {
69-
public:
70-
/// Create an empty coordinator.
71-
coordinator() = default;
72-
73-
/// The address of the coordinator.
74-
PN_CPP_EXTERN std::string address() const;
75-
private:
76-
coordinator(pn_terminus_t* t);
77-
coordinator(const sender&);
78-
coordinator(const receiver&);
79-
80-
81-
/// @cond INTERNAL
82-
friend class proton::internal::factory<coordinator>;
83-
friend class sender;
84-
friend class receiver;
85-
/// @endcond
86-
};
87-
8868
} // proton
8969

9070
#endif // PROTON_TARGET_HPP

0 commit comments

Comments
 (0)