zmachine 0.1.0 → 0.1.1

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.
@@ -5,7 +5,6 @@ require 'zmachine/deferrable'
5
5
  require 'zmachine/reactor'
6
6
  require 'zmachine/timers'
7
7
 
8
- java_import java.lang.ThreadLocal
9
8
 
10
9
  module ZMachine
11
10
  class ConnectionError < RuntimeError; end
@@ -13,16 +12,17 @@ module ZMachine
13
12
  class UnknownTimerFired < RuntimeError; end
14
13
  class Unsupported < RuntimeError; end
15
14
 
15
+ class << self
16
+ attr_accessor :logger
17
+ attr_accessor :debug
18
+ end
19
+
16
20
  def self.reactor
17
- @reactor ||= ThreadLocal.new
18
- @reactor.set(Reactor.new) unless @reactor.get
19
- @reactor.get
21
+ Thread.current[:reactor] ||= Reactor.new
20
22
  end
21
23
 
22
24
  def self.context
23
- @context ||= ThreadLocal.new
24
- @context.set(ZContext.new) unless @context.get
25
- @context.get
25
+ Thread.current[:context] ||= ZContext.new
26
26
  end
27
27
 
28
28
  class << self
@@ -54,6 +54,7 @@ module ZMachine
54
54
  @timers.put(deadline, [signature])
55
55
  end
56
56
 
57
+ ZMachine.logger.debug("zmachine:#{__method__}", signature: signature) if ZMachine.debug
57
58
  @timer_callbacks[signature] = callback
58
59
  signature
59
60
  end
@@ -62,11 +63,13 @@ module ZMachine
62
63
  if timer_or_sig.respond_to?(:cancel)
63
64
  timer_or_sig.cancel
64
65
  else
66
+ ZMachine.logger.debug("zmachine:#{__method__}", signature: timer_or_sig) if ZMachine.debug
65
67
  @timer_callbacks[timer_or_sig] = false if @timer_callbacks.has_key?(timer_or_sig)
66
68
  end
67
69
  end
68
70
 
69
71
  def connect(server, port_or_type=nil, handler=nil, *args, &block)
72
+ ZMachine.logger.debug("zmachine:#{__method__}", server: server, port_or_type: port_or_type) if ZMachine.debug
70
73
  if server.nil? or server =~ %r{\w+://}
71
74
  _connect_zmq(server, port_or_type, handler, *args, &block)
72
75
  else
@@ -88,6 +91,8 @@ module ZMachine
88
91
  end
89
92
 
90
93
  def run(callback=nil, shutdown_hook=nil, &block)
94
+ ZMachine.logger.debug("zmachine:#{__method__}") if ZMachine.debug
95
+
91
96
  @callback = callback || block
92
97
 
93
98
  add_shutdown_hook(shutdown_hook) if shutdown_hook
@@ -101,6 +106,7 @@ module ZMachine
101
106
  @run_reactor = true
102
107
 
103
108
  while @run_reactor
109
+ ZMachine.logger.debug("zmachine:#{__method__}", run_reactor: true) if ZMachine.debug
104
110
  run_deferred_callbacks
105
111
  break unless @run_reactor
106
112
  run_timers
@@ -111,13 +117,17 @@ module ZMachine
111
117
  process_io
112
118
  end
113
119
  ensure
120
+ ZMachine.logger.debug("zmachine:#{__method__}", stop: :selector) if ZMachine.debug
114
121
  @selector.close rescue nil
115
122
  @selector = nil
123
+ ZMachine.logger.debug("zmachine:#{__method__}", stop: :channels) if ZMachine.debug
116
124
  @unbound_channels += @channels
117
125
  remove_unbound_channels
126
+ ZMachine.logger.debug("zmachine:#{__method__}", stop: :shutdown_hooks) if ZMachine.debug
118
127
  @shutdown_hooks.pop.call until @shutdown_hooks.empty?
119
128
  @next_tick_queue = ConcurrentLinkedQueue.new
120
129
  @running = false
130
+ ZMachine.logger.debug("zmachine:#{__method__}", stop: :zcontext) if ZMachine.debug
121
131
  ZMachine.context.destroy
122
132
  end
123
133
  end
@@ -127,6 +137,7 @@ module ZMachine
127
137
  end
128
138
 
129
139
  def start_server(server, port_or_type=nil, handler=nil, *args, &block)
140
+ ZMachine.logger.debug("zmachine:#{__method__}", server: server, port_or_type: port_or_type) if ZMachine.debug
130
141
  if server =~ %r{\w+://}
131
142
  _bind_zmq(server, port_or_type, handler, *args, &block)
132
143
  else
@@ -192,6 +203,8 @@ module ZMachine
192
203
  timeout = -1
193
204
  end
194
205
 
206
+ ZMachine.logger.debug("zmachine:#{__method__}", timeout: timeout) if ZMachine.debug
207
+
195
208
  if timeout == -1
196
209
  @selector.select_now
197
210
  else
@@ -223,6 +236,7 @@ module ZMachine
223
236
  end
224
237
 
225
238
  def is_acceptable(channel)
239
+ ZMachine.logger.debug("zmachine:#{__method__}", channel: channel) if ZMachine.debug
226
240
  client_channel = channel.accept(next_signature)
227
241
  acceptor = channel.handler
228
242
  add_channel(client_channel, acceptor.klass, *acceptor.args, &acceptor.callback)
@@ -231,6 +245,7 @@ module ZMachine
231
245
  end
232
246
 
233
247
  def is_readable(channel)
248
+ ZMachine.logger.debug("zmachine:#{__method__}", channel: channel) if ZMachine.debug
234
249
  data = channel.read_inbound_data(@read_buffer)
235
250
  channel.handler.receive_data(data) if data
236
251
  rescue IOException
@@ -238,12 +253,14 @@ module ZMachine
238
253
  end
239
254
 
240
255
  def is_writable(channel)
256
+ ZMachine.logger.debug("zmachine:#{__method__}", channel: channel) if ZMachine.debug
241
257
  @unbound_channels << channel unless channel.write_outbound_data
242
258
  rescue IOException
243
259
  @unbound_channels << channel
244
260
  end
245
261
 
246
262
  def is_connectable(channel)
263
+ ZMachine.logger.debug("zmachine:#{__method__}", channel: channel) if ZMachine.debug
247
264
  channel.finish_connecting
248
265
  channel.handler.connection_completed
249
266
  rescue IOException
@@ -251,6 +268,7 @@ module ZMachine
251
268
  end
252
269
 
253
270
  def add_channel(channel, klass, *args, &block)
271
+ ZMachine.logger.debug("zmachine:#{__method__}", channel: channel) if ZMachine.debug
254
272
  channel.handler = klass.new(channel, *args)
255
273
  @new_channels << channel
256
274
  block.call(channel.handler) if block
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "zmachine"
5
- spec.version = "0.1.0"
5
+ spec.version = "0.1.1"
6
6
  spec.authors = ["madvertise Mobile Advertising GmbH"]
7
7
  spec.email = ["tech@madvertise.com"]
8
8
  spec.description = %q{pure JRuby multi-threaded EventMachine compatible event loop}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-27 00:00:00.000000000 Z
12
+ date: 2013-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -79,19 +79,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
82
  version: '0'
85
- hash: 2
86
83
  none: false
87
84
  required_rubygems_version: !ruby/object:Gem::Requirement
88
85
  requirements:
89
86
  - - '>='
90
87
  - !ruby/object:Gem::Version
91
- segments:
92
- - 0
93
88
  version: '0'
94
- hash: 2
95
89
  none: false
96
90
  requirements: []
97
91
  rubyforge_project:
@@ -100,3 +94,4 @@ signing_key:
100
94
  specification_version: 3
101
95
  summary: pure JRuby multi-threaded EventMachine compatible event loop
102
96
  test_files: []
97
+ has_rdoc: