Class: Baykit::BayServer::Docker::SendFile::WaitFileShip

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

Constant Summary

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 inherited from Common::ReadOnlyShip

#notify_connect, #notify_handshake_done, #notify_protocol_error

Methods inherited from Ships::Ship

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

Constructor Details

#initializeWaitFileShip

Returns a new instance of WaitFileShip.



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

def initialize()
  @file_content = nil
  @handler = nil
end

Instance Attribute Details

#file_contentObject (readonly)

Returns the value of attribute file_content.



13
14
15
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 13

def file_content
  @file_content
end

#handlerObject (readonly)

Returns the value of attribute handler.



14
15
16
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 14

def handler
  @handler
end

#tourObject (readonly)

Returns the value of attribute tour.



16
17
18
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 16

def tour
  @tour
end

#tour_idObject (readonly)

Returns the value of attribute tour_id.



17
18
19
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 17

def tour_id
  @tour_id
end

Instance Method Details

#check_timeout(duration_sec) ⇒ Object



84
85
86
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 84

def check_timeout(duration_sec)
  return false
end

#init(rd, tp, tur, file_content, handler) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 23

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

#notify_closeObject



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

def notify_close
end

#notify_eofObject

Raises:



77
78
79
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 77

def notify_eof()
  raise Sink.new
end

#notify_error(e) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 68

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

#notify_read(buf) ⇒ Object

Implements ReadOnlyShip



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 50

def notify_read(buf)

  BayLog.debug("%s file read completed", self)

  begin
    @handler.send_file_from_cache
  rescue HttpException => e
    begin
      @tour.res.send_error(Tour::TOUR_ID_NOCHECK, e.status, e.message)
      rescue IOError => ex
        notify_error(ex)
        return NextSocketAction::CLOSE
    end
  end

  return NextSocketAction::CONTINUE
end

#resetObject

Implements Reusable



39
40
41
42
43
44
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 39

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

#to_sObject



31
32
33
# File 'lib/baykit/bayserver/docker/send_file/wait_file_ship.rb', line 31

def to_s
  return "agt#" + @agent_id.to_s + " wait_file#" + @ship_id.to_s + "/" + @object_id.to_s
end