hermann 0.11-x86-darwin-13 → 0.13-x86-darwin-13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,50 @@ void log_debug(char* msg) {
46
46
  }
47
47
  }
48
48
 
49
+ /**
50
+ * Convenience function
51
+ *
52
+ * @param config HermannInstanceConfig
53
+ * @param outputStream FILE*
54
+ *
55
+ * Log the contents of the configuration to the provided stream.
56
+ */
57
+ void fprintf_hermann_instance_config(HermannInstanceConfig* config, FILE* outputStream) {
58
+
59
+ const char* topic;
60
+ const char* brokers;
61
+ int isRkSet;
62
+ int isRktSet;
63
+ int partition;
64
+ int isInitialized;
65
+
66
+ if(config==NULL) {
67
+ fprintf(outputStream, "NULL configuration");
68
+ } else {
69
+
70
+ isRkSet = config->rk != NULL;
71
+ isRktSet = config->rkt != NULL;
72
+
73
+ if(config->topic == NULL) {
74
+ topic = NULL;
75
+ } else {
76
+ topic = config->topic;
77
+ }
78
+
79
+ if(config->brokers == NULL) {
80
+ brokers = "NULL";
81
+ } else {
82
+ brokers = config->brokers;
83
+ }
84
+
85
+ partition = config->partition;
86
+ isInitialized = config->isInitialized;
87
+ }
88
+
89
+ fprintf(outputStream, "{ topic: %s, brokers: %s, partition: %d, isInitialized: %d, rkSet: %d, rkTSet: %d }\n",
90
+ topic, brokers, partition, isInitialized, isRkSet, isRktSet );
91
+ }
92
+
49
93
  /**
50
94
  * Message delivery report callback.
51
95
  * Called once for each message.
@@ -226,7 +270,11 @@ static void logger (const rd_kafka_t *rk, int level,
226
270
  *
227
271
  * @param config HermannInstanceConfig* pointer to the instance configuration for this producer or consumer
228
272
  */
229
- void consumer_init_kafka(HermannInstanceConfig* config) {
273
+ void consumer_init_kafka(HermannInstanceConfig* config)
274
+ {
275
+ #ifdef TRACE
276
+ fprintf(stderr, "consumer_init_kafka");
277
+ #endif
230
278
 
231
279
  config->quiet = !isatty(STDIN_FILENO);
232
280
 
@@ -271,6 +319,10 @@ void consumer_init_kafka(HermannInstanceConfig* config) {
271
319
  static void consumer_consume_stop_callback(void *ptr) {
272
320
  HermannInstanceConfig* config = (HermannInstanceConfig*)ptr;
273
321
 
322
+ #ifdef TRACE
323
+ fprintf(stderr, "consumer_consume_stop_callback");
324
+ #endif
325
+
274
326
  config->run = 0;
275
327
  }
276
328
 
@@ -280,6 +332,10 @@ static void consumer_consume_stop_callback(void *ptr) {
280
332
  */
281
333
  void consumer_consume_loop(HermannInstanceConfig* consumerConfig) {
282
334
 
335
+ #ifdef TRACE
336
+ fprintf(stderr, "consumer_consume_loop");
337
+ #endif
338
+
283
339
  while (consumerConfig->run) {
284
340
  rd_kafka_message_t *rkmessage;
285
341
 
@@ -304,6 +360,10 @@ static VALUE consumer_consume(VALUE self) {
304
360
 
305
361
  HermannInstanceConfig* consumerConfig;
306
362
 
363
+ #ifdef TRACE
364
+ fprintf(stderr, "consumer_consume");
365
+ #endif
366
+
307
367
  Data_Get_Struct(self, HermannInstanceConfig, consumerConfig);
308
368
 
309
369
  if(consumerConfig->topic==NULL) {
@@ -352,6 +412,10 @@ static VALUE consumer_consume(VALUE self) {
352
412
  */
353
413
  void producer_init_kafka(HermannInstanceConfig* config) {
354
414
 
415
+ #ifdef TRACE
416
+ fprintf(stderr, "producer_init_kafka\n");
417
+ #endif
418
+
355
419
  config->quiet = !isatty(STDIN_FILENO);
356
420
 
357
421
  /* Kafka configuration */
@@ -389,6 +453,11 @@ void producer_init_kafka(HermannInstanceConfig* config) {
389
453
 
390
454
  /* We're now initialized */
391
455
  config->isInitialized = 1;
456
+
457
+ #ifdef TRACE
458
+ fprintf(stderr, "producer_init_kafka::END\n");
459
+ fprintf_hermann_instance_config(config, stderr);
460
+ #endif
392
461
  }
393
462
 
394
463
  /**
@@ -402,6 +471,10 @@ static VALUE producer_push_single(VALUE self, VALUE message) {
402
471
  HermannInstanceConfig* producerConfig;
403
472
  char buf[2048];
404
473
 
474
+ #ifdef TRACE
475
+ fprintf(stderr, "producer_push_single\n");
476
+ #endif
477
+
405
478
  Data_Get_Struct(self, HermannInstanceConfig, producerConfig);
406
479
 
407
480
  if(producerConfig->topic==NULL) {
@@ -420,6 +493,13 @@ static VALUE producer_push_single(VALUE self, VALUE message) {
420
493
  if (buf[len-1] == '\n')
421
494
  buf[--len] = '\0';
422
495
 
496
+ #ifdef TRACE
497
+ fprintf(stderr, "producer_push_single::before_produce message1\n");
498
+ fprintf_hermann_instance_config(producerConfig, stderr);
499
+ fprintf(stderr, "producer_push_single::before_produce_message2\n");
500
+ fflush(stderr);
501
+ #endif
502
+
423
503
  /* Send/Produce message. */
424
504
  if (rd_kafka_produce(producerConfig->rkt, producerConfig->partition, RD_KAFKA_MSG_F_COPY,
425
505
  /* Payload and length */
@@ -442,6 +522,10 @@ static VALUE producer_push_single(VALUE self, VALUE message) {
442
522
  /* Must poll to handle delivery reports */
443
523
  rd_kafka_poll(producerConfig->rk, 0);
444
524
 
525
+ #ifdef TRACE
526
+ fprintf(stderr, "producer_push_single::prior return\n");
527
+ #endif
528
+
445
529
  return self;
446
530
  }
447
531
 
@@ -459,6 +543,10 @@ static VALUE producer_push_array(VALUE self, int length, VALUE array) {
459
543
  int i;
460
544
  VALUE message;
461
545
 
546
+ #ifdef TRACE
547
+ fprintf(stderr, "producer_push_array\n");
548
+ #endif
549
+
462
550
  for(i=0;i<length;i++) {
463
551
  message = RARRAY_PTR(array)[i];
464
552
  producer_push_single(self, message);
@@ -479,6 +567,10 @@ static VALUE producer_push(VALUE self, VALUE message) {
479
567
 
480
568
  VALUE arrayP = rb_check_array_type(message);
481
569
 
570
+ #ifdef TRACE
571
+ fprintf(stderr, "producer_push\n");
572
+ #endif
573
+
482
574
  if(!NIL_P(arrayP)) {
483
575
  return producer_push_array(self, RARRAY_LEN(arrayP), message);
484
576
  } else {
@@ -497,10 +589,18 @@ static void consumer_free(void * p) {
497
589
 
498
590
  HermannInstanceConfig* config = (HermannInstanceConfig *)p;
499
591
 
592
+ #ifdef TRACE
593
+ fprintf(stderr, "consumer_free\n");
594
+ #endif
595
+
500
596
  // the p *should* contain a pointer to the consumerConfig which also must be freed
501
- rd_kafka_topic_destroy(config->rkt);
597
+ if(config->rkt != NULL) {
598
+ rd_kafka_topic_destroy(config->rkt);
599
+ }
502
600
 
503
- rd_kafka_destroy(config->rk);
601
+ if(config->rk != NULL) {
602
+ rd_kafka_destroy(config->rk);
603
+ }
504
604
 
505
605
  // clean up the struct
506
606
  free(config);
@@ -516,8 +616,31 @@ static void consumer_free(void * p) {
516
616
  static VALUE consumer_allocate(VALUE klass) {
517
617
 
518
618
  VALUE obj;
619
+ HermannInstanceConfig* consumerConfig;
620
+
621
+ #ifdef TRACE
622
+ fprintf(stderr, "consumer_free\n");
623
+ #endif
624
+
625
+ consumerConfig = ALLOC(HermannInstanceConfig);
626
+
627
+ // Make sure it's initialized
628
+ consumerConfig->topic = NULL;
629
+ consumerConfig->rk = NULL;
630
+ consumerConfig->rkt = NULL;
631
+ consumerConfig->brokers = NULL;
632
+ consumerConfig->partition = -1;
633
+ consumerConfig->topic_conf = NULL;
634
+ consumerConfig->errstr[0] = 0;
635
+ consumerConfig->conf = NULL;
636
+ consumerConfig->debug = NULL;
637
+ consumerConfig->start_offset = -1;
638
+ consumerConfig->do_conf_dump = -1;
639
+ consumerConfig->run = 0;
640
+ consumerConfig->exit_eof = 0;
641
+ consumerConfig->quiet = 0;
642
+ consumerConfig->isInitialized = 0;
519
643
 
520
- HermannInstanceConfig* consumerConfig = ALLOC(HermannInstanceConfig);
521
644
  obj = Data_Wrap_Struct(klass, 0, consumer_free, consumerConfig);
522
645
 
523
646
  return obj;
@@ -542,6 +665,10 @@ static VALUE consumer_initialize(VALUE self, VALUE topic, VALUE brokers, VALUE p
542
665
  char* brokersPtr;
543
666
  int partitionNo;
544
667
 
668
+ #ifdef TRACE
669
+ fprintf(stderr, "consumer_initialize\n");
670
+ #endif
671
+
545
672
  topicPtr = StringValuePtr(topic);
546
673
  brokersPtr = StringValuePtr(brokers);
547
674
  partitionNo = FIX2INT(partition);
@@ -570,6 +697,10 @@ static VALUE consumer_init_copy(VALUE copy, VALUE orig) {
570
697
  HermannInstanceConfig* orig_config;
571
698
  HermannInstanceConfig* copy_config;
572
699
 
700
+ #ifdef TRACE
701
+ fprintf(stderr, "consumer_init_copy\n");
702
+ #endif
703
+
573
704
  if(copy == orig) {
574
705
  return copy;
575
706
  }
@@ -596,13 +727,27 @@ static VALUE consumer_init_copy(VALUE copy, VALUE orig) {
596
727
  */
597
728
  static void producer_free(void * p) {
598
729
 
599
- HermannInstanceConfig* config = (HermannInstanceConfig *)p;
730
+ HermannInstanceConfig* config;
731
+
732
+ #ifdef TRACE
733
+ fprintf(stderr, "producer_free\n");
734
+ #endif
735
+
736
+ config = (HermannInstanceConfig *)p;
737
+
738
+ if(NULL==p) {
739
+ return;
740
+ }
600
741
 
601
742
  // Clean up the topic
602
- rd_kafka_topic_destroy(config->rkt);
743
+ if(config->rkt != NULL) {
744
+ rd_kafka_topic_destroy(config->rkt);
745
+ }
603
746
 
604
747
  // Take care of the producer instance
605
- rd_kafka_destroy(config->rk);
748
+ if(config->rk != NULL) {
749
+ rd_kafka_destroy(config->rk);
750
+ }
606
751
 
607
752
  // Free the struct
608
753
  free(config);
@@ -618,8 +763,30 @@ static void producer_free(void * p) {
618
763
  static VALUE producer_allocate(VALUE klass) {
619
764
 
620
765
  VALUE obj;
766
+ HermannInstanceConfig* producerConfig;
767
+
768
+ #ifdef TRACE
769
+ fprintf(stderr, "producer_allocate\n");
770
+ #endif
771
+
772
+ producerConfig = ALLOC(HermannInstanceConfig);
773
+
774
+ producerConfig->topic = NULL;
775
+ producerConfig->rk = NULL;
776
+ producerConfig->rkt = NULL;
777
+ producerConfig->brokers = NULL;
778
+ producerConfig->partition = -1;
779
+ producerConfig->topic_conf = NULL;
780
+ producerConfig->errstr[0] = 0;
781
+ producerConfig->conf = NULL;
782
+ producerConfig->debug = NULL;
783
+ producerConfig->start_offset = -1;
784
+ producerConfig->do_conf_dump = -1;
785
+ producerConfig->run = 0;
786
+ producerConfig->exit_eof = 0;
787
+ producerConfig->quiet = 0;
788
+ producerConfig->isInitialized = 0;
621
789
 
622
- HermannInstanceConfig* producerConfig = ALLOC(HermannInstanceConfig);
623
790
  obj = Data_Wrap_Struct(klass, 0, producer_free, producerConfig);
624
791
 
625
792
  return obj;
@@ -640,6 +807,10 @@ static VALUE producer_initialize(VALUE self, VALUE topic, VALUE brokers) {
640
807
  char* topicPtr;
641
808
  char* brokersPtr;
642
809
 
810
+ #ifdef TRACE
811
+ fprintf(stderr, "producer_initialize\n");
812
+ #endif
813
+
643
814
  topicPtr = StringValuePtr(topic);
644
815
  brokersPtr = StringValuePtr(brokers);
645
816
  Data_Get_Struct(self, HermannInstanceConfig, producerConfig);
@@ -669,6 +840,10 @@ static VALUE producer_init_copy(VALUE copy, VALUE orig) {
669
840
  HermannInstanceConfig* orig_config;
670
841
  HermannInstanceConfig* copy_config;
671
842
 
843
+ #ifdef TRACE
844
+ fprintf(stderr, "producer_init_copy\n");
845
+ #endif
846
+
672
847
  if(copy == orig) {
673
848
  return copy;
674
849
  }
@@ -695,6 +870,10 @@ static VALUE producer_init_copy(VALUE copy, VALUE orig) {
695
870
  */
696
871
  void Init_hermann_lib() {
697
872
 
873
+ #ifdef TRACE
874
+ fprintf(stderr, "init_hermann_lib\n");
875
+ #endif
876
+
698
877
  /* Define the module */
699
878
  m_hermann = rb_define_module("Hermann");
700
879
 
@@ -42,6 +42,8 @@
42
42
 
43
43
  #include <librdkafka/rdkafka.h>
44
44
 
45
+ #undef TRACE
46
+
45
47
  // Holds the defined Ruby module for Hermann
46
48
  static VALUE m_hermann;
47
49
 
Binary file
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermann
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 11
9
- version: "0.11"
8
+ - 13
9
+ version: "0.13"
10
10
  platform: x86-darwin-13
11
11
  authors:
12
12
  - Stan Campbell