@@ -110,19 +110,20 @@ int TxSenderHandler::getBatchSize() const
110110 return batch_size;
111111}
112112
113- void TxSenderHandler::checkIfCanSend () {
114- if (processed < count) {
115- work_q->schedule (interval, make_work (&TxSenderHandler::checkIfCanSend, this ));
116-
117- if (sndr.credit () > 0 ) {
118- send ();
119- } else {
120- ready = true ;
121- }
122- }
123- }
124-
125- void TxSenderHandler::send ()
113+ // void TxSenderHandler::checkIfCanSend() {
114+ // if (processed < count) {
115+ // work_q->schedule(interval, make_work(&TxSenderHandler::checkIfCanSend, this));
116+ //
117+ // if (sndr.credit() > 0) {
118+ // logger(debug) << "[checkIfCanSend] Preparing to send message";
119+ // send();
120+ // } else {
121+ // ready = true;
122+ // }
123+ // }
124+ // }
125+
126+ void TxSenderHandler::send (session s)
126127{
127128 logger (debug) << " [send] Preparing to send message" ;
128129 int credit = sndr.credit ();
@@ -150,12 +151,14 @@ void TxSenderHandler::send()
150151 }
151152
152153
153- logger (trace) << " [send] Transaction is empty: " << tx. is_empty ();
154+ logger (trace) << " [send] Transaction is empty: " << s. txn_is_empty ();
154155 logger (debug) << " [send] Messages processed: " << processed;
155156 logger (trace) << " [send] Current batch: " << current_batch;
156- while (!tx. is_empty () && sndr.credit () && (processed + current_batch) < count)
157+ while (s. txn_is_declared () && sndr.credit () && (processed + current_batch) < count)
157158 {
158- tx.send (sndr, message_to_send);
159+ logger (trace) << " [send] Sending messages through the link NAZDAR" ;
160+ s.txn_send (sndr, message_to_send);
161+ logger (trace) << " [send] Sending messages through the link BAZAR" ;
159162 current_batch += 1 ;
160163
161164 if (log_msgs == " dict" ) {
@@ -185,27 +188,26 @@ void TxSenderHandler::send()
185188 if (current_batch == batch_size) {
186189 logger (debug) << " [send] Transaction attempt: " << tx_action;
187190 if (tx_action == " commit" ) {
188- tx. commit ();
191+ s. txn_commit ();
189192 } else if (tx_action == " rollback" ) {
190- tx. abort ();
193+ s. txn_abort ();
191194 }
192- tx = transaction ();
193195
194196 if (tx_action == " none" ) {
195197 if (processed + current_batch == count) {
196198 sndr.connection ().close ();
197199 } else {
198200 processed += current_batch;
199201 current_batch = 0 ;
200- sess .declare_transaction (*this );
202+ s .declare_transaction (*this );
201203 }
202204 }
203205 } else if (processed + current_batch == count) {
204206 logger (debug) << " [send] Transaction attempt (endloop): " << tx_endloop_action;
205207 if (tx_endloop_action == " commit" ) {
206- tx. commit ();
208+ s. txn_commit ();
207209 } else if (tx_endloop_action == " rollback" ) {
208- tx. abort ();
210+ s. txn_abort ();
209211 }
210212 sndr.connection ().close ();
211213 }
@@ -221,9 +223,10 @@ void TxSenderHandler::send()
221223
222224void TxSenderHandler::on_sendable (sender &s)
223225{
224- logger (trace) << " [on_sendable] transaction: " << &tx;
226+ logger (trace) << " [on_sendable] IS THIS METHOD EVER CALLED IN TX MODE???" ;
227+ logger (trace) << " [on_sendable] transaction: " << &s;
225228 if (ready) {
226- send ();
229+ send (s. session () );
227230 }
228231}
229232
@@ -238,39 +241,39 @@ void TxSenderHandler::on_connection_close(connection &c)
238241 logger (debug) << " [on_connection_close] Closing connection" ;
239242}
240243
241- void TxSenderHandler::on_transaction_declared (transaction t ) {
242- logger (trace) << " [on_transaction_declared] txn called " << (&t );
243- logger (trace) << " [on_transaction_declared] txn is_empty " << (t. is_empty ())
244- << " \t " << tx. is_empty ();
245- tx = t;
246- send ();
244+ void TxSenderHandler::on_transaction_declared (session s ) {
245+ logger (trace) << " [on_transaction_declared] txn called " << (&s );
246+ logger (trace) << " [on_transaction_declared] txn is_empty " << (s. txn_is_empty ())
247+ << " \t " << s. txn_is_empty ();
248+ // tx = t;
249+ send (s );
247250}
248251
249- void TxSenderHandler::on_transaction_committed (transaction t ) {
252+ void TxSenderHandler::on_transaction_committed (session s ) {
250253 logger (trace) << " [on_transaction_committed] Messages committed" ;
251254 processed += current_batch;
252255 logger (debug) << " [on_transaction_committed] Messages processed" << processed;
253256 if (processed == count) {
254257 logger (trace) << " [on_transaction_committed] All messages processed" ;
255- t .connection ().close ();
258+ s .connection ().close ();
256259 } else {
257260 logger (trace) << " [on_transaction_committed] Declaring new transaction" ;
258261 current_batch = 0 ;
259- sess .declare_transaction (*this );
262+ s .declare_transaction (*this );
260263 }
261264}
262265
263- void TxSenderHandler::on_transaction_aborted (transaction t ) {
266+ void TxSenderHandler::on_transaction_aborted (session s ) {
264267 logger (trace) << " [on_transaction_aborted] Messages aborted" ;
265268 processed += current_batch;
266- logger (debug) << " [on_transaction_committed ] Messages processed" << processed;
269+ logger (debug) << " [on_transaction_aborted ] Messages processed" << processed;
267270 if (processed == count) {
268271 logger (trace) << " [on_transaction_aborted] All messages processed" ;
269- t .connection ().close ();
272+ s .connection ().close ();
270273 } else {
271- logger (trace) << " [on_transaction_committed ] Declaring new transaction" ;
274+ logger (trace) << " [on_transaction_aborted ] Declaring new transaction" ;
272275 current_batch = 0 ;
273- sess .declare_transaction (*this );
276+ s .declare_transaction (*this );
274277 }
275278}
276279
@@ -279,7 +282,6 @@ void TxSenderHandler::on_sender_close(sender &s) {
279282}
280283
281284void TxSenderHandler::on_session_open (session &s) {
282- sess = s;
283285 logger (trace) << " [on_session_open] declare_txn started..." ;
284286 s.declare_transaction (*this );
285287 logger (trace) << " [on_session_open] declare_txn ended..." ;
@@ -366,26 +368,27 @@ void TxSenderHandler::on_container_start(container &c)
366368
367369 logger (trace) << " [on_container_start] Interval for duration: " << interval.milliseconds () << " ms" ;
368370 }
369- #if defined(__REACTOR_HAS_TIMER)
370- work_q->schedule (duration::IMMEDIATE, make_work (&TxSenderHandler::timerEvent, this ));
371-
372- if (duration_time > 0 && duration_mode == " after-send" ) {
373- work_q->schedule (duration::IMMEDIATE, make_work (&TxSenderHandler::checkIfCanSend, this ));
374- } else if (duration_time > 0 && duration_mode == " before-send" ) {
375- work_q->schedule (interval, make_work (&TxSenderHandler::checkIfCanSend, this ));
376- } else {
377- work_q->schedule (duration::IMMEDIATE, make_work (&TxSenderHandler::checkIfCanSend, this ));
378- }
379- #endif
380-
381- tx = transaction ();
371+ // TODO
372+ // #if defined(__REACTOR_HAS_TIMER)
373+ // work_q->schedule(duration::IMMEDIATE, make_work(&TxSenderHandler::timerEvent, this));
374+ //
375+ // if (duration_time > 0 && duration_mode == "after-send") {
376+ // work_q->schedule(duration::IMMEDIATE, make_work(&TxSenderHandler::checkIfCanSend, this));
377+ // } else if (duration_time > 0 && duration_mode == "before-send") {
378+ // work_q->schedule(interval, make_work(&TxSenderHandler::checkIfCanSend, this));
379+ // } else {
380+ // work_q->schedule(duration::IMMEDIATE, make_work(&TxSenderHandler::checkIfCanSend, this));
381+ // }
382+ // #endif
383+
384+ // tx = transaction();
382385}
383386
384- void TxSenderHandler::on_transaction_declare_failed (transaction ) {}
387+ void TxSenderHandler::on_transaction_declare_failed (session ) {}
385388
386- void TxSenderHandler::on_transaction_commit_failed (transaction t ) {
389+ void TxSenderHandler::on_transaction_commit_failed (session s ) {
387390 logger (error) << " [on_transaction_commit_failed] Transaction Commit Failed" ;
388- t .connection ().close ();
391+ s .connection ().close ();
389392 exit (1 );
390393}
391394
0 commit comments