Class: Iyyov::ShutdownHandler
- Inherits:
-
Object
- Object
- Iyyov::ShutdownHandler
- Defined in:
- lib/iyyov/shutdown_handler.rb
Constant Summary collapse
- Thread =
Java::java.lang.Thread
- Runtime =
Java::java.lang.Runtime
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
Instance Method Summary collapse
-
#initialize(&block) ⇒ ShutdownHandler
constructor
A new instance of ShutdownHandler.
- #run ⇒ Object
- #unregister ⇒ Object
Constructor Details
#initialize(&block) ⇒ ShutdownHandler
Returns a new instance of ShutdownHandler.
29 30 31 32 33 |
# File 'lib/iyyov/shutdown_handler.rb', line 29 def initialize( &block ) @block = block @handler = Thread.new( self ) Runtime::runtime.add_shutdown_hook( @handler ) end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
27 28 29 |
# File 'lib/iyyov/shutdown_handler.rb', line 27 def handler @handler end |
Instance Method Details
#run ⇒ Object
41 42 43 |
# File 'lib/iyyov/shutdown_handler.rb', line 41 def run @block.call end |
#unregister ⇒ Object
35 36 37 38 39 |
# File 'lib/iyyov/shutdown_handler.rb', line 35 def unregister Runtime::runtime.remove_shutdown_hook( @handler ) @handler = nil @block = nil end |