class DRbFileServer

Attributes

nodes[RW]

Public Class Methods

new(nodes, sps: nil, topic: 'file') click to toggle source
# File lib/drb_fileserver_plus.rb, line 16
def initialize(nodes, sps: nil, topic: 'file')
  
  @nodes = nodes
  @failcount = 0
  @sps, @topic = sps, topic
  
end

Public Instance Methods

cp(path, path2) click to toggle source
# File lib/drb_fileserver_plus.rb, line 24
def cp(path, path2)
     
  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first      
    f.cp File.join(node, path), File.join(node, path2)
  end
  
  if @sps then
    @sps.notice "%s/copy: %s %s" % [@topic, File.join(node, path), 
                             File.join(node, path2)]
  end

end
directory?(fname) click to toggle source
# File lib/drb_fileserver_plus.rb, line 40
def directory?(fname)
      
  file_op do |f| 
    node = 'dfs://' + @nodes.first
    f.directory? File.join(node, fname) 
  end

end
exists?(fname) click to toggle source
# File lib/drb_fileserver_plus.rb, line 49
def exists?(fname)
      
  file_op do |f| 
    node = 'dfs://' + @nodes.first
    f.exists? File.join(node, fname) 
  end

end
ls(path) click to toggle source
# File lib/drb_fileserver_plus.rb, line 58
def ls(path)
  
  file_op do |f| 
    node = 'dfs://' + @nodes.first
    f.ls File.join(node, path)
  end

end
mkdir(path) click to toggle source
# File lib/drb_fileserver_plus.rb, line 67
def mkdir(path)

  node = ''
  
  file_op do |f| 
    node = 'dfs://' + @nodes.first
    f.mkdir File.join(node, path)
  end
  
  if @sps then
    @sps.notice "%s/mkdir: %s" % [@topic, File.join(node, path)]    
  end

end
mkdir_p(path) click to toggle source
# File lib/drb_fileserver_plus.rb, line 82
def mkdir_p(path)

  node = ''    

  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.mkdir_p File.join(node, path)
  end
  
  if @sps then
    @sps.notice "%s/mkdir_p: %s" % [@topic, File.join(node, path)]
  end
  
end
mv(path, path2) click to toggle source
# File lib/drb_fileserver_plus.rb, line 97
def mv(path, path2)

  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.mv File.join(node, path), File.join(node, path2)
  end
  
  if @sps then
    @sps.notice "%s/mv: %s %s" % [@topic, File.join(node, path), 
                             File.join(node, path2)]
  end

end
read(fname) click to toggle source
# File lib/drb_fileserver_plus.rb, line 113
def read(fname)
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.read File.join(node, fname)
  end

end
rm(fname) click to toggle source
# File lib/drb_fileserver_plus.rb, line 122
def rm(fname)

  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.rm File.join(node, fname)
  end
  
  if @sps then
    @sps.notice "%s/rm: %s" % [@topic, File.join(node, fname)]
  end

end
write(fname, content) click to toggle source
# File lib/drb_fileserver_plus.rb, line 137
def write(fname, content)

  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.write File.join(node, fname), content
  end
  
  if @sps then
    @sps.notice("%s/write: %s" % [@topic, File.join(node, fname)])
  end
  
end
zip(fname, a) click to toggle source
# File lib/drb_fileserver_plus.rb, line 152
def zip(fname, a)
  
  node = ''
  
  file_op do |f|
    node = 'dfs://' + @nodes.first
    f.zip File.join(node, fname), a
  end
  
  if @sps then
    @sps.notice "%s/zip: %s" % [@topic, File.join(node, fname)]
  end
  
end

Private Instance Methods

file_op() { |DfsFile| ... } click to toggle source
# File lib/drb_fileserver_plus.rb, line 170
def file_op()

  begin
    r = yield(DfsFile)
    @failcount = 0
    r
  rescue
    raise $! if ($!).inspect =~ /No such file or directory/
    puts 'warning: ' + ($!).inspect
    @nodes.rotate!
    @failcount += 1
    retry unless @failcount > @nodes.length
    raise 'DRbFileServerPlus nodes exhausted2'
  end

end