This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
wmq_queue_manager.c
1577 lines (1413 loc) · 57.4 KB
/
wmq_queue_manager.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "wmq.h"
static ID ID_open;
static ID ID_call;
static ID ID_new;
static ID ID_backout;
static ID ID_connect_options;
static ID ID_q_mgr_name;
static ID ID_queue_manager;
static ID ID_exception_on_error;
static ID ID_descriptor;
static ID ID_message;
static ID ID_trace_level;
/* MQCD ID's */
static ID ID_channel_name;
static ID ID_transport_type;
static ID ID_mode_name;
static ID ID_tp_name;
static ID ID_security_exit;
static ID ID_send_exit;
static ID ID_receive_exit;
static ID ID_max_msg_length;
static ID ID_security_user_data;
static ID ID_send_user_data;
static ID ID_receive_user_data;
static ID ID_user_identifier;
static ID ID_password;
static ID ID_connection_name;
static ID ID_heartbeat_interval;
static ID ID_long_remote_user_id;
static ID ID_remote_security_id;
static ID ID_ssl_cipher_spec;
static ID ID_ssl_peer_name;
static ID ID_keep_alive_interval;
static ID ID_crypto_hardware;
static ID ID_use_system_connection_data;
/* MQSCO ID's */
static ID ID_key_repository;
/* Admin ID's */
static ID ID_create_queue;
static ID ID_q_name;
static ID ID_command;
void QueueManager_id_init(void)
{
ID_open = rb_intern("open");
ID_call = rb_intern("call");
ID_new = rb_intern("new");
ID_backout = rb_intern("backout");
ID_q_mgr_name = rb_intern("q_mgr_name");
ID_queue_manager = rb_intern("queue_manager");
ID_exception_on_error = rb_intern("exception_on_error");
ID_connect_options = rb_intern("connect_options");
ID_trace_level = rb_intern("trace_level");
ID_descriptor = rb_intern("descriptor");
ID_message = rb_intern("message");
/* MQCD ID's */
ID_channel_name = rb_intern("channel_name");
ID_transport_type = rb_intern("transport_type");
ID_mode_name = rb_intern("mode_name");
ID_tp_name = rb_intern("tp_name");
ID_security_exit = rb_intern("security_exit");
ID_send_exit = rb_intern("send_exit");
ID_receive_exit = rb_intern("receive_exit");
ID_max_msg_length = rb_intern("max_msg_length");
ID_security_user_data = rb_intern("security_user_data");
ID_send_user_data = rb_intern("send_user_data");
ID_receive_user_data = rb_intern("receive_user_data");
ID_user_identifier = rb_intern("user_identifier");
ID_password = rb_intern("password");
ID_connection_name = rb_intern("connection_name");
ID_heartbeat_interval = rb_intern("heartbeat_interval");
ID_long_remote_user_id = rb_intern("long_remote_user_id");
ID_remote_security_id = rb_intern("remote_security_id");
ID_ssl_cipher_spec = rb_intern("ssl_cipher_spec");
ID_ssl_peer_name = rb_intern("ssl_peer_name");
ID_keep_alive_interval = rb_intern("keep_alive_interval");
ID_use_system_connection_data = rb_intern("use_system_connection_data");
/* MQSCO ID's */
ID_key_repository = rb_intern("key_repository");
ID_crypto_hardware = rb_intern("crypto_hardware");
/* Admin ID's */
ID_create_queue = rb_intern("create_queue");
ID_q_name = rb_intern("q_name");
ID_command = rb_intern("command");
}
/* --------------------------------------------------
* C Structure to store MQ data types and other
* C internal values
* --------------------------------------------------*/
void QUEUE_MANAGER_free(void* p)
{
PQUEUE_MANAGER pqm = (PQUEUE_MANAGER)p;
if(pqm->trace_level>1) printf("WMQ::QueueManager Freeing QUEUE_MANAGER structure\n");
if (pqm->hcon && !pqm->already_connected) /* Valid MQ handle means MQDISC was not called */
{
printf("WMQ::QueueManager#free disconnect() was not called for Queue Manager instance!!\n");
printf("WMQ::QueueManager#free Automatically calling back() and disconnect()\n");
pqm->MQBACK(pqm->hcon, &pqm->comp_code, &pqm->reason_code);
pqm->MQDISC(&pqm->hcon, &pqm->comp_code, &pqm->reason_code);
}
#ifdef MQCD_VERSION_6
free(pqm->long_remote_user_id_ptr);
#endif
#ifdef MQCD_VERSION_7
free(pqm->ssl_peer_name_ptr);
#endif
#ifdef MQHB_UNUSABLE_HBAG
if (pqm->admin_bag != MQHB_UNUSABLE_HBAG)
{
pqm->mqDeleteBag(&pqm->admin_bag, &pqm->comp_code, &pqm->reason_code);
}
if (pqm->reply_bag != MQHB_UNUSABLE_HBAG)
{
pqm->mqDeleteBag(&pqm->reply_bag, &pqm->comp_code, &pqm->reason_code);
}
#endif
Queue_manager_mq_free(pqm);
free(pqm->p_buffer);
free(p);
}
VALUE QUEUE_MANAGER_alloc(VALUE klass)
{
static MQCNO default_MQCNO = {MQCNO_DEFAULT}; /* MQCONNX Connection Options */
#ifdef MQCNO_VERSION_2
static MQCD default_MQCD = {MQCD_CLIENT_CONN_DEFAULT}; /* Client Connection */
#endif
#ifdef MQCNO_VERSION_4
static MQSCO default_MQSCO = {MQSCO_DEFAULT};
#endif
PQUEUE_MANAGER pqm = ALLOC(QUEUE_MANAGER);
pqm->hcon = 0;
pqm->comp_code = 0;
pqm->reason_code = 0;
pqm->exception_on_error = 1;
pqm->already_connected = 0;
pqm->trace_level = 0;
memcpy(&pqm->connect_options, &default_MQCNO, sizeof(MQCNO));
#ifdef MQCNO_VERSION_2
memcpy(&pqm->client_conn, &default_MQCD, sizeof(MQCD));
/* Tell MQ to use Client Conn structures, etc. */
pqm->connect_options.Version = MQCNO_CURRENT_VERSION;
pqm->connect_options.ClientConnPtr = &pqm->client_conn;
#endif
#ifdef MQCNO_VERSION_4
memcpy(&pqm->ssl_config_opts, &default_MQSCO, sizeof(MQSCO));
#endif
#ifdef MQCD_VERSION_6
pqm->long_remote_user_id_ptr = 0;
#endif
#ifdef MQCD_VERSION_7
pqm->ssl_peer_name_ptr = 0;
#endif
#ifdef MQHB_UNUSABLE_HBAG
pqm->admin_bag = MQHB_UNUSABLE_HBAG;
pqm->reply_bag = MQHB_UNUSABLE_HBAG;
#endif
pqm->buffer_size = 0;
pqm->p_buffer = 0;
pqm->is_client_conn = 0;
pqm->mq_lib_handle = 0;
return Data_Wrap_Struct(klass, 0, QUEUE_MANAGER_free, pqm);
}
/*
* call-seq:
* new(...)
*
* Parameters:
* * Since the number of parameters can vary dramatically, all parameters are passed by name in a hash
* * See QueueManager.new for details on all the parameters
*
* Note:
* * It is not recommended to use this method, rather use QueueManager.connect, since
* it will automatically disconnect from the queue manager. It also deals with backing out
* the current unit of work in the event of an unhandled exception. E.g. Syntax Error
* * RuntimeError and ArgumentError exceptions are always thrown regardless of the
* value of :exception_on_error
*
* Todo:
* * Support multiple send and receive exits
*/
VALUE QueueManager_initialize(VALUE self, VALUE hash)
{
VALUE val;
VALUE str;
size_t size;
size_t length;
PQUEUE_MANAGER pqm;
Check_Type(hash, T_HASH);
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
WMQ_HASH2MQLONG(hash,trace_level, pqm->trace_level)
/* @name = options[:q_mgr_name] || '' # QMGR Name optional with Client Connection */
val = rb_hash_aref(hash, ID2SYM(ID_q_mgr_name));
if (NIL_P(val))
{
rb_iv_set(self, "@name", rb_str_new2(""));
if(pqm->trace_level > 1) printf("WMQ::QueueManager#initialize() Queue Manager:[Not specified, use Default QMGR]\n");
}
else
{
rb_iv_set(self, "@name", val);
if(pqm->trace_level > 1) printf("WMQ::QueueManager#initialize() Queue Manager:%s\n", RSTRING_PTR(val));
}
WMQ_HASH2BOOL(hash,exception_on_error, pqm->exception_on_error)
/*
* All Client connection parameters are ignored if connection_name is missing
*/
#ifdef MQCNO_VERSION_2
int use_system_connection_data = (rb_hash_aref(hash, ID2SYM(ID_use_system_connection_data)) == Qtrue) ? 1 : 0;
if(!NIL_P(rb_hash_aref(hash, ID2SYM(ID_connection_name))) || use_system_connection_data)
{
PMQCD pmqcd = &pqm->client_conn; /* Process MQCD */
pqm->is_client_conn = 1; /* Set to Client connection */
if(use_system_connection_data)
{
/*
* Use system defined connection data rather than explicitly providing a
* connection name. This is used with CCDT, the MQSERVER ENV var or the
* mqclient.ini file
*/
pqm->connect_options.ClientConnPtr = NULL;
}
else
{
WMQ_HASH2MQCHARS(hash,connection_name, pmqcd->ConnectionName)
}
WMQ_HASH2MQLONG (hash,transport_type, pmqcd->TransportType)
WMQ_HASH2MQCHARS(hash,mode_name, pmqcd->ModeName)
WMQ_HASH2MQCHARS(hash,tp_name, pmqcd->TpName)
WMQ_HASH2MQCHARS(hash,security_exit, pmqcd->SecurityExit)
WMQ_HASH2MQCHARS(hash,send_exit, pmqcd->SendExit)
WMQ_HASH2MQCHARS(hash,receive_exit, pmqcd->ReceiveExit)
WMQ_HASH2MQLONG (hash,max_msg_length, pmqcd->MaxMsgLength)
WMQ_HASH2MQCHARS(hash,security_user_data, pmqcd->SecurityUserData)
WMQ_HASH2MQCHARS(hash,send_user_data, pmqcd->SendUserData)
WMQ_HASH2MQCHARS(hash,receive_user_data, pmqcd->ReceiveUserData)
WMQ_HASH2MQCHARS(hash,user_identifier, pmqcd->UserIdentifier)
WMQ_HASH2MQCHARS(hash,password, pmqcd->Password)
/* Default channel name to system default */
val = rb_hash_aref(hash, ID2SYM(ID_channel_name));
if (NIL_P(val))
{
strncpy(pmqcd->ChannelName, "SYSTEM.DEF.SVRCONN", sizeof(pmqcd->ChannelName));
}
else
{
WMQ_HASH2MQCHARS(hash,channel_name, pmqcd->ChannelName)
}
#ifdef MQCD_VERSION_4
WMQ_HASH2MQLONG(hash,heartbeat_interval, pmqcd->HeartbeatInterval)
/* TODO:
WMQ_HASH2MQLONG(hash,exit_name_length, pmqcd->ExitNameLength)
WMQ_HASH2MQLONG(hash,exit_data_length, pmqcd->ExitDataLength)
WMQ_HASH2MQLONG(hash,send_exits_defined, pmqcd->SendExitsDefined)
WMQ_HASH2MQLONG(hash,receive_exits_defined, pmqcd->ReceiveExitsDefined)
TO_PTR (send_exit_ptr, pmqcd->SendExitPtr)
TO_PTR (send_user_data_ptr, pmqcd->SendUserDataPtr)
TO_PTR (receive_exit_ptr, pmqcd->ReceiveExitPtr)
TO_PTR (receive_user_data_ptr, pmqcd->ReceiveUserDataPtr)
*/
#endif
#ifdef MQCD_VERSION_6
val = rb_hash_aref(hash, ID2SYM(ID_long_remote_user_id));
if (!NIL_P(val))
{
str = StringValue(val);
length = RSTRING_LEN(str);
if (length > 0)
{
MQPTR pBuffer;
if(pqm->trace_level > 1)
printf("WMQ::QueueManager#initialize() Setting long_remote_user_id:%s\n",
RSTRING_PTR(str));
/* Include null at end of string */
pBuffer = ALLOC_N(char, length+1);
memcpy(pBuffer, RSTRING_PTR(str), length+1);
pmqcd->LongRemoteUserIdLength = length;
pmqcd->LongRemoteUserIdPtr = pBuffer;
pqm->long_remote_user_id_ptr = pBuffer;
}
}
WMQ_HASH2MQBYTES(hash,remote_security_id, pmqcd->RemoteSecurityId)
WMQ_HASH2MQCHARS(hash,ssl_cipher_spec, pmqcd->SSLCipherSpec)
#endif
#ifdef MQCD_VERSION_7
val = rb_hash_aref(hash, ID2SYM(ID_ssl_peer_name));
if (!NIL_P(val))
{
str = StringValue(val);
length = RSTRING_LEN(str);
if (length > 0)
{
MQPTR pBuffer;
if(pqm->trace_level > 1)
printf("WMQ::QueueManager#initialize() Setting ssl_peer_name:%s\n",
RSTRING_PTR(str));
/* Include null at end of string */
pBuffer = ALLOC_N(char, length+1);
memcpy(pBuffer, RSTRING_PTR(str), length+1);
pmqcd->SSLPeerNameLength = length;
pmqcd->SSLPeerNamePtr = pBuffer;
pqm->ssl_peer_name_ptr = pBuffer;
}
}
WMQ_HASH2MQLONG(hash,keep_alive_interval, pmqcd->KeepAliveInterval)
/* Only set if SSL options are supplied, otherwise
* environment variables are ignored: MQSSLKEYR and MQSSLCRYP
* Any SSL info in the client channel definition tables is also ignored
*/
if (!NIL_P(rb_hash_aref(hash, ID2SYM(ID_key_repository))) ||
!NIL_P(rb_hash_aref(hash, ID2SYM(ID_crypto_hardware))))
{
/* Process MQSCO */
WMQ_HASH2MQCHARS(hash,key_repository, pqm->ssl_config_opts.KeyRepository)
WMQ_HASH2MQCHARS(hash,crypto_hardware, pqm->ssl_config_opts.CryptoHardware)
pqm->connect_options.SSLConfigPtr = &pqm->ssl_config_opts;
}
#endif
}
else
{
pqm->is_client_conn = 0; /* Set to Server connection */
}
#endif
#ifdef MQCNO_VERSION_4
/* Process MQCNO */
WMQ_HASH2MQLONG(hash,connect_options, pqm->connect_options.Options)
#endif
/* --------------------------------------------------
* TODO: MQAIR Structure - LDAP Security
* --------------------------------------------------*/
return Qnil;
}
/*
* Before working with any queues, it is necessary to connect
* to the queue manager.
*
* Returns:
* * true : On Success
* * false: On Failure
*
* comp_code and reason_code are also updated.
* reason will return a text description of the reason_code
*
* Throws:
* * WMQ::WMQException if comp_code != MQCC_OK
* * Except if exception_on_error: false was supplied as a parameter
* to QueueManager.new
*/
VALUE QueueManager_connect(VALUE self)
{
VALUE name;
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
pqm->already_connected = 0;
Queue_manager_mq_load(pqm); /* Load MQ Library */
name = rb_iv_get(self,"@name");
name = StringValue(name);
if(pqm->trace_level)
printf("WMQ::QueueManager#connect() Connect to Queue Manager:%s\n", RSTRING_PTR(name));
if (pqm->hcon) /* Disconnect from qmgr if already connected, ignore errors */
{
if(pqm->trace_level)
printf("WMQ::QueueManager#connect() Already connected to Queue Manager:%s, Disconnecting first!\n", RSTRING_PTR(name));
pqm->MQDISC(&pqm->hcon, &pqm->comp_code, &pqm->reason_code);
}
pqm->MQCONNX(
RSTRING_PTR(name), /* queue manager */
&pqm->connect_options, /* connection options */
&pqm->hcon, /* connection handle */
&pqm->comp_code, /* completion code */
&pqm->reason_code); /* connect reason code */
if(pqm->trace_level)
printf("WMQ::QueueManager#connect() MQCONNX completed with reason:%s, Handle:%ld\n",
wmq_reason(pqm->reason_code),
(long)pqm->hcon);
if (pqm->comp_code == MQCC_FAILED)
{
pqm->hcon = 0;
if (pqm->exception_on_error)
{
rb_raise(wmq_exception,
"WMQ::QueueManager#connect(). Error connecting to Queue Manager:%s, reason:%s",
RSTRING_PTR(name),
wmq_reason(pqm->reason_code));
}
return Qfalse;
}
if (pqm->reason_code == MQRC_ALREADY_CONNECTED)
{
if(pqm->trace_level) printf("WMQ::QueueManager#connect() Already connected\n");
pqm->already_connected = 1;
}
return Qtrue;
}
/*
* Disconnect from this QueueManager instance
*
* Returns:
* * true : On Success
* * false: On Failure
*
* comp_code and reason_code are also updated.
* reason will return a text description of the reason_code
*
* Throws:
* * WMQ::WMQException if comp_code != MQCC_OK
* * Except if exception_on_error: false was supplied as a parameter
* to QueueManager.new
*/
VALUE QueueManager_disconnect(VALUE self)
{
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
if(pqm->trace_level) printf ("WMQ::QueueManager#disconnect() Queue Manager Handle:%ld\n", (long)pqm->hcon);
if (!pqm->already_connected)
{
pqm->MQDISC(&pqm->hcon, &pqm->comp_code, &pqm->reason_code);
if(pqm->trace_level) printf("WMQ::QueueManager#disconnect() MQDISC completed with reason:%s\n", wmq_reason(pqm->reason_code));
if (pqm->comp_code != MQCC_OK)
{
if (pqm->exception_on_error)
{
VALUE name = rb_iv_get(self,"@name");
name = StringValue(name);
rb_raise(wmq_exception,
"WMQ::QueueManager#disconnect(). Error disconnecting from Queue Manager:%s, reason:%s",
RSTRING_PTR(name),
wmq_reason(pqm->reason_code));
}
return Qfalse;
}
}
else
{
pqm->comp_code = 0;
pqm->reason_code = 0;
if(pqm->trace_level) printf ("WMQ::QueueManager#disconnect() Not calling MQDISC, since already connected on connect\n");
}
pqm->hcon = 0;
return Qtrue;
}
/*
* Commit the current unit of work for this QueueManager instance
*
* Note:
* * commit will have no effect if all put and get operations were performed
* without specifying sync: true
*
* Returns:
* * true : On Success
* * false: On Failure
*
* comp_code and reason_code are also updated.
* reason will return a text description of the reason_code
*
* Throws:
* * WMQ::WMQException if comp_code != MQCC_OK
* * Except if exception_on_error: false was supplied as a parameter
* to QueueManager.new
*/
VALUE QueueManager_commit(VALUE self)
{
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
if(pqm->trace_level) printf ("WMQ::QueueManager#commit() Queue Manager Handle:%ld\n", (long)pqm->hcon);
pqm->MQCMIT(pqm->hcon, &pqm->comp_code, &pqm->reason_code);
if(pqm->trace_level) printf("WMQ::QueueManager#commit() MQCMIT completed with reason:%s\n", wmq_reason(pqm->reason_code));
if (pqm->comp_code != MQCC_OK)
{
if (pqm->exception_on_error)
{
VALUE name = rb_iv_get(self,"@name");
name = StringValue(name);
rb_raise(wmq_exception,
"WMQ::QueueManager#commit(). Error commiting changes to Queue Manager:%s, reason:%s",
RSTRING_PTR(name),
wmq_reason(pqm->reason_code));
}
return Qfalse;
}
return Qtrue;
}
/*
* Backout the current unit of work for this QueueManager instance
*
* Since the last commit or rollback any messages put to a queue
* under synchpoint will be removed and any messages retrieved
* under synchpoint from any queues will be returned
*
* Note:
* * backout will have no effect if all put and get operations were performed
* without specifying sync: true
*
* Returns:
* * true : On Success
* * false: On Failure
*
* comp_code and reason_code are also updated.
* reason will return a text description of the reason_code
*
* Throws:
* * WMQ::WMQException if comp_code != MQCC_OK
* * Except if exception_on_error: false was supplied as a parameter
* to QueueManager.new
*/
VALUE QueueManager_backout(VALUE self)
{
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
if(pqm->trace_level) printf ("WMQ::QueueManager#backout() Queue Manager Handle:%ld\n", (long)pqm->hcon);
pqm->MQBACK(pqm->hcon, &pqm->comp_code, &pqm->reason_code);
if(pqm->trace_level) printf("WMQ::QueueManager#backout() MQBACK completed with reason:%s\n", wmq_reason(pqm->reason_code));
if (pqm->comp_code != MQCC_OK)
{
if (pqm->exception_on_error)
{
VALUE name = rb_iv_get(self,"@name");
name = StringValue(name);
rb_raise(wmq_exception,
"WMQ::QueueManager#backout(). Error backing out changes to Queue Manager:%s, reason:%s",
RSTRING_PTR(name),
wmq_reason(pqm->reason_code));
}
return Qfalse;
}
return Qtrue;
}
/*
* Advanced WebSphere MQ Use:
*
* Begin a unit of work between this QueueManager instance and another
* resource such as a Database
*
* Starts a new unit of work under which put and get can be called with
* with the parameter sync: true
*
* Returns:
* * true : On Success
* * false: On Failure
*
* comp_code and reason_code are also updated.
* reason will return a text description of the reason_code
*
* Throws:
* * WMQ::WMQException if comp_code != MQCC_OK
* * Except if exception_on_error: false was supplied as a parameter
* to QueueManager.new
*/
VALUE QueueManager_begin(VALUE self)
{
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
if(pqm->trace_level) printf ("WMQ::QueueManager#begin() Queue Manager Handle:%ld\n", (long)pqm->hcon);
pqm->MQBEGIN(pqm->hcon, 0, &pqm->comp_code, &pqm->reason_code);
if(pqm->trace_level) printf("WMQ::QueueManager#begin() MQBEGIN completed with reason:%s\n", wmq_reason(pqm->reason_code));
if (pqm->comp_code != MQCC_OK)
{
if (pqm->exception_on_error)
{
VALUE name = rb_iv_get(self,"@name");
name = StringValue(name);
rb_raise(wmq_exception,
"WMQ::QueueManager#begin(). Error starting unit of work on Queue Manager:%s, reason:%s",
RSTRING_PTR(name),
wmq_reason(pqm->reason_code));
}
return Qfalse;
}
return Qtrue;
}
/*
* call-seq:
* put(parameters)
*
* Put a message to the queue without having to first open the queue
* Recommended for reply queues that change frequently
*
* * parameters: a Hash consisting of one or more of the following parameters
*
* Summary of parameters and their WebSphere MQ equivalents
* queue.get( # WebSphere MQ Equivalents:
* q_name: 'Queue Name', # MQOD.ObjectName
* q_name: { queue_manager=>'QMGR_name', # MQOD.ObjectQMgrName
* q_name =>'q_name'}
* message: my_message, # n/a : Instance of Message
* data: "Hello World", # n/a : Data to send
* sync: false, # MQGMO_SYNCPOINT
* new_id: true, # MQPMO_NEW_MSG_ID & MQPMO_NEW_CORREL_ID
* new_msg_id: true, # MQPMO_NEW_MSG_ID
* new_correl_id: true, # MQPMO_NEW_CORREL_ID
* fail_if_quiescing: true, # MQOO_FAIL_IF_QUIESCING
* options: WMQ::MQPMO_FAIL_IF_QUIESCING # MQPMO_*
* )
*
* Mandatory Parameters
* * :q_name => String
* * Name of the existing WebSphere MQ local queue, model queue or remote queue to open
* * To open remote queues for which a local remote queue definition is not available
* pass a Hash as q_name (see q_name => Hash)
* OR
* * :q_name => Hash
* * q_name => String
* * Name of the existing WebSphere MQ local queue, model queue or remote queue to open
* * :q_mgr_name => String
* * Name of the remote WebSphere MQ queue manager to send the message to.
* * This allows a message to be written to a queue on a remote queue manager
* where a remote queue definition is not defined locally
* * Commonly used to reply to messages from remote systems
* * If q_mgr_name is the same as the local queue manager name then the message
* is merely written to the local queue.
* * Note: q_mgr_name should only be supplied when putting messages to the queue.
* It is not possible to get messages from a queue on a queue manager other
* than the currently connected queue manager
*
* * Either :message or :data must be supplied
* * If both are supplied, then :data will be written to the queue. The data in :message
* will be ignored
*
* Optional Parameters
* * :data => String
* * Data to be written to the queue. Can be binary or text data
*
* * :message => Message
* * An instance of the WMQ::Message
* * The Message descriptor, headers and data is retrieved from :message
* * message.data is ignored if :data is supplied
*
* * :sync => true or false
* * Determines whether the get is performed under synchpoint.
* I.e. Under the current unit of work
* Default: false
*
* * :new_id => true or false
* * Generate a new message id and correlation id for this
* message. :new_msg_id and :new_correl_id will be ignored
* if this parameter is true
* Default: false
*
* * :new_msg_id => true or false
* * Generate a new message id for this message
* * Note: A blank message id will result in a new message id anyway.
* However, for subsequent puts using the same message descriptor, the same
* message id will be used.
* Default: false
*
* * :new_correl_id => true or false
* * Generate a new correlation id for this message
* Default: false
*
* * :fail_if_quiescing => true or false
* * Determines whether the WMQ::Queue#put call will fail if the queue manager is
* in the process of being quiesced.
* * Note: This interface differs from other WebSphere MQ interfaces,
* they do not default to true.
* Default: true
* Equivalent to: MQGMO_FAIL_IF_QUIESCING
*
* * Note: As part of the application design, carefull consideration
* should be given as to when to allow a transaction or
* unit of work to complete or fail under this condition.
* As such it is important to include this option where
* appropriate so that MQ Administrators can shutdown the
* queue managers without having to resort to the 'immediate'
* shutdown option.
*
* * :options => Fixnum (Advanced MQ Use only)
* * Numeric field containing any of the MQ Put message options or'd together
* * E.g. options: WMQ::MQPMO_PASS_IDENTITY_CONTEXT | WMQ::MQPMO_ALTERNATE_USER_AUTHORITY
* * Note: If :options is supplied, it is applied first, then the above parameters are
* applied afterwards.
* * One or more of the following values:
* WMQ::MQPMO_NO_SYNCPOINT
* WMQ::MQPMO_LOGICAL_ORDER
* WMQ::MQPMO_NO_CONTEXT
* WMQ::MQPMO_DEFAULT_CONTEXT
* WMQ::MQPMO_PASS_IDENTITY_CONTEXT
* WMQ::MQPMO_PASS_ALL_CONTEXT
* WMQ::MQPMO_SET_IDENTITY_CONTEXT
* WMQ::MQPMO_SET_ALL_CONTEXT
* WMQ::MQPMO_ALTERNATE_USER_AUTHORITY
* WMQ::MQPMO_RESOLVE_LOCAL_Q
* WMQ::MQPMO_NONE
* * Please see the WebSphere MQ documentation for more details on the above options
* Default: WMQ::MQPMO_NONE
*
* Returns:
* * true : On Success
* * false: On Failure
*
* comp_code and reason_code are also updated.
* reason will return a text description of the reason_code
*
* Throws:
* * WMQ::WMQException if comp_code == MQCC_FAILED
* * Except if exception_on_error: false was supplied as a parameter
* to QueueManager.new
*/
VALUE QueueManager_put(VALUE self, VALUE hash)
{
MQLONG BufferLength; /* Length of the message in Buffer */
PMQVOID pBuffer; /* Message data */
MQMD md = {MQMD_DEFAULT}; /* Message Descriptor */
MQPMO pmo = {MQPMO_DEFAULT}; /* put message options */
MQOD od = {MQOD_DEFAULT}; /* Object Descriptor */
VALUE q_name;
VALUE str;
size_t size;
size_t length;
VALUE val;
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
Check_Type(hash, T_HASH);
q_name = rb_hash_aref(hash, ID2SYM(ID_q_name));
if (NIL_P(q_name))
{
rb_raise(rb_eArgError,
"Mandatory parameter :q_name is missing from WMQ::QueueManager::put1()");
}
/* --------------------------------------------------
* If :q_name is a hash, extract :q_name and :q_mgr_name
* --------------------------------------------------*/
if(TYPE(q_name) == T_HASH)
{
WMQ_HASH2MQCHARS(q_name, q_mgr_name, od.ObjectQMgrName)
q_name = rb_hash_aref(q_name, ID2SYM(ID_q_name));
if (NIL_P(q_name))
{
rb_raise(rb_eArgError,
"Mandatory parameter :q_name missing from :q_name hash passed to WMQ::QueueManager#put");
}
}
WMQ_STR2MQCHARS(q_name,od.ObjectName)
Queue_extract_put_message_options(hash, &pmo);
Message_build(&pqm->p_buffer, &pqm->buffer_size, pqm->trace_level,
hash, &pBuffer, &BufferLength, &md);
if(pqm->trace_level) printf("WMQ::QueueManager#put Queue Manager Handle:%ld\n", (long)pqm->hcon);
pqm->MQPUT1(
pqm->hcon, /* connection handle */
&od, /* object descriptor */
&md, /* message descriptor */
&pmo, /* put message options */
BufferLength, /* message length */
pBuffer, /* message buffer */
&pqm->comp_code, /* completion code */
&pqm->reason_code); /* reason code */
if(pqm->trace_level) printf("WMQ::QueueManager#put MQPUT1 ended with reason:%s\n", wmq_reason(pqm->reason_code));
if (pqm->reason_code != MQRC_NONE)
{
if (pqm->exception_on_error)
{
VALUE qmgr_name = QueueManager_name(self);
rb_raise(wmq_exception,
"WMQ::QueueManager.put(). Error writing a message to Queue:%s on Queue Manager:%s reason:%s",
RSTRING_PTR(q_name),
RSTRING_PTR(qmgr_name),
wmq_reason(pqm->reason_code));
}
return Qfalse;
}
else
{
VALUE message = rb_hash_aref(hash, ID2SYM(ID_message));
if(!NIL_P(message))
{
VALUE descriptor = rb_funcall(message, ID_descriptor, 0);
Message_from_mqmd(descriptor, &md); /* This could be optimized to output only fields */
}
}
return Qtrue;
}
/*
* Return the completion code for the last MQ operation
*
* Returns => FixNum
* * WMQ::MQCC_OK 0
* * WMQ::MQCC_WARNING 1
* * WMQ::MQCC_FAILED 2
* * WMQ::MQCC_UNKNOWN -1
*
*/
VALUE QueueManager_comp_code(VALUE self)
{
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
return LONG2NUM(pqm->comp_code);
}
/*
* Return the reason code for the last MQ operation
*
* Returns => FixNum
* * For a complete list of reason codes, please see WMQ Constants or
* the WebSphere MQ documentation for Reason Codes
*
* Note
* * The list of Reason Codes varies depending on the version of WebSphere MQ
* and the operating system on which Ruby WMQ was compiled
*/
VALUE QueueManager_reason_code(VALUE self)
{
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
return LONG2NUM(pqm->reason_code);
}
/*
* Returns a textual representation of the reason_code for the last MQ operation
*
* Returns => String
* * For a complete list of reasons, please see WMQ Constants or
* the WebSphere MQ documentation for Reason Codes
*
* Note
* * The list of Reason Codes varies depending on the version of WebSphere MQ
* and the operating system on which Ruby WMQ was compiled
*/
VALUE QueueManager_reason(VALUE self)
{
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
return rb_str_new2(wmq_reason(pqm->reason_code));
}
/*
* Returns whether this QueueManager instance is set
* to throw a WMQ::WMQException whenever an MQ operation fails
*
* Returns:
* * true : This QueueManager instance will throw a WMQ::WMQException whenever
* an MQ operation fails. I.e. if comp_code != WMQ::OK.
* * false: WMQ::WMQException will not be thrown
*
* Note:
* * RuntimeError and ArgumentError exceptions are always thrown regardless of the
* value of exception_on_error
*/
VALUE QueueManager_exception_on_error(VALUE self)
{
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
if (pqm->exception_on_error)
{
return Qtrue;
}
return Qfalse;
}
/*
* Returns whether this QueueManager instance is currently
* connected to a WebSphere MQ queue manager
*
* Returns:
* * true : This QueueManager instance is connected to a local or remote queue manager
* * false: This QueueManager instance is not currently connected to a local or
* remote queue manager
*/
VALUE QueueManager_connected_q(VALUE self)
{
PQUEUE_MANAGER pqm;
Data_Get_Struct(self, QUEUE_MANAGER, pqm);
if (pqm->hcon)
{
return Qtrue;
}
return Qfalse;
}
/*
* Returns the QueueManager name => String
*/
VALUE QueueManager_name(VALUE self)
{
return rb_iv_get(self,"@name");
}
static VALUE QueueManager_open_queue_block(VALUE message, VALUE proc)
{
return rb_funcall(proc, ID_call, 1, message);
}
static VALUE QueueManager_open_queue_each(VALUE parameters)
{
return Queue_singleton_open(1, ¶meters, wmq_queue);
}
/*
* call-seq:
* open_queue(...)
* access_queue(...)
*
* Open the specified queue, then close it once the
* supplied code block has completed
*
* Parameters:
* * Since the number of parameters can vary dramatically, all parameters are passed by name in a hash
* * See Queue.open for the complete list of parameters, except that :queue_manager is *not* required
* since it is supplied automatically by this method