qpid_proton 0.7 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b70107ac69810c2330900845476d870eb2e3361f
4
- data.tar.gz: 1093747ff006b0b6136efbab601c6c23de7d0a1c
3
+ metadata.gz: f914374a534998105fb090532516ae7ca15b014a
4
+ data.tar.gz: 0d030a2c53ef6d6a7194ad12bea93b616f292284
5
5
  SHA512:
6
- metadata.gz: 09b2d6aba8690da17517b1132d6a3b3aac42847aa4d93bf0310659b92d5644a1cb2e882e673f3c0c818909a9df5ef197c0bc9b6e8dc2ddfe4b2742f0dc8045b9
7
- data.tar.gz: 7df1a080509c2f7408255609da58fbcbbc2afc086e2a5a3b0f89f89d73d3f12e1535b4a5c5e1f0c89e1cfebf5f05a18d09c69505874c12aa5e17cdcc9c52f9ac
6
+ metadata.gz: af26ed131c6b7bbdfefd1c7f0974c51356541b4f372df912b67c703197e85c8775f9bc69dbddb20b90fb066953650cf05c5ed7573cc4bc30f99ee75e52aa242e
7
+ data.tar.gz: 8576f8b33520a1d38c9dc557a1ee873bebcab41eebc2d434e6747aaf57e7bb493a0efc9d6a68847e1157f5b59715bb4e13373655582febd305723a1979c39cbc
@@ -26,11 +26,12 @@ require "qpid_proton/array"
26
26
  require "qpid_proton/hash"
27
27
  require "qpid_proton/exceptions"
28
28
  require "qpid_proton/exception_handling"
29
+ require "qpid_proton/filters"
29
30
  require "qpid_proton/message_format"
30
31
  require "qpid_proton/data"
31
32
  require "qpid_proton/message"
32
33
  require "qpid_proton/subscription"
33
34
  require "qpid_proton/tracker_status"
34
35
  require "qpid_proton/tracker"
36
+ require "qpid_proton/selectable"
35
37
  require "qpid_proton/messenger"
36
-
@@ -0,0 +1,67 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ module Qpid
21
+
22
+ module Proton
23
+
24
+ module Filters
25
+
26
+ def self.included(base)
27
+ base.class_eval do
28
+ extend ClassMethods
29
+ end
30
+ end
31
+
32
+ module ClassMethods
33
+
34
+ def method_added(method_name)
35
+ @@hooked_methods ||= []
36
+ return if @@hooked_methods.include?(method_name)
37
+ @@hooked_methods << method_name
38
+ hooks = @@before_hooks[method_name]
39
+ return if hooks.nil?
40
+ orig_method = instance_method(method_name)
41
+ define_method(method_name) do |*args, &block|
42
+ hooks = @@before_hooks[method_name]
43
+ hooks.each do |hook|
44
+ method(hook).call
45
+ end
46
+
47
+ orig_method.bind(self).call(*args, &block)
48
+ end
49
+ end
50
+
51
+ def call_before(before_method, *methods)
52
+ @@before_hooks ||= {}
53
+ methods.each do |method|
54
+ hooks = @@before_hooks[method] || []
55
+ raise "Repeat filter: #{before_method}" if hooks.include? before_method
56
+ hooks << before_method
57
+ @@before_hooks[method] = hooks
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -36,19 +36,19 @@ module Qpid
36
36
  #
37
37
  # The Messenger class works in conjuction with the Message class. The
38
38
  # Message class is a mutable holder of message content.
39
- #
40
- # The put method copies its Message to the outgoing queue, and may
39
+ #
40
+ # The put method copies its Message to the outgoing queue, and may
41
41
  # send queued messages if it can do so without blocking. The send
42
42
  # method blocks until it has sent the requested number of messages,
43
43
  # or until a timeout interrupts the attempt.
44
- #
44
+ #
45
45
  # Similarly, the recv method receives messages into the incoming
46
46
  # queue, and may block as it attempts to receive the requested number
47
47
  # of messages, or until timeout is reached. It may receive fewer
48
48
  # than the requested number. The get method pops the
49
49
  # eldest Message off the incoming queue and copies it into the Message
50
50
  # object that you supply. It will not block.
51
- #
51
+ #
52
52
  # The blocking attribute allows you to turn off blocking behavior entirely,
53
53
  # in which case send and recv will do whatever they can without
54
54
  # blocking, and then return. You can then look at the number
@@ -70,6 +70,7 @@ module Qpid
70
70
  #
71
71
  def initialize(name = nil)
72
72
  @impl = Cproton.pn_messenger(name)
73
+ @selectables = {}
73
74
  ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
74
75
  end
75
76
 
@@ -136,6 +137,30 @@ module Qpid
136
137
  Cproton.pn_messenger_set_blocking(@impl, blocking)
137
138
  end
138
139
 
140
+ # Returns true if passive mode is enabled.
141
+ #
142
+ def passive?
143
+ Cproton.pn_messenger_is_passive(@impl)
144
+ end
145
+
146
+ # Turns passive mode on or off.
147
+ #
148
+ # When set to passive mode, Messenger will not attempt to perform I/O
149
+ # operations internally. In this mode it is necesssary to use the
150
+ # Selectable type to drive any I/O needed to perform requestioned
151
+ # actions.
152
+ #
153
+ # In this mode Messenger will never block.
154
+ #
155
+ def passive=(mode)
156
+ Cproton.pn_messenger_set_passive(@impl, mode)
157
+ end
158
+
159
+ def deadline
160
+ tstamp = Cproton.pn_messenger_deadline(@impl)
161
+ return tstamp / 1000.0 unless tstamp.nil?
162
+ end
163
+
139
164
  # Reports whether an error occurred.
140
165
  #
141
166
  def error?
@@ -457,6 +482,22 @@ module Qpid
457
482
  check_for_error(Cproton.pn_messenger_rewrite(@impl, pattern, address))
458
483
  end
459
484
 
485
+ def selectable
486
+ impl = Cproton.pn_messenger_selectable(@impl)
487
+
488
+ # if we don't have any selectables, then return
489
+ return nil if impl.nil?
490
+
491
+ fd = Cproton.pn_selectable_fd(impl)
492
+
493
+ selectable = @selectables[fd]
494
+ if selectable.nil?
495
+ selectable = Selectable.new(self, impl)
496
+ @selectables[fd] = selectable
497
+ end
498
+ return selectable
499
+ end
500
+
460
501
  # Returns a +Tracker+ for the message most recently sent via the put
461
502
  # method.
462
503
  #
@@ -601,6 +642,11 @@ module Qpid
601
642
  Cproton.pn_messenger_get_outgoing_window(@impl)
602
643
  end
603
644
 
645
+ # Unregisters a selectable object.
646
+ def unregister_selectable(fileno) # :nodoc:
647
+ @selectables.delete(fileno)
648
+ end
649
+
604
650
  private
605
651
 
606
652
  def valid_tracker?(tracker)
@@ -0,0 +1,126 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ module Qpid
21
+
22
+ module Proton
23
+
24
+ # Selectable enables accessing the underlying file descriptors
25
+ # for Messenger.
26
+ class Selectable
27
+
28
+ include Qpid::Proton::Filters
29
+
30
+ call_before :check_is_initialized,
31
+ :fileno, :capacity, :pending, :deadline,
32
+ :readable, :writable, :expired,
33
+ :registered=, :registered?
34
+
35
+ def initialize(messenger, impl) # :nodoc:
36
+ @messenger = messenger
37
+ @impl = impl
38
+ @io = nil
39
+ @freed = false
40
+ end
41
+
42
+ # Returns the underlying file descriptor.
43
+ #
44
+ # This can be used in conjunction with the IO class.
45
+ #
46
+ def fileno
47
+ Cproton.pn_selectable_fd(@impl)
48
+ end
49
+
50
+ def to_io
51
+ @io ||= IO.new(fileno)
52
+ end
53
+
54
+ # The number of bytes the selectable is capable of consuming.
55
+ #
56
+ def capacity
57
+ Cproton.pn_selectable_capacity(@impl)
58
+ end
59
+
60
+ # The number of bytes waiting to be written to the file descriptor.
61
+ #
62
+ def pending
63
+ Cproton.pn_selectable_pending(@impl)
64
+ end
65
+
66
+ # The future expiry time at which control will be returned to the
67
+ # selectable.
68
+ #
69
+ def deadline
70
+ tstamp = Cproton.pn_selectable_deadline(@impl)
71
+ tstamp.nil? ? nil : tstamp / 1000
72
+ end
73
+
74
+ def readable
75
+ Cproton.pn_selectable_readable(@impl)
76
+ end
77
+
78
+ def writable
79
+ Cproton.pn_selectable_writable(@impl)
80
+ end
81
+
82
+ def expired?
83
+ Cproton.pn_selectable_expired(@impl)
84
+ end
85
+
86
+ def registered=(registered)
87
+ Cproton.pn_selectable_set_registered(@impl, registered)
88
+ end
89
+
90
+ def registered?
91
+ Cproton.pn_selectable_is_registered(@impl)
92
+ end
93
+
94
+ def terminal?
95
+ return true if @impl.nil?
96
+ Cproton.pn_selectable_is_terminal(@impl)
97
+ end
98
+
99
+ def to_s
100
+ "fileno=#{self.fileno} registered=#{self.registered?} terminal=#{self.terminal?}"
101
+ end
102
+
103
+ def free
104
+ return if @freed
105
+ @freed = true
106
+ @messenger.unregister_selectable(fileno)
107
+ @io.close unless @io.nil?
108
+ Cproton.pn_selectable_free(@impl)
109
+ @impl = nil
110
+ end
111
+
112
+ def freed? # :nodoc:
113
+ @freed
114
+ end
115
+
116
+ private
117
+
118
+ def check_is_initialized
119
+ raise RuntimeError.new("selectable freed") if @impl.nil?
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+
126
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qpid_proton
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darryl L. Pierce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-25 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Proton is a high performance, lightweight messaging library. It can be used in
@@ -28,9 +28,11 @@ files:
28
28
  - ext/cproton/extconf.rb
29
29
  - ext/cproton/cproton.c
30
30
  - lib/qpid_proton.rb
31
+ - lib/qpid_proton/filters.rb
31
32
  - lib/qpid_proton/tracker_status.rb
32
33
  - lib/qpid_proton/described.rb
33
34
  - lib/qpid_proton/tracker.rb
35
+ - lib/qpid_proton/selectable.rb
34
36
  - lib/qpid_proton/hash.rb
35
37
  - lib/qpid_proton/subscription.rb
36
38
  - lib/qpid_proton/message.rb