Class: Baykit::BayServer::Docker::SendFile::FileContent

Inherits:
Object
  • Object
show all
Includes:
Rudders, Util
Defined in:
lib/baykit/bayserver/docker/send_file/file_content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, length) ⇒ FileContent

Returns a new instance of FileContent.



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

def initialize(path, length)
  @path = path
  @content = ""
  @content_length = length
  @bytes_loaded = 0
  @loaded_time = Time.now.to_i
  @waiters = []
  @lock = Mutex.new
end

Instance Attribute Details

#bytes_loadedObject

Returns the value of attribute bytes_loaded.



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

def bytes_loaded
  @bytes_loaded
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#content_lengthObject (readonly)

Returns the value of attribute content_length.



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

def content_length
  @content_length
end

#loaded_timeObject (readonly)

Returns the value of attribute loaded_time.



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

def loaded_time
  @loaded_time
end

#lockObject (readonly)

Returns the value of attribute lock.



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

def lock
  @lock
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#waitersObject (readonly)

Returns the value of attribute waiters.



15
16
17
# File 'lib/baykit/bayserver/docker/send_file/file_content.rb', line 15

def waiters
  @waiters
end

Instance Method Details

#add_waiter(waiter) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/baykit/bayserver/docker/send_file/file_content.rb', line 36

def add_waiter(waiter)
  @lock.synchronize do
    if is_loaded
      wakeup_waiter(waiter)
    else
      waiters << waiter
    end
  end
end

#completeObject



46
47
48
49
50
51
52
53
# File 'lib/baykit/bayserver/docker/send_file/file_content.rb', line 46

def complete()
  @lock.synchronize do
    @waiters.each do |waiter|
      wakeup_waiter(waiter)
    end
    waiters.clear
  end
end

#is_loadedObject



32
33
34
# File 'lib/baykit/bayserver/docker/send_file/file_content.rb', line 32

def is_loaded()
  return @bytes_loaded == @content_length
end

#wakeup_waiter(waiter) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/baykit/bayserver/docker/send_file/file_content.rb', line 55

def wakeup_waiter(waiter)
  begin
    waiter.write(" ")
  rescue IOError => e
    BayLog.error_e(e, "Write error: %s", e)
  end
end