Class: DNS::Server::Dispatcher
- Inherits:
-
Object
- Object
- DNS::Server::Dispatcher
show all
- Defined in:
- lib/faildns/server/dispatcher.rb,
lib/faildns/server/dispatcher/event.rb,
lib/faildns/server/dispatcher/socket.rb,
lib/faildns/server/dispatcher/eventdispatcher.rb,
lib/faildns/server/dispatcher/connectiondispatcher.rb
Defined Under Namespace
Classes: ConnectionDispatcher, Event, EventDispatcher
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(server) ⇒ Dispatcher
Returns a new instance of Dispatcher.
30
31
32
33
34
35
36
37
38
|
# File 'lib/faildns/server/dispatcher.rb', line 30
def initialize (server)
@server = server
@connection = ConnectionDispatcher.new(self)
@event = EventDispatcher.new(self)
@intervals = {}
@timeouts = {}
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
28
29
30
|
# File 'lib/faildns/server/dispatcher.rb', line 28
def connection
@connection
end
|
#event ⇒ Object
Returns the value of attribute event.
28
29
30
|
# File 'lib/faildns/server/dispatcher.rb', line 28
def event
@event
end
|
#server ⇒ Object
Returns the value of attribute server.
28
29
30
|
# File 'lib/faildns/server/dispatcher.rb', line 28
def server
@server
end
|
Instance Method Details
#alias(*args) ⇒ Object
162
163
164
|
# File 'lib/faildns/server/dispatcher.rb', line 162
def alias (*args)
@event.alias(*args)
end
|
#clearInterval(interval) ⇒ Object
142
143
144
|
# File 'lib/faildns/server/dispatcher.rb', line 142
def clearInterval (interval)
@intervals.delete(interval[:fiber])
end
|
#clearTimeout(timeout) ⇒ Object
129
130
131
|
# File 'lib/faildns/server/dispatcher.rb', line 129
def clearTimeout (timeout)
@timeouts.delete(timeout[:fiber])
end
|
#connections ⇒ Object
146
147
148
|
# File 'lib/faildns/server/dispatcher.rb', line 146
def connections
@connection.connections
end
|
#disconnecting ⇒ Object
158
159
160
|
# File 'lib/faildns/server/dispatcher.rb', line 158
def disconnecting
@connection.disconnecting
end
|
#dispatch(*args) ⇒ Object
170
171
172
|
# File 'lib/faildns/server/dispatcher.rb', line 170
def dispatch (*args)
@event.dispatch(*args)
end
|
#execute(*args) ⇒ Object
174
175
176
|
# File 'lib/faildns/server/dispatcher.rb', line 174
def execute (*args)
@event.execute(*args)
end
|
150
151
152
|
# File 'lib/faildns/server/dispatcher.rb', line 150
def input
@connection.input
end
|
#loop ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/faildns/server/dispatcher.rb', line 70
def loop
while true
@defaults.each {|fiber|
begin
fiber.resume
rescue FiberError
DNS.debug 'Something went deeply wrong in the dispatcher, aborting.'
Process::exit 23
rescue Exception => e
DNS.debug e
end
}
@intervals.each {|fiber, meta|
begin
if !@intervals[fiber]
raise FiberError
end
if meta[:at] <= Time.now
fiber.resume
meta[:at] += meta[:offset]
end
rescue FiberError
clearInterval meta
rescue Exception => e
DNS.debug e
end
}
@timeouts.each {|fiber, meta|
begin
if !@timeouts[fiber]
raise FiberError
end
if meta[:at] <= Time.now
fiber.resume
clearTimeout meta
end
rescue FiberError
clearTimeout meta
rescue Exception => e
DNS.debug e
end
}
end
end
|
#output ⇒ Object
154
155
156
|
# File 'lib/faildns/server/dispatcher.rb', line 154
def output
@connection.output
end
|
#register(*args) ⇒ Object
166
167
168
|
# File 'lib/faildns/server/dispatcher.rb', line 166
def register (*args)
@event.register(*args)
end
|
#setInterval(fiber, time) ⇒ Object
133
134
135
136
137
138
139
140
|
# File 'lib/faildns/server/dispatcher.rb', line 133
def setInterval (fiber, time)
@intervals[fiber] = {
:fiber => fiber,
:offset => time,
:at => Time.now + time,
:on => Time.now,
}
end
|
#setTimeout(fiber, time) ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/faildns/server/dispatcher.rb', line 121
def setTimeout (fiber, time)
@timeouts[fiber] = {
:fiber => fiber,
:at => Time.now + time,
:on => Time.now,
}
end
|
#start ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/faildns/server/dispatcher.rb', line 40
def start
@connection.start
@started = true
@defaults = [Fiber.new {
while true
@connection.read
Fiber.yield
end
}]
self.loop
end
|
#stop ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/faildns/server/dispatcher.rb', line 56
def stop
if !@started
return
end
@started = false
@stopping = true
@event.finalize
@connection.finalize
@stopping = false
end
|