qpid_proton 0.9.0 → 0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codec/data.rb +912 -0
  3. data/lib/codec/mapping.rb +169 -0
  4. data/lib/{qpid_proton/tracker.rb → core/base_handler.rb} +4 -15
  5. data/lib/core/connection.rb +328 -0
  6. data/lib/core/delivery.rb +271 -0
  7. data/lib/core/disposition.rb +158 -0
  8. data/lib/core/endpoint.rb +140 -0
  9. data/lib/{qpid_proton → core}/exceptions.rb +43 -2
  10. data/lib/core/link.rb +387 -0
  11. data/lib/core/message.rb +633 -0
  12. data/lib/core/receiver.rb +95 -0
  13. data/lib/core/sasl.rb +94 -0
  14. data/lib/core/selectable.rb +130 -0
  15. data/lib/core/sender.rb +76 -0
  16. data/lib/core/session.rb +163 -0
  17. data/lib/core/ssl.rb +164 -0
  18. data/lib/{qpid_proton/version.rb → core/ssl_details.rb} +7 -6
  19. data/lib/core/ssl_domain.rb +156 -0
  20. data/lib/core/terminus.rb +218 -0
  21. data/lib/core/transport.rb +411 -0
  22. data/lib/core/url.rb +77 -0
  23. data/lib/event/collector.rb +148 -0
  24. data/lib/event/event.rb +318 -0
  25. data/lib/event/event_base.rb +91 -0
  26. data/lib/event/event_type.rb +71 -0
  27. data/lib/handler/acking.rb +70 -0
  28. data/lib/handler/c_adaptor.rb +47 -0
  29. data/lib/handler/c_flow_controller.rb +33 -0
  30. data/lib/handler/endpoint_state_handler.rb +217 -0
  31. data/lib/handler/incoming_message_handler.rb +74 -0
  32. data/lib/handler/messaging_handler.rb +218 -0
  33. data/lib/handler/outgoing_message_handler.rb +98 -0
  34. data/lib/handler/wrapped_handler.rb +76 -0
  35. data/lib/messenger/messenger.rb +702 -0
  36. data/lib/messenger/subscription.rb +37 -0
  37. data/lib/messenger/tracker.rb +38 -0
  38. data/lib/messenger/tracker_status.rb +69 -0
  39. data/lib/qpid_proton.rb +106 -16
  40. data/lib/reactor/acceptor.rb +41 -0
  41. data/lib/reactor/backoff.rb +41 -0
  42. data/lib/reactor/connector.rb +98 -0
  43. data/lib/reactor/container.rb +272 -0
  44. data/lib/reactor/global_overrides.rb +44 -0
  45. data/lib/reactor/link_option.rb +90 -0
  46. data/lib/reactor/reactor.rb +198 -0
  47. data/lib/reactor/session_per_connection.rb +45 -0
  48. data/lib/reactor/ssl_config.rb +41 -0
  49. data/lib/reactor/task.rb +39 -0
  50. data/lib/{qpid_proton/subscription.rb → reactor/urls.rb} +12 -13
  51. data/lib/{qpid_proton → types}/array.rb +28 -29
  52. data/lib/types/described.rb +63 -0
  53. data/lib/{qpid_proton → types}/hash.rb +4 -3
  54. data/lib/types/strings.rb +62 -0
  55. data/lib/util/class_wrapper.rb +54 -0
  56. data/lib/util/condition.rb +45 -0
  57. data/lib/util/constants.rb +85 -0
  58. data/lib/util/engine.rb +82 -0
  59. data/lib/util/error_handler.rb +127 -0
  60. data/lib/util/handler.rb +41 -0
  61. data/lib/util/reactor.rb +32 -0
  62. data/lib/util/swig_helper.rb +114 -0
  63. data/lib/util/timeout.rb +50 -0
  64. data/lib/util/uuid.rb +32 -0
  65. data/lib/util/version.rb +30 -0
  66. data/lib/util/wrapper.rb +124 -0
  67. metadata +67 -21
  68. data/ext/cproton/cproton.c +0 -22196
  69. data/lib/qpid_proton/data.rb +0 -788
  70. data/lib/qpid_proton/described.rb +0 -66
  71. data/lib/qpid_proton/exception_handling.rb +0 -127
  72. data/lib/qpid_proton/filters.rb +0 -67
  73. data/lib/qpid_proton/mapping.rb +0 -170
  74. data/lib/qpid_proton/message.rb +0 -621
  75. data/lib/qpid_proton/messenger.rb +0 -702
  76. data/lib/qpid_proton/selectable.rb +0 -126
  77. data/lib/qpid_proton/strings.rb +0 -65
  78. data/lib/qpid_proton/tracker_status.rb +0 -73
@@ -0,0 +1,37 @@
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::Proton::Messenger
21
+
22
+ # A +Subscription+ is an opaque object for working with a +Messenger+'s
23
+ # subscriptions.
24
+ #
25
+ class Subscription
26
+
27
+ def initialize(impl) # :nodoc:
28
+ @impl = impl
29
+ end
30
+
31
+ def impl # :nodoc:
32
+ @impl
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,38 @@
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::Proton::Messenger
21
+
22
+ # A +Tracker+ is used to track the disposition of a +Message+.
23
+ #
24
+ class Tracker
25
+
26
+ CUMULATIVE = Cproton::PN_CUMULATIVE
27
+
28
+ def initialize(impl) # :nodoc:
29
+ @impl = impl
30
+ end
31
+
32
+ def impl # :nodoc:
33
+ @impl
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,69 @@
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::Proton::Messenger
21
+
22
+ # TrackerStatus contains symbols that represent the status value for a
23
+ # Tracker.
24
+ #
25
+ class TrackerStatus
26
+
27
+ def initialize value, name # :nodoc:
28
+ @value = value
29
+ @name = name
30
+ end
31
+
32
+ def value # :nodoc:
33
+ @value
34
+ end
35
+
36
+ def to_s # :nodoc:
37
+ @name.to_s
38
+ end
39
+
40
+ def self.by_name(name) # :nodoc:
41
+ @by_name[name.to_sym] unless name.nil?
42
+ end
43
+
44
+ def self.by_value(value) # :nodoc:
45
+ @by_value[value] unless value.nil?
46
+ end
47
+
48
+ private
49
+
50
+ def self.add_item(key, value) # :nodoc:
51
+ @by_name ||= {}
52
+ @by_name[key] = TrackerStatus.new value, key
53
+ @by_value ||= {}
54
+ @by_value[value] = @by_name[key]
55
+ end
56
+
57
+ def self.const_missing(key) # :nodoc:
58
+ @by_name[key]
59
+ end
60
+
61
+ self.add_item :UNKNOWN, Cproton::PN_STATUS_UNKNOWN
62
+ self.add_item :PENDING, Cproton::PN_STATUS_PENDING
63
+ self.add_item :ACCEPTED, Cproton::PN_STATUS_ACCEPTED
64
+ self.add_item :REJECTED, Cproton::PN_STATUS_REJECTED
65
+ self.add_item :SETTLED, Cproton::PN_STATUS_SETTLED
66
+
67
+ end
68
+
69
+ end
data/lib/qpid_proton.rb CHANGED
@@ -19,24 +19,114 @@
19
19
 
20
20
  require "cproton"
21
21
  require "date"
22
+ require "weakref"
22
23
 
23
24
  if RUBY_VERSION < "1.9"
24
25
  require "kconv"
26
+ else
27
+ require "securerandom"
25
28
  end
26
29
 
27
- require "qpid_proton/version"
28
- require "qpid_proton/described"
29
- require "qpid_proton/strings"
30
- require "qpid_proton/mapping"
31
- require "qpid_proton/array"
32
- require "qpid_proton/hash"
33
- require "qpid_proton/exceptions"
34
- require "qpid_proton/exception_handling"
35
- require "qpid_proton/filters"
36
- require "qpid_proton/data"
37
- require "qpid_proton/message"
38
- require "qpid_proton/subscription"
39
- require "qpid_proton/tracker_status"
40
- require "qpid_proton/tracker"
41
- require "qpid_proton/selectable"
42
- require "qpid_proton/messenger"
30
+ # Exception classes
31
+ require "core/exceptions"
32
+
33
+ # Utility classes
34
+ require "util/version"
35
+ require "util/error_handler"
36
+ require "util/constants"
37
+ require "util/swig_helper"
38
+ require "util/condition"
39
+ require "util/wrapper"
40
+ require "util/class_wrapper"
41
+ require "util/engine"
42
+ require "util/uuid"
43
+ require "util/timeout"
44
+ require "util/handler"
45
+ require "util/reactor"
46
+
47
+ # Types
48
+ require "types/strings"
49
+ require "types/hash"
50
+ require "types/array"
51
+ require "types/described"
52
+
53
+ # Codec classes
54
+ require "codec/mapping"
55
+ require "codec/data"
56
+
57
+ # Event API classes
58
+ require "event/event_type"
59
+ require "event/event_base"
60
+ require "event/event"
61
+ require "event/collector"
62
+
63
+ # Main Proton classes
64
+ require "core/selectable"
65
+ require "core/message"
66
+ require "core/endpoint"
67
+ require "core/session"
68
+ require "core/terminus"
69
+ require "core/disposition"
70
+ require "core/delivery"
71
+ require "core/link"
72
+ require "core/sender"
73
+ require "core/receiver"
74
+ require "core/connection"
75
+ require "core/sasl"
76
+ require "core/ssl_domain"
77
+ require "core/ssl_details"
78
+ require "core/ssl"
79
+ require "core/transport"
80
+ require "core/base_handler"
81
+ require "core/url"
82
+
83
+ # Messenger API classes
84
+ require "messenger/subscription"
85
+ require "messenger/tracker_status"
86
+ require "messenger/tracker"
87
+ require "messenger/messenger"
88
+
89
+ # Handler classes
90
+ require "handler/c_adaptor"
91
+ require "handler/wrapped_handler"
92
+ require "handler/acking"
93
+ require "handler/endpoint_state_handler"
94
+ require "handler/incoming_message_handler"
95
+ require "handler/outgoing_message_handler"
96
+ require "handler/c_flow_controller"
97
+ require "handler/messaging_handler"
98
+
99
+ # Reactor classes
100
+ require "reactor/task"
101
+ require "reactor/acceptor"
102
+ require "reactor/reactor"
103
+ require "reactor/ssl_config"
104
+ require "reactor/global_overrides"
105
+ require "reactor/urls"
106
+ require "reactor/connector"
107
+ require "reactor/backoff"
108
+ require "reactor/session_per_connection"
109
+ require "reactor/container"
110
+ require "reactor/link_option"
111
+
112
+ module Qpid::Proton
113
+ # @private
114
+ def self.registry
115
+ @registry ||= {}
116
+ end
117
+
118
+ # @private
119
+ def self.add_to_registry(key, value)
120
+ self.registry[key] = value
121
+ end
122
+
123
+ # @private
124
+ def self.get_from_registry(key)
125
+ self.registry[key]
126
+ end
127
+
128
+ # @private
129
+ def self.delete_from_registry(key)
130
+ self.registry.delete(key)
131
+ end
132
+ end
@@ -0,0 +1,41 @@
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::Proton::Reactor
21
+
22
+ class Acceptor
23
+
24
+ include Qpid::Proton::Util::Wrapper
25
+
26
+ def initialize(impl)
27
+ @impl = impl
28
+ self.class.store_instance(self)
29
+ end
30
+
31
+ def set_ssl_domain(ssl_domain)
32
+ Cproton.pn_acceptor_set_ssl_domain(@impl, ssl_domain.impl)
33
+ end
34
+
35
+ def close
36
+ Cproton.pn_acceptor_close(@impl)
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,41 @@
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::Proton::Reactor
21
+
22
+ class Backoff
23
+
24
+ def initialize
25
+ @delay = 0
26
+ end
27
+
28
+ def reset
29
+ @delay = 0
30
+ end
31
+
32
+ def next
33
+ current = @delay
34
+ current = 0.1 if current.zero?
35
+ @delay = [10, 2 * current].min
36
+ return current
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,98 @@
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::Proton::Reactor
21
+
22
+ class Connector < Qpid::Proton::BaseHandler
23
+
24
+ attr_accessor :address
25
+ attr_accessor :reconnect
26
+ attr_accessor :ssl_domain
27
+
28
+ def initialize(connection)
29
+ @connection = connection
30
+ @address = nil
31
+ @heartbeat = nil
32
+ @reconnect = nil
33
+ @ssl_domain = nil
34
+ end
35
+
36
+ def on_connection_local_open(event)
37
+ self.connect(event.connection)
38
+ end
39
+
40
+ def on_connection_remote_open(event)
41
+ if !@reconnect.nil?
42
+ @reconnect.reset
43
+ @transport = nil
44
+ end
45
+ end
46
+
47
+ def on_transport_tail_closed(event)
48
+ self.on_transport_closed(event)
49
+ end
50
+
51
+ def on_transport_closed(event)
52
+ if !@connection.nil? && !(@connection.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
53
+ if !@reconnect.nil?
54
+ event.transport.unbind
55
+ delay = @reconnect.next
56
+ if delay == 0
57
+ self.connect(@connection)
58
+ else
59
+ event.reactor.schedule(delay, self)
60
+ end
61
+ else
62
+ @connection = nil
63
+ end
64
+ end
65
+ end
66
+
67
+ def on_timer_task(event)
68
+ self.connect(@connection)
69
+ end
70
+
71
+ def on_connection_remote_close(event)
72
+ @connection = nil
73
+ end
74
+
75
+ def connect(connection)
76
+ url = @address.next
77
+ connection.hostname = "#{url.host}:#{url.port}"
78
+
79
+ transport = Qpid::Proton::Transport.new
80
+ transport.bind(connection)
81
+ if !@heartbeat.nil?
82
+ transport.idle_timeout = @heartbeat
83
+ elsif (url.scheme == "amqps") && !@ssl_domain.nil?
84
+ @ssl = Qpid::Proton::SSL.new(transport, @ssl_domain)
85
+ @ss.peer_hostname = url.host
86
+ elsif !url.username.nil?
87
+ sasl = transport.sasl
88
+ if url.username == "anonymous"
89
+ sasl.mechanisms("ANONYMOUS")
90
+ else
91
+ sasl.plain(url.username, url.password)
92
+ end
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ end