Class: S3FileCollection

Inherits:
Object show all
Defined in:
lib/openc3/utilities/s3_file_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeS3FileCollection

Returns a new instance of S3FileCollection.



88
89
90
91
# File 'lib/openc3/utilities/s3_file_cache.rb', line 88

def initialize
  @array = []
  @mutex = Mutex.new
end

Instance Method Details

#add(s3_path, size, priority) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/openc3/utilities/s3_file_cache.rb', line 93

def add(s3_path, size, priority)
  @mutex.synchronize do
    @array.each do |file|
      if file.s3_path == s3_path
        file.priority = priority if priority < file.priority
        @array.sort! {|a,b| a.priority <=> b.priority}
        return file
      end
    end
    file = S3File.new(s3_path, size, priority)
    @array << file
    @array.sort! {|a,b| a.priority <=> b.priority}
    return file
  end
end

#current_disk_usageObject



131
132
133
134
135
136
137
138
139
# File 'lib/openc3/utilities/s3_file_cache.rb', line 131

def current_disk_usage
  @mutex.synchronize do
    total_size = 0
    @array.each do |file|
      total_size += file.size if file.local_path
    end
    return total_size
  end
end

#get(local_path) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/openc3/utilities/s3_file_cache.rb', line 113

def get(local_path)
  @mutex.synchronize do
    @array.each do |file|
      return file if file.local_path == local_path
    end
  end
  return nil
end

#get_next_to_retrieveObject



122
123
124
125
126
127
128
129
# File 'lib/openc3/utilities/s3_file_cache.rb', line 122

def get_next_to_retrieve
  @mutex.synchronize do
    @array.each do |file|
      return file unless file.local_path
    end
  end
  return nil
end

#lengthObject



109
110
111
# File 'lib/openc3/utilities/s3_file_cache.rb', line 109

def length
  @array.length
end