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, HashedWheel, HashedWheelTimeout, NoReactorError, NotReactorOwner, PeriodicTimer, Reactor, TCPChannel, Timer, ZMQChannel

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.debugObject

Returns the value of attribute debug.



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

def debug
  @debug
end

.loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

Class Method Details

.add_periodic_timer(*args, &block) ⇒ Object



31
32
33
34
35
# File 'lib/zmachine.rb', line 31

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

.add_shutdown_hook(&block) ⇒ Object



37
38
39
# File 'lib/zmachine.rb', line 37

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

.add_timer(*args, &block) ⇒ Object



41
42
43
# File 'lib/zmachine.rb', line 41

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

.cancel_timer(timer_or_sig) ⇒ Object



45
46
47
# File 'lib/zmachine.rb', line 45

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

.clear_current_reactorObject



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

def self.clear_current_reactor
  Thread.current[:reactor] = nil
end

.close_connection(connection, reason = nil) ⇒ Object



49
50
51
# File 'lib/zmachine.rb', line 49

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

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



53
54
55
# File 'lib/zmachine.rb', line 53

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

.connection_countObject



57
58
59
# File 'lib/zmachine.rb', line 57

def self.connection_count
  reactor.connections.size
end

.contextObject



27
28
29
# File 'lib/zmachine.rb', line 27

def self.context
  Thread.current[:context] ||= ZContext.new
end

.heartbeat_intervalObject



61
62
63
# File 'lib/zmachine.rb', line 61

def self.heartbeat_interval
  reactor.heartbeat_interval
end

.heartbeat_interval=(time) ⇒ Object



65
66
67
# File 'lib/zmachine.rb', line 65

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

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



69
70
71
# File 'lib/zmachine.rb', line 69

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

.reactorObject



23
24
25
# File 'lib/zmachine.rb', line 23

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

.reactor_running?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/zmachine.rb', line 73

def self.reactor_running?
  reactor.running?
end

.reconnect(server, port, handler) ⇒ Object



77
78
79
# File 'lib/zmachine.rb', line 77

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

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



81
82
83
# File 'lib/zmachine.rb', line 81

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

.run_block(&block) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/zmachine.rb', line 85

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



93
94
95
# File 'lib/zmachine.rb', line 93

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

.stopObject



105
106
107
# File 'lib/zmachine.rb', line 105

def self.stop
  Reactor.terminate_all_reactors
end

.stop_event_loopObject



97
98
99
# File 'lib/zmachine.rb', line 97

def self.stop_event_loop
  reactor.stop_event_loop
end

.stop_server(signature) ⇒ Object



101
102
103
# File 'lib/zmachine.rb', line 101

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