Class: Iyyov::ShutdownHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/iyyov/shutdown_handler.rb

Constant Summary collapse

Thread =
Java::java.lang.Thread
Runtime =
Java::java.lang.Runtime

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#handlerObject (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

#runObject



41
42
43
# File 'lib/iyyov/shutdown_handler.rb', line 41

def run
  @block.call
end

#unregisterObject



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