Class: Baykit::BayServer::Tours::ReadFileTaxi

Inherits:
Baykit::BayServer::Taxi::Taxi show all
Includes:
Agent, Baykit::BayServer::Taxi, Util, Util::Valve
Defined in:
lib/baykit/bayserver/tours/read_file_taxi.rb

Instance Attribute Summary collapse

Attributes inherited from Baykit::BayServer::Taxi::Taxi

#taxi_id

Instance Method Summary collapse

Methods inherited from Baykit::BayServer::Taxi::Taxi

#run

Constructor Details

#initialize(buf_size) ⇒ ReadFileTaxi

Returns a new instance of ReadFileTaxi.



27
28
29
30
31
32
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 27

def initialize(buf_size)
  super()
  @buf_size = buf_size
  @buf = StringUtil.alloc(buf_size)
  @lock = Monitor.new()
end

Instance Attribute Details

#bufObject (readonly)

Returns the value of attribute buf.



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

def buf
  @buf
end

#buf_sizeObject (readonly)

Returns the value of attribute buf_size.



23
24
25
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 23

def buf_size
  @buf_size
end

#ch_validObject (readonly)

Returns the value of attribute ch_valid.



20
21
22
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 20

def ch_valid
  @ch_valid
end

#data_listenerObject (readonly)

Returns the value of attribute data_listener.



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

def data_listener
  @data_listener
end

#infileObject (readonly)

Returns the value of attribute infile.



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

def infile
  @infile
end

#lockObject (readonly)

Returns the value of attribute lock.



25
26
27
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 25

def lock
  @lock
end

#runningObject (readonly)

Returns the value of attribute running.



24
25
26
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 24

def running
  @running
end

Instance Method Details

#closeObject



94
95
96
97
98
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 94

def close()
  @ch_valid = false
  @infile.close()
  @data_listener.notify_close()
end

#departObject

implements Taxi



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 58

def depart()
  @lock.synchronize do
    begin
      @buf.clear()
      @infile.read(@buf_size, @buf)

      if @buf.length == 0
        @data_listener.notify_eof()
        close()
        return
      end

      act = @data_listener.notify_read(@buf, nil)

      @running = false
      if act == NextSocketAction::CONTINUE
        next_run()
      end

    rescue Exception => e
      BayLog.error_e(e)
      close()
    end
  end
end

#init(infile, data_listener) ⇒ Object



38
39
40
41
42
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 38

def init(infile, data_listener)
  @data_listener = data_listener
  @infile = infile
  @ch_valid = true
end

#next_runObject



85
86
87
88
89
90
91
92
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 85

def next_run()
  if @running
    # If running, not posted because next run exists
    return
  end
  @running = true
  TaxiRunner.post(self)
end

#open_valveObject

implements Valve



48
49
50
51
52
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 48

def open_valve()
  @lock.synchronize do
    next_run()
  end
end

#to_sObject



34
35
36
# File 'lib/baykit/bayserver/tours/read_file_taxi.rb', line 34

def to_s()
  return super.to_s() + " " + @data_listener.to_s()
end