class VDDKFactory

Attributes

logger[R]
running[RW]
shutdown[RW]

Public Class Methods

new() click to toggle source
# File lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb, line 20
def initialize
  @shutdown = nil
  @started = nil
  @running = nil
  @logger  = Logger.new($stdout)
end

Public Instance Methods

connect(connect_parms) click to toggle source
# File lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb, line 32
def connect(connect_parms)
  load_error = FFI::VixDiskLib::API.load_error
  unless load_error.nil?
    @shutdown = true
    raise VixDiskLibError, load_error
  end
  @running = true
  VdlWrapper.connect(connect_parms)
end
init() click to toggle source
# File lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb, line 27
def init
  VdlWrapper.init
  @started = true
end
shut_down_drb() click to toggle source
# File lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb, line 42
def shut_down_drb
  thr = DRb.thread
  DRb.stop_service
  thr.join unless thr.nil?
  logger.info "Finished shutting down DRb"
end
shut_down_service(msg) click to toggle source
# File lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb, line 49
def shut_down_service(msg)
  logger.info msg.to_s
  VdlWrapper.__exit__ if @started
  @running = true
  logger.info "VdlWrapper.__exit__ finished"
  shut_down_drb
end
wait_for_status(status, secs_to_wait) click to toggle source

Wait for the client to call our init function. If it isn't called within “max_secs_to_wait” seconds, shut down the service.

# File lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb, line 61
def wait_for_status(status, secs_to_wait)
  start_time = Time.now
  sleep_secs = 2
  until (status == "started") ? @started : @running
    sleep sleep_secs
    #
    # Specifically check the shutdown flag in case we've been asked
    # to wait for a different flag.
    #
    break if @shutdown
    #
    # Check if we've waited the specified number of seconds.
    #
    current_time = Time.now
    if current_time - start_time > secs_to_wait
      elapsed = current_time - start_time
      msg = "ERROR: Maximum time for a call to VixDiskLib has been reached after #{elapsed} seconds."
      msg += "\nShutting down VixDiskLib Service"
      @shutdown = true
      shut_down_service(msg)
      raise VixDiskLibError, msg
    end
  end
end