Class: Baykit::BayServer::Common::WarpData

Inherits:
Object
  • Object
show all
Includes:
Agent, Tours::ReqContentHandler, Util
Defined in:
lib/baykit/bayserver/common/warp_data.rb

Constant Summary

Constants included from Tours::ReqContentHandler

Tours::ReqContentHandler::DEV_NULL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(warp_ship, warp_id) ⇒ WarpData

Returns a new instance of WarpData.



20
21
22
23
24
25
26
27
28
# File 'lib/baykit/bayserver/common/warp_data.rb', line 20

def initialize(warp_ship, warp_id)
  @warp_ship = warp_ship
  @warp_ship_id = warp_ship.id()
  @warp_id = warp_id
  @req_headers = Headers.new
  @res_headers = Headers.new
  @started = false
  @ended = false
end

Instance Attribute Details

#endedObject (readonly)

Returns the value of attribute ended.



18
19
20
# File 'lib/baykit/bayserver/common/warp_data.rb', line 18

def ended
  @ended
end

#req_headersObject (readonly)

Returns the value of attribute req_headers.



15
16
17
# File 'lib/baykit/bayserver/common/warp_data.rb', line 15

def req_headers
  @req_headers
end

#res_headersObject (readonly)

Returns the value of attribute res_headers.



16
17
18
# File 'lib/baykit/bayserver/common/warp_data.rb', line 16

def res_headers
  @res_headers
end

#startedObject (readonly)

Returns the value of attribute started.



17
18
19
# File 'lib/baykit/bayserver/common/warp_data.rb', line 17

def started
  @started
end

#warp_idObject (readonly)

Returns the value of attribute warp_id.



14
15
16
# File 'lib/baykit/bayserver/common/warp_data.rb', line 14

def warp_id
  @warp_id
end

#warp_shipObject (readonly)

Returns the value of attribute warp_ship.



12
13
14
# File 'lib/baykit/bayserver/common/warp_data.rb', line 12

def warp_ship
  @warp_ship
end

#warp_ship_idObject (readonly)

Returns the value of attribute warp_ship_id.



13
14
15
# File 'lib/baykit/bayserver/common/warp_data.rb', line 13

def warp_ship_id
  @warp_ship_id
end

Class Method Details

.get(tur) ⇒ Object



94
95
96
# File 'lib/baykit/bayserver/common/warp_data.rb', line 94

def self.get(tur)
  return tur.req.content_handler
end

Instance Method Details

#on_abort_req(tur) ⇒ Object



71
72
73
74
75
76
# File 'lib/baykit/bayserver/common/warp_data.rb', line 71

def on_abort_req(tur)
  BayLog.debug("%s on req abort tur=%s", @warp_ship, tur)
  @warp_ship.check_ship_id(@warp_ship_id)
  @warp_ship.abort(@warp_ship_id)
  return false # not aborted immediately
end

#on_end_req_content(tur) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/baykit/bayserver/common/warp_data.rb', line 62

def on_end_req_content(tur)
  BayLog.debug("%s End req content tur=%s", @warp_ship, tur)
  @warp_ship.check_ship_id(@warp_ship_id)
  @warp_ship.warp_handler.send_end_tour(tur, false) do
    agt = GrandAgent.get(@warp_ship.agent_id)
    agt.net_multiplexer.req_read(@warp_ship.rudder)
  end
end

#on_read_req_content(tur, buf, start, len, &lis) ⇒ Object

Implements ReqContentHandler



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/baykit/bayserver/common/warp_data.rb', line 33

def on_read_req_content(tur, buf, start, len, &lis)
  BayLog.debug("%s Read req content tur=%s len=%d", @warp_ship, tur, len);
  @warp_ship.check_ship_id(@warp_ship_id)
  max_len = @warp_ship.protocol_handler.max_req_packet_data_size()
  pos = 0
  while pos < len
    post_len = len - pos
    if post_len > max_len
      post_len = max_len
    end

    tur_id = tur.id()

    if !@started
      # The buffer will become corrupted due to reuse.
      buf = buf.dup()
    end

    @warp_ship.warp_handler.send_res_content(
      tur,
      buf,
      start + pos,
      post_len) do
        tur.req.consumed(tur_id, len, &lis)
      end
    pos += max_len
  end
end

#startObject

Other methods



82
83
84
85
86
87
88
# File 'lib/baykit/bayserver/common/warp_data.rb', line 82

def start
  if !@started
    BayLog.debug("%s Start Warp tour", self)
    @warp_ship.flush()
    @started = true
  end
end

#to_sObject



90
91
92
# File 'lib/baykit/bayserver/common/warp_data.rb', line 90

def to_s
  return "#{@warp_ship} wtur##{@warp_id}"
end