Module: ZMachine

Defined in:
lib/zmachine/deferrable.rb,
lib/zmachine.rb,
lib/zmachine/timers.rb,
lib/zmachine/channel.rb,
lib/zmachine/reactor.rb,
lib/zmachine/connection.rb,
lib/zmachine/tcp_channel.rb,
lib/zmachine/zmq_channel.rb,
lib/zmachine/hashed_wheel.rb,
lib/zmachine/connection_manager.rb

Overview

Author

Francis Cianfrocca (gmail: blackhedd)

Homepage

rubyeventmachine.com

Date

16 Jul 2006

See ZMachine and ZMachine::Connection for documentation and usage examples.


Copyright © 2006-07 by Francis Cianfrocca. All Rights Reserved. Gmail: blackhedd

This program is free software; you can redistribute it and/or modify it under the terms of either: 1) the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version; or 2) Ruby’s License.

See the file COPYING for complete licensing information.


Defined Under Namespace

Modules: Deferrable Classes: Channel, Connection, ConnectionError, ConnectionManager, DefaultDeferrable, NoReactorError, NotReactorOwner, PeriodicTimer, Reactor, TCPChannel, Timer, ZMQChannel

Constant Summary collapse

HashedWheel =
Java::ComLiquidmZmachine::HashedWheel

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.debugObject

Returns the value of attribute debug.



13
14
15
# File 'lib/zmachine.rb', line 13

def debug
  @debug
end

.loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/zmachine.rb', line 12

def logger
  @logger
end

Class Method Details

.add_periodic_timer(*args, &block) ⇒ Object



29
30
31
32
33
# File 'lib/zmachine.rb', line 29

def self.add_periodic_timer(*args, &block)
  interval = args.shift
  callback = args.shift || block
  PeriodicTimer.new(interval, callback)
end

.add_shutdown_hook(&block) ⇒ Object



35
36
37
# File 'lib/zmachine.rb', line 35

def self.add_shutdown_hook(&block)
  reactor.add_shutdown_hook(&block)
end

.add_timer(*args, &block) ⇒ Object



39
40
41
# File 'lib/zmachine.rb', line 39

def self.add_timer(*args, &block)
  reactor.add_timer(*args, &block)
end

.cancel_timer(timer_or_sig) ⇒ Object



43
44
45
# File 'lib/zmachine.rb', line 43

def self.cancel_timer(timer_or_sig)
  timer_or_sig.cancel # we do not support signatures
end

.close_connection(connection, after_writing = false, reason = nil) ⇒ Object



47
48
49
# File 'lib/zmachine.rb', line 47

def self.close_connection(connection, after_writing = false, reason = nil)
  reactor.close_connection(connection, after_writing, reason)
end

.connect(server, port_or_type = nil, handler = nil, *args, &block) ⇒ Object



51
52
53
# File 'lib/zmachine.rb', line 51

def self.connect(server, port_or_type=nil, handler=nil, *args, &block)
  reactor.connect(server, port_or_type, handler, *args, &block)
end

.connection_countObject



55
56
57
# File 'lib/zmachine.rb', line 55

def self.connection_count
  reactor.connections.size
end

.contextObject

for backwards compat. please use ZContext.instance directly.



25
26
27
# File 'lib/zmachine.rb', line 25

def self.context
  ZContext.instance
end

.heartbeat_intervalObject



59
60
61
# File 'lib/zmachine.rb', line 59

def self.heartbeat_interval
  @heartbeat_interval
end

.heartbeat_interval=(time) ⇒ Object



63
64
65
# File 'lib/zmachine.rb', line 63

def self.heartbeat_interval=(time)
  @heartbeat_interval = time
end

.next_tick(callback = nil, &block) ⇒ Object



67
68
69
# File 'lib/zmachine.rb', line 67

def self.next_tick(callback=nil, &block)
  reactor.next_tick(callback, &block)
end

.reactorObject



20
21
22
# File 'lib/zmachine.rb', line 20

def self.reactor
  Thread.current[:reactor] ||= Reactor.new
end

.reactor=(value) ⇒ Object



16
17
18
# File 'lib/zmachine.rb', line 16

def self.reactor=(value)
  Thread.current[:reactor] = value
end

.reactor_running?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/zmachine.rb', line 71

def self.reactor_running?
  reactor.running?
end

.reconnect(server, port, handler) ⇒ Object



75
76
77
# File 'lib/zmachine.rb', line 75

def self.reconnect(server, port, handler)
  reactor.reconnect(server, port, handler)
end

.run(callback = nil, shutdown_hook = nil, &block) ⇒ Object



79
80
81
# File 'lib/zmachine.rb', line 79

def self.run(callback=nil, shutdown_hook=nil, &block)
  reactor.run(callback, shutdown_hook, &block)
end

.run_block(&block) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/zmachine.rb', line 83

def self.run_block(&block)
  pr = proc {
    block.call
    ZMachine::stop_event_loop
  }
  run(&pr)
end

.start_server(server, port_or_type = nil, handler = nil, *args, &block) ⇒ Object



91
92
93
# File 'lib/zmachine.rb', line 91

def self.start_server(server, port_or_type=nil, handler=nil, *args, &block)
  reactor.bind(server, port_or_type, handler, *args, &block)
end

.stopObject



103
104
105
# File 'lib/zmachine.rb', line 103

def self.stop
  Reactor.terminate_all_reactors
end

.stop_event_loopObject



95
96
97
# File 'lib/zmachine.rb', line 95

def self.stop_event_loop
  reactor.stop_event_loop
end

.stop_server(signature) ⇒ Object



99
100
101
# File 'lib/zmachine.rb', line 99

def self.stop_server(signature)
  reactor.stop_server(signature)
end