Class: VDDKFactory
- Inherits:
-
Object
- Object
- VDDKFactory
- Includes:
- DRb::DRbUndumped
- Defined in:
- lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb
Instance Attribute Summary collapse
-
#running ⇒ Object
Returns the value of attribute running.
-
#shutdown ⇒ Object
Returns the value of attribute shutdown.
Instance Method Summary collapse
- #connect(connect_parms) ⇒ Object
- #init ⇒ Object
-
#initialize ⇒ VDDKFactory
constructor
A new instance of VDDKFactory.
- #shut_down_drb ⇒ Object
- #shut_down_service(msg) ⇒ Object
-
#wait_for_status(status, secs_to_wait) ⇒ Object
Wait for the client to call our init function.
Constructor Details
#initialize ⇒ VDDKFactory
Returns a new instance of VDDKFactory.
23 24 25 26 27 |
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 23 def initialize @shutdown = nil @started = nil @running = nil end |
Instance Attribute Details
#running ⇒ Object
Returns the value of attribute running.
21 22 23 |
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 21 def running @running end |
#shutdown ⇒ Object
Returns the value of attribute shutdown.
20 21 22 |
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 20 def shutdown @shutdown end |
Instance Method Details
#connect(connect_parms) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 34 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 ⇒ Object
29 30 31 32 |
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 29 def init VdlWrapper.init @started = true end |
#shut_down_drb ⇒ Object
44 45 46 47 48 49 |
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 44 def shut_down_drb thr = DRb.thread DRb.stop_service thr.join unless thr.nil? $vim_log.info "Finished shutting down DRb" end |
#shut_down_service(msg) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 51 def shut_down_service(msg) $vim_log.info msg.to_s VdlWrapper.__exit__ if @started @running = true $vim_log.info "VdlWrapper.__exit__ finished" shut_down_drb end |
#wait_for_status(status, secs_to_wait) ⇒ Object
Wait for the client to call our init function. If it isn’t called within “max_secs_to_wait” seconds, shut down the service.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb', line 63 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 |