Class: Baykit::BayServer::Docker::SendFile::SendFileShip

Inherits:
Common::ReadOnlyShip show all
Includes:
Agent, Agent::Multiplexer, Rudders, Tours, Tours::ReqContentHandler
Defined in:
lib/baykit/bayserver/docker/send_file/send_file_ship.rb

Constant Summary

Constants included from Tours::ReqContentHandler

Tours::ReqContentHandler::DEV_NULL

Constants inherited from Ships::Ship

Ships::Ship::INVALID_SHIP_ID, Ships::Ship::SHIP_ID_NOCHECK

Instance Attribute Summary collapse

Attributes inherited from Ships::Ship

#agent_id, #initialized, #keeping, #object_id, #rudder, #ship_id, #transporter

Instance Method Summary collapse

Methods included from Tours::ReqContentHandler

#on_abort_req, #on_end_req_content, #on_read_req_content

Methods inherited from Common::ReadOnlyShip

#notify_connect, #notify_handshake_done, #notify_protocol_error

Methods inherited from Ships::Ship

#check_ship_id, #id, #initialize, #notify_connect, #notify_handshake_done, #notify_protocol_error, #post_close, #resume_read

Constructor Details

This class inherits a constructor from Baykit::BayServer::Ships::Ship

Instance Attribute Details

#abortableObject (readonly)

Returns the value of attribute abortable.



20
21
22
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 20

def abortable
  @abortable
end

#file_wrote_lenObject (readonly)

Returns the value of attribute file_wrote_len.



10
11
12
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 10

def file_wrote_len
  @file_wrote_len
end

#pathObject (readonly)

Returns the value of attribute path.



19
20
21
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 19

def path
  @path
end

#tourObject (readonly)

Returns the value of attribute tour.



11
12
13
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 11

def tour
  @tour
end

#tour_idObject (readonly)

Returns the value of attribute tour_id.



12
13
14
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 12

def tour_id
  @tour_id
end

Instance Method Details

#check_timeout(duration_sec) ⇒ Object



85
86
87
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 85

def check_timeout(duration_sec)
  return false
end

#init(rd, tp, tur) ⇒ Object



22
23
24
25
26
27
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 22

def init(rd, tp, tur)
  super(tur.ship.agent_id, rd, tp)
  @file_wrote_len = 0
  @tour = tur
  @tour_id = tur.tour_id
end

#notify_closeObject



81
82
83
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 81

def notify_close
  BayLog.debug("%s Close", self)
end

#notify_eofObject



71
72
73
74
75
76
77
78
79
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 71

def notify_eof
  BayLog.debug("%s EOF", self)
  begin
    @tour.res.end_res_content(@tour_id)
  rescue IOError => e
    BayLog.debug_e(ex)
  end
  return NextSocketAction::CLOSE
end

#notify_error(e) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 62

def notify_error(e)
  BayLog.debug_e(e, "%s Error notified", self)
  begin
    @tour.res.send_error(@tour_id, HttpStatus::INTERNAL_SERVER_ERROR, nil, e)
  rescue IOError => ex
    BayLog.debug_e(ex)
  end
end

#notify_read(buf) ⇒ Object

Implements ReqContentHandler



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 44

def notify_read(buf)
  @file_wrote_len += buf.length
  BayLog.debug("%s read file %d bytes: total=%d", self, buf.length, @file_wrote_len)

  begin
    available = @tour.res.send_res_content(@tour_id, buf, 0, buf.length)

    if available
      return NextSocketAction::CONTINUE
    else
      return NextSocketAction::SUSPEND
    end
  rescue IOError => e
    notify_error(e)
    return NextSocketAction::CLOSE
  end
end

#resetObject

Implements Reusable



33
34
35
36
37
38
# File 'lib/baykit/bayserver/docker/send_file/send_file_ship.rb', line 33

def reset
  super
  @file_wrote_len = 0
  @tour_id = 0
  @tour = nil
end