Class: Nervion::Stream

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/nervion/stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Stream

Returns a new instance of Stream.



10
11
12
13
# File 'lib/nervion/stream.rb', line 10

def initialize(*args)
  @request = args[0]
  @handler = args[1]
end

Instance Attribute Details

#http_errorObject (readonly)

Returns the value of attribute http_error.



8
9
10
# File 'lib/nervion/stream.rb', line 8

def http_error
  @http_error
end

Instance Method Details

#closeObject



47
48
49
50
# File 'lib/nervion/stream.rb', line 47

def close
  @close_stream = true
  close_connection
end

#close_requested?Boolean

Returns:

  • (Boolean)


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

def close_requested?
  @close_stream ||= false
end

#connection_completedObject



19
20
21
22
# File 'lib/nervion/stream.rb', line 19

def connection_completed
  start_tls
  send_data @request
end

#http_error_occurred?Boolean

Returns:

  • (Boolean)


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

def http_error_occurred?
  not http_error.nil?
end

#post_initObject



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

def post_init
  @scheduler = ReconnectionScheduler.new
end

#receive_data(data) ⇒ Object



24
25
26
27
28
# File 'lib/nervion/stream.rb', line 24

def receive_data(data)
  @handler << data
rescue HttpError => error
  @http_error = error
end

#retryObject



30
31
32
33
# File 'lib/nervion/stream.rb', line 30

def retry
  @http_error = nil
  reconnect @request.host, @request.port
end

#unbindObject



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

def unbind
  handle_closed_stream unless close_requested?
end