Skip to content

Commit 74818fc

Browse files
committed
Add txn id in disposition frame bits
1 parent ed624cd commit 74818fc

File tree

10 files changed

+216
-74
lines changed

10 files changed

+216
-74
lines changed

cpp/examples/tx_send.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
6060
std::cout << " [on_container_start] completed!! txn: " << &transaction << std::endl;
6161
}
6262

63-
void on_transaction_aborted(proton::transaction&) {}
64-
void on_transaction_declare_failed(proton::transaction &) {}
65-
void on_transaction_commit_failed(proton::transaction&) {}
63+
void on_transaction_aborted(proton::transaction) {}
64+
void on_transaction_declare_failed(proton::transaction) {}
65+
void on_transaction_commit_failed(proton::transaction) {}
6666

67-
68-
void on_transaction_declared(proton::transaction &t) override {
69-
std::cout<<"[on_transaction_declared] txn: "<<(&transaction)<< " new_txn: "<<(&t)<<std::endl;
67+
void on_transaction_declared(proton::transaction t) override {
68+
std::cout << "[on_transaction_declared] txn: " << (&transaction)
69+
<< " new_txn: " << (t._impl->id) << std::endl;
7070
connection.close();
7171
// transaction = &t;
7272
// ASSUME: THIS FUNCTION DOESN"T WORK
@@ -95,7 +95,6 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
9595
if(current_batch == batch_size)
9696
{
9797
transaction.commit();
98-
// WE DON"T CARE ANY MORE FOR NOW
9998
// transaction = NULL;
10099
}
101100
}
@@ -106,7 +105,7 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
106105
confirmed += 1;
107106
}
108107

109-
void on_transaction_committed(proton::transaction &t) override {
108+
void on_transaction_committed(proton::transaction t) override {
110109
committed += current_batch;
111110
std::cout<<" [OnTxnCommitted] Committed:"<< committed<< std::endl;
112111
if(committed == total) {

cpp/include/proton/container.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ class PN_CPP_CLASS_EXTERN container {
327327
friend class receiver_options;
328328
friend class sender_options;
329329
friend class work_queue;
330+
friend class transaction;
330331
/// @endcond
331332
};
332333

cpp/include/proton/transaction.hpp

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "./internal/export.hpp"
2929
#include "./sender.hpp"
3030
#include "./tracker.hpp"
31+
#include "./container.hpp"
3132

3233
/// @file
3334
/// @copybrief proton::transaction
@@ -36,16 +37,57 @@ namespace proton {
3637

3738
class transaction_handler;
3839

40+
// TODO: This should not be accessible to users.
41+
class transaction_impl {
42+
public:
43+
proton::sender *txn_ctrl = nullptr;
44+
proton::transaction_handler *handler = nullptr;
45+
proton::binary id;
46+
proton::tracker _declare;
47+
proton::tracker _discharge;
48+
bool failed = false;
49+
std::vector<proton::tracker> pending;
50+
51+
void commit();
52+
void abort();
53+
void declare();
54+
proton::tracker send(proton::sender s, proton::message msg);
55+
56+
void discharge(bool failed);
57+
proton::tracker send_ctrl(proton::symbol descriptor, proton::value _value);
58+
void handle_outcome(proton::tracker t);
59+
transaction_impl(proton::sender &_txn_ctrl,
60+
proton::transaction_handler &_handler,
61+
bool _settle_before_discharge);
62+
63+
// delete copy and assignment operator to ensure no copy of this object is
64+
// every made transaction_impl(const transaction_impl&) = delete;
65+
// transaction_impl& operator=(const transaction_impl&) = delete;
66+
};
67+
3968
class
4069
PN_CPP_CLASS_EXTERN transaction {
70+
// private:
71+
// PN_CPP_EXTERN transaction(proton::sender& _txn_ctrl,
72+
// proton::transaction_handler& _handler, bool _settle_before_discharge);
73+
74+
static transaction mk_transaction_impl(sender &s, transaction_handler &h,
75+
bool f);
76+
PN_CPP_EXTERN transaction(transaction_impl* impl);
4177
public:
78+
transaction_impl* _impl;
4279
// TODO:
43-
PN_CPP_EXTERN virtual ~transaction();
44-
PN_CPP_EXTERN virtual void commit();
45-
PN_CPP_EXTERN virtual void abort();
46-
PN_CPP_EXTERN virtual void declare();
47-
PN_CPP_EXTERN virtual void handle_outcome(proton::tracker);
48-
PN_CPP_EXTERN virtual proton::tracker send(proton::sender s, proton::message msg);
80+
// PN_CPP_EXTERN transaction(transaction &o);
81+
PN_CPP_EXTERN transaction();
82+
PN_CPP_EXTERN ~transaction();
83+
PN_CPP_EXTERN void commit();
84+
PN_CPP_EXTERN void abort();
85+
PN_CPP_EXTERN void declare();
86+
PN_CPP_EXTERN void handle_outcome(proton::tracker);
87+
PN_CPP_EXTERN proton::tracker send(proton::sender s, proton::message msg);
88+
89+
friend class transaction_impl;
90+
friend class container::impl;
4991
};
5092

5193
class
@@ -54,19 +96,19 @@ PN_CPP_CLASS_EXTERN transaction_handler {
5496
PN_CPP_EXTERN virtual ~transaction_handler();
5597

5698
/// Called when a local transaction is declared.
57-
PN_CPP_EXTERN virtual void on_transaction_declared(transaction&);
99+
PN_CPP_EXTERN virtual void on_transaction_declared(transaction);
58100

59101
/// Called when a local transaction is discharged successfully.
60-
PN_CPP_EXTERN virtual void on_transaction_committed(transaction&);
102+
PN_CPP_EXTERN virtual void on_transaction_committed(transaction);
61103

62104
/// Called when a local transaction is discharged unsuccessfully (aborted).
63-
PN_CPP_EXTERN virtual void on_transaction_aborted(transaction&);
105+
PN_CPP_EXTERN virtual void on_transaction_aborted(transaction);
64106

65107
/// Called when a local transaction declare fails.
66-
PN_CPP_EXTERN virtual void on_transaction_declare_failed(transaction&);
108+
PN_CPP_EXTERN virtual void on_transaction_declare_failed(transaction);
67109

68110
/// Called when the commit of a local transaction fails.
69-
PN_CPP_EXTERN virtual void on_transaction_commit_failed(transaction&);
111+
PN_CPP_EXTERN virtual void on_transaction_commit_failed(transaction);
70112
};
71113

72114
} // namespace proton

cpp/include/proton/transfer.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,26 @@
3333
/// @copybrief proton::transfer
3434

3535
struct pn_delivery_t;
36+
struct pn_disposition_t;
3637

3738
namespace proton {
3839

40+
class disposition : public internal::object<pn_disposition_t> {
41+
/// @cond INTERNAL
42+
disposition(pn_disposition_t *d) : internal::object<pn_disposition_t>(d) {}
43+
/// @endcond
44+
45+
public:
46+
/// Create an empty disposition.
47+
disposition() : internal::object<pn_disposition_t>(0) {}
48+
49+
proton::value data() const;
50+
51+
/// @cond INTERNAL
52+
friend class internal::factory<disposition>;
53+
/// @endcond
54+
};
55+
3956
/// The base class for delivery and tracker.
4057
class transfer : public internal::object<pn_delivery_t> {
4158
/// @cond INTERNAL
@@ -88,6 +105,9 @@ class transfer : public internal::object<pn_delivery_t> {
88105
/// Get user data from this transfer.
89106
PN_CPP_EXTERN void* user_data() const;
90107

108+
PN_CPP_EXTERN disposition remote();
109+
PN_CPP_EXTERN disposition local();
110+
91111
/// @cond INTERNAL
92112
friend class internal::factory<transfer>;
93113
/// @endcond

cpp/src/messaging_adapter.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include <proton/connection.h>
4343
#include <proton/delivery.h>
44+
#include <proton/disposition.h>
4445
#include <proton/handlers.h>
4546
#include <proton/link.h>
4647
#include <proton/message.h>
@@ -115,20 +116,32 @@ void message_decode(message& msg, proton::delivery delivery) {
115116
msg.decode(buf);
116117
pn_link_advance(unwrap(link));
117118
}
118-
119119
void on_delivery(messaging_handler& handler, pn_event_t* event) {
120120
pn_link_t *lnk = pn_event_link(event);
121121
pn_delivery_t *dlv = pn_event_delivery(event);
122122
link_context& lctx = link_context::get(lnk);
123123
Tracing& ot = Tracing::getTracing();
124124
if (pn_terminus_get_type(pn_link_remote_target(lnk))==PN_COORDINATOR) {
125-
std::cout<< " on_delivery: COOORINDATOR.. " << &handler << std::endl;
125+
// delivery d(make_wrapper<delivery>(dlv));
126+
pn_disposition_t *disposition = pn_delivery_remote(dlv);
127+
proton::value val(pn_disposition_data(disposition));
128+
std::cout << " on_delivery: COOORINDATOR.. tracker: " << val
129+
<< std::endl;
126130
tracker t(make_wrapper<tracker>(dlv));
127-
std::cout<< " on_delivery: COOORINDATOR.. tracker" << &t << std::endl;
128-
handler.on_tracker_settle(t);
129-
}
131+
std::cout << " on_delivery: COOORINDATOR.. TRACKER MADE: "
132+
<< std::endl;
133+
// t.user_data = val; // not
134+
135+
// proton::disposition _disposition = make_wrapper(disposition); // #
136+
// t.remote();
130137

131-
else if (pn_link_is_receiver(lnk)) {
138+
// proton::value val2 = _disposition.data();
139+
140+
// std::cout<< " on_delivery: COOORINDATOR with TXN IN :"
141+
// << val2 << std::endl;
142+
143+
handler.on_tracker_settle(t);
144+
} else if (pn_link_is_receiver(lnk)) {
132145
delivery d(make_wrapper<delivery>(dlv));
133146
if (pn_delivery_aborted(dlv)) {
134147
pn_delivery_settle(dlv);

cpp/src/proactor_container_impl.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@
3636
#include "proton/transport.h"
3737
#include "proton/transaction.hpp"
3838

39+
#include "proton/delivery.h"
40+
3941
#include "contexts.hpp"
4042
#include "messaging_adapter.hpp"
4143
#include "reconnect_options_impl.hpp"
4244
#include "proton_bits.hpp"
4345

46+
#include <proton/types.hpp>
47+
4448
#include <assert.h>
4549
#include <string.h>
4650

@@ -863,16 +867,32 @@ void container::impl::stop(const proton::error_condition& err) {
863867
}
864868

865869
// TODO: declare this in separate internal header file
866-
extern transaction mk_transaction_impl(sender&, transaction_handler&, bool);
870+
// extern transaction mk_transaction_impl(sender&, transaction_handler&, bool);
867871

868872
transaction container::impl::declare_transaction(proton::connection conn, proton::transaction_handler &handler, bool settle_before_discharge) {
869873
class InternalTransactionHandler : public proton::messaging_handler {
870874
// TODO: auto_settle
871875
void on_tracker_settle(proton::tracker &t) override {
872876
std::cout<<" [InternalTransactionHandler][on_tracker_settle] called with tracker.txn"
873877
<< std::endl;
878+
t.transaction().handle_outcome(t);
879+
880+
// t.user_data = val; // not
881+
882+
// proton::disposition _disposition = make_wrapper(disposition);
883+
// // # t.remote();
884+
885+
// proton::value val2 = _disposition.data();
886+
887+
// proton::disposition _disposition = t.remote();
888+
889+
// proton::value val = _disposition.data();
890+
891+
// std::cout<< " declare_transaction: on_tracker_settle with
892+
// TXN IN :" << val << std::endl;
893+
874894
// if(t.transaction()) {
875-
t.transaction().handle_outcome(t);
895+
// t.transaction().handle_outcome(t);
876896
// }
877897
}
878898

@@ -903,7 +923,8 @@ transaction container::impl::declare_transaction(proton::connection conn, proton
903923

904924
std::cout<<" [declare_transaction] calling mk_transaction_impl" << std::endl;
905925

906-
auto txn = mk_transaction_impl(s, handler, settle_before_discharge);
926+
auto txn =
927+
transaction::mk_transaction_impl(s, handler, settle_before_discharge);
907928
std::cout<<" [declare_transaction] txn address:" << &txn << std::endl;
908929

909930
return txn;

cpp/src/proton_bits.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
#include <proton/link.h>
2222
#include <proton/session.h>
23+
#include <proton/tracker.hpp>
2324

2425
#include <string>
2526
#include <iosfwd>
@@ -41,6 +42,7 @@ struct pn_connection_t;
4142
struct pn_session_t;
4243
struct pn_link_t;
4344
struct pn_delivery_t;
45+
struct pn_disposition_t;
4446
struct pn_condition_t;
4547
struct pn_acceptor_t;
4648
struct pn_terminus_t;
@@ -60,6 +62,7 @@ class sender;
6062
class receiver;
6163
class transfer;
6264
class tracker;
65+
class disposition;
6366
class delivery;
6467
class error_condition;
6568
class acceptor;
@@ -98,6 +101,9 @@ template <> struct wrapped<sender> { typedef pn_link_t type; };
98101
template <> struct wrapped<receiver> { typedef pn_link_t type; };
99102
template <> struct wrapped<transfer> { typedef pn_delivery_t type; };
100103
template <> struct wrapped<tracker> { typedef pn_delivery_t type; };
104+
template <> struct wrapped<disposition> {
105+
typedef pn_disposition_t type;
106+
};
101107
template <> struct wrapped<delivery> { typedef pn_delivery_t type; };
102108
template <> struct wrapped<error_condition> { typedef pn_condition_t type; };
103109
template <> struct wrapped<terminus> { typedef pn_terminus_t type; };
@@ -111,6 +117,9 @@ template <> struct wrapper<pn_connection_t> { typedef connection type; };
111117
template <> struct wrapper<pn_session_t> { typedef session type; };
112118
template <> struct wrapper<pn_link_t> { typedef link type; };
113119
template <> struct wrapper<pn_delivery_t> { typedef transfer type; };
120+
template <> struct wrapper<pn_disposition_t> {
121+
typedef disposition type;
122+
};
114123
template <> struct wrapper<pn_condition_t> { typedef error_condition type; };
115124
template <> struct wrapper<pn_terminus_t> { typedef terminus type; };
116125

cpp/src/tracker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
namespace proton {
3434

35-
tracker::tracker(pn_delivery_t *d): transfer(make_wrapper(d)) {}
35+
tracker::tracker(pn_delivery_t *d) : transfer(make_wrapper(d)) {}
3636
sender tracker::sender() const { return make_wrapper<class sender>(pn_delivery_link(pn_object())); }
3737
binary tracker::tag() const { return bin(pn_delivery_tag(pn_object())); }
3838
}

0 commit comments

Comments
 (0)