Class: Baykit::BayServer::Tours::SendFileYacht

Inherits:
WaterCraft::Yacht show all
Includes:
Agent, Util
Defined in:
lib/baykit/bayserver/tours/send_file_yacht.rb

Constant Summary

Constants inherited from WaterCraft::Yacht

WaterCraft::Yacht::INVALID_YACHT_ID, WaterCraft::Yacht::YACHT_ID_NOCHECK

Instance Attribute Summary collapse

Attributes inherited from WaterCraft::Yacht

#object_id, #yacht_id

Instance Method Summary collapse

Methods inherited from WaterCraft::Yacht

#init_yacht

Methods included from Agent::Transporter::DataListener

#notify_connect, #notify_handshake_done, #notify_protocol_error

Constructor Details

#initializeSendFileYacht

Returns a new instance of SendFileYacht.



21
22
23
24
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 21

def initialize
  super
  reset()
end

Instance Attribute Details

#file_lenObject (readonly)

Returns the value of attribute file_len.



18
19
20
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 18

def file_len
  @file_len
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



17
18
19
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 17

def file_name
  @file_name
end

#file_wrote_lenObject (readonly)

Returns the value of attribute file_wrote_len.



19
20
21
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 19

def file_wrote_len
  @file_wrote_len
end

#tourObject (readonly)

Returns the value of attribute tour.



14
15
16
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 14

def tour
  @tour
end

#tour_idObject (readonly)

Returns the value of attribute tour_id.



15
16
17
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 15

def tour_id
  @tour_id
end

Instance Method Details

#check_timeout(duration) ⇒ Object



72
73
74
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 72

def check_timeout(duration)
  BayLog.trace("Check timeout: %s", @file_name)
end

#init(tur, file_name, tp) ⇒ Object

Custom methods



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 80

def init(tur, file_name, tp)
  init_yacht()
  @tour = tur
  @tour_id = tur.id()
  @file_name = file_name
  @file_len = File.size(file_name)
  #file = File.open(file_name, "rb")
  tur.res.set_consume_listener do |len, resume|
    if resume
      tp.open_valve();
    end
  end
end

#notify_closeObject



68
69
70
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 68

def notify_close()
  BayLog.trace("File closed: %s", @file_name)
end

#notify_eofObject



58
59
60
61
62
63
64
65
66
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 58

def notify_eof()
  BayLog.trace("%s EOF(^o^) %s", self, @file_name)
  begin
    @tour.res.end_content(@tour_id)
  rescue IOError => e
    BayLog.debug_e(e)
  end
  return NextSocketAction::CLOSE
end

#notify_read(buf, adr) ⇒ Object

implements Yacht



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 45

def notify_read(buf, adr)
  @file_wrote_len += buf.length
  BayLog.trace("%s read file %d bytes: total=%d/%d", self, buf.length, @file_wrote_len, @file_len)
  available = @tour.res.send_content(@tour_id, buf, 0, buf.length)

  if available
    return NextSocketAction::CONTINUE;
  else
    return NextSocketAction::SUSPEND;
  end

end

#resetObject

implements Reusable



34
35
36
37
38
39
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 34

def reset()
  @file_wrote_len = 0
  @file_len = 0
  @tour = nil
  @tour_id = 0
end

#to_sObject



26
27
28
# File 'lib/baykit/bayserver/tours/send_file_yacht.rb', line 26

def to_s()
  return "filyt##{@yacht_id}/#{@object_id} tour=#{@tour} id=#{@tour_id}";
end