Class: Kibosh::Session
- Inherits:
-
Object
show all
- Includes:
- Exceptions
- Defined in:
- lib/kibosh/session.rb,
lib/kibosh/session/stream.rb
Defined Under Namespace
Modules: NewSessionResponse
Classes: Stream, Streams, Version
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(request, response) ⇒ Session
Returns a new instance of Session.
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/kibosh/session.rb', line 100
def initialize request, response
@timer = nil
@timer_fires_at = nil
@responses = []
@bodies = []
client[:xml_lang] = request["xml:lang"]
client[:ver] = Version.new(request["ver"]) if request["ver"]
client[:wait] = Integer(request["wait"]) if request["wait"]
client[:hold] = Integer(request["hold"]) if request["hold"]
client[:from] = request["from"]
client[:ack] = Integer(request["ack"]) if request["ack"]
client[:content] = request["content"]
@sid = ('%16.16f' % rand)[2..-1]
@content = request["content"]
response.session = self
self.class.const_get(:Stream).new self,
request,
response.extend(NewSessionResponse) do |response|
yield response
end
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
12
13
14
|
# File 'lib/kibosh/session.rb', line 12
def content
@content
end
|
#sid ⇒ Object
Returns the value of attribute sid.
12
13
14
|
# File 'lib/kibosh/session.rb', line 12
def sid
@sid
end
|
Class Method Details
.find(request) ⇒ Object
14
15
16
|
# File 'lib/kibosh/session.rb', line 14
def self.find request
raise "hell"
end
|
Instance Method Details
#accept ⇒ Object
164
165
|
# File 'lib/kibosh/session.rb', line 164
def accept
end
|
#charsets ⇒ Object
171
172
|
# File 'lib/kibosh/session.rb', line 171
def charsets
end
|
#defer(response) ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/kibosh/session.rb', line 197
def defer response
raise "hell" if response.deliver_fired || response.deferred
if body = @bodies.shift
streams[body["stream"]].lock body
response.body = body
else
response.deferred = true
response.on_close do
response._cancel!
@responses.delete response
check_responses 0
end
@responses << response
check_responses 0
end
end
|
#handle(request, response) ⇒ Object
127
128
129
130
131
132
133
134
|
# File 'lib/kibosh/session.rb', line 127
def handle request, response
check_responses 1
if stream = streams[request]
stream.handle request, response
else
raise "hell: new stream"
end
end
|
#hold ⇒ Object
160
161
162
|
# File 'lib/kibosh/session.rb', line 160
def hold
@hold ||= client[:hold] ? client[:hold] : 1;
end
|
#inactivity ⇒ Object
152
153
154
|
# File 'lib/kibosh/session.rb', line 152
def inactivity
@polling ||= 60
end
|
#maxpause ⇒ Object
167
168
169
|
# File 'lib/kibosh/session.rb', line 167
def maxpause
@maxpause ||= 60*5
end
|
#polling ⇒ Object
148
149
150
|
# File 'lib/kibosh/session.rb', line 148
def polling
@polling ||= 5
end
|
#requests ⇒ Object
156
157
158
|
# File 'lib/kibosh/session.rb', line 156
def requests
@requests ||= hold+1
end
|
#respond(body) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/kibosh/session.rb', line 178
def respond body
raise "hell" if !body
if response = @responses.shift
raise "hell" if !response.deferred || response.delivered
response.body = body
response._deliver
body = nil
else
raise "hell" if !body
@bodies << body unless @bodies.include? body
end
check_responses 0
body
end
|
#stop ⇒ Object
174
175
176
|
# File 'lib/kibosh/session.rb', line 174
def stop
streams.stop
end
|
#streams ⇒ Object
84
85
86
|
# File 'lib/kibosh/session.rb', line 84
def streams
@streams ||= Streams.new self
end
|
#ver ⇒ Object
141
142
143
144
145
146
|
# File 'lib/kibosh/session.rb', line 141
def ver
@ver ||= (!client[:ver] && Version.new("1.8") ||
client[:ver] < Version.new("1.8") ?
client[:ver] :
Version.new("1.8")).to_s
end
|
#wait ⇒ Object
136
137
138
139
|
# File 'lib/kibosh/session.rb', line 136
def wait
default = 60
@wait ||= !client[:wait] && default || [ client[:wait], default ].min
end
|