@@ -110,19 +110,20 @@ int TxSenderHandler::getBatchSize() const
110
110
return batch_size;
111
111
}
112
112
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)
126
127
{
127
128
logger (debug) << " [send] Preparing to send message" ;
128
129
int credit = sndr.credit ();
@@ -150,12 +151,14 @@ void TxSenderHandler::send()
150
151
}
151
152
152
153
153
- logger (trace) << " [send] Transaction is empty: " << tx. is_empty ();
154
+ logger (trace) << " [send] Transaction is empty: " << s. txn_is_empty ();
154
155
logger (debug) << " [send] Messages processed: " << processed;
155
156
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)
157
158
{
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" ;
159
162
current_batch += 1 ;
160
163
161
164
if (log_msgs == " dict" ) {
@@ -185,27 +188,26 @@ void TxSenderHandler::send()
185
188
if (current_batch == batch_size) {
186
189
logger (debug) << " [send] Transaction attempt: " << tx_action;
187
190
if (tx_action == " commit" ) {
188
- tx. commit ();
191
+ s. txn_commit ();
189
192
} else if (tx_action == " rollback" ) {
190
- tx. abort ();
193
+ s. txn_abort ();
191
194
}
192
- tx = transaction ();
193
195
194
196
if (tx_action == " none" ) {
195
197
if (processed + current_batch == count) {
196
198
sndr.connection ().close ();
197
199
} else {
198
200
processed += current_batch;
199
201
current_batch = 0 ;
200
- sess .declare_transaction (*this );
202
+ s .declare_transaction (*this );
201
203
}
202
204
}
203
205
} else if (processed + current_batch == count) {
204
206
logger (debug) << " [send] Transaction attempt (endloop): " << tx_endloop_action;
205
207
if (tx_endloop_action == " commit" ) {
206
- tx. commit ();
208
+ s. txn_commit ();
207
209
} else if (tx_endloop_action == " rollback" ) {
208
- tx. abort ();
210
+ s. txn_abort ();
209
211
}
210
212
sndr.connection ().close ();
211
213
}
@@ -221,9 +223,10 @@ void TxSenderHandler::send()
221
223
222
224
void TxSenderHandler::on_sendable (sender &s)
223
225
{
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;
225
228
if (ready) {
226
- send ();
229
+ send (s. session () );
227
230
}
228
231
}
229
232
@@ -238,39 +241,39 @@ void TxSenderHandler::on_connection_close(connection &c)
238
241
logger (debug) << " [on_connection_close] Closing connection" ;
239
242
}
240
243
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 );
247
250
}
248
251
249
- void TxSenderHandler::on_transaction_committed (transaction t ) {
252
+ void TxSenderHandler::on_transaction_committed (session s ) {
250
253
logger (trace) << " [on_transaction_committed] Messages committed" ;
251
254
processed += current_batch;
252
255
logger (debug) << " [on_transaction_committed] Messages processed" << processed;
253
256
if (processed == count) {
254
257
logger (trace) << " [on_transaction_committed] All messages processed" ;
255
- t .connection ().close ();
258
+ s .connection ().close ();
256
259
} else {
257
260
logger (trace) << " [on_transaction_committed] Declaring new transaction" ;
258
261
current_batch = 0 ;
259
- sess .declare_transaction (*this );
262
+ s .declare_transaction (*this );
260
263
}
261
264
}
262
265
263
- void TxSenderHandler::on_transaction_aborted (transaction t ) {
266
+ void TxSenderHandler::on_transaction_aborted (session s ) {
264
267
logger (trace) << " [on_transaction_aborted] Messages aborted" ;
265
268
processed += current_batch;
266
- logger (debug) << " [on_transaction_committed ] Messages processed" << processed;
269
+ logger (debug) << " [on_transaction_aborted ] Messages processed" << processed;
267
270
if (processed == count) {
268
271
logger (trace) << " [on_transaction_aborted] All messages processed" ;
269
- t .connection ().close ();
272
+ s .connection ().close ();
270
273
} else {
271
- logger (trace) << " [on_transaction_committed ] Declaring new transaction" ;
274
+ logger (trace) << " [on_transaction_aborted ] Declaring new transaction" ;
272
275
current_batch = 0 ;
273
- sess .declare_transaction (*this );
276
+ s .declare_transaction (*this );
274
277
}
275
278
}
276
279
@@ -279,7 +282,6 @@ void TxSenderHandler::on_sender_close(sender &s) {
279
282
}
280
283
281
284
void TxSenderHandler::on_session_open (session &s) {
282
- sess = s;
283
285
logger (trace) << " [on_session_open] declare_txn started..." ;
284
286
s.declare_transaction (*this );
285
287
logger (trace) << " [on_session_open] declare_txn ended..." ;
@@ -366,26 +368,27 @@ void TxSenderHandler::on_container_start(container &c)
366
368
367
369
logger (trace) << " [on_container_start] Interval for duration: " << interval.milliseconds () << " ms" ;
368
370
}
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();
382
385
}
383
386
384
- void TxSenderHandler::on_transaction_declare_failed (transaction ) {}
387
+ void TxSenderHandler::on_transaction_declare_failed (session ) {}
385
388
386
- void TxSenderHandler::on_transaction_commit_failed (transaction t ) {
389
+ void TxSenderHandler::on_transaction_commit_failed (session s ) {
387
390
logger (error) << " [on_transaction_commit_failed] Transaction Commit Failed" ;
388
- t .connection ().close ();
391
+ s .connection ().close ();
389
392
exit (1 );
390
393
}
391
394
0 commit comments