Class: WebSocket::ShutdownHook

Inherits:
Object
  • Object
show all
Defined in:
lib/websocket/shutdown_hook.rb

Overview

The ShutdownHook class specifies a routine to be invoked when the java runtime is shutdown.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ ShutdownHook

Returns a new instance of ShutdownHook.



22
23
24
25
26
# File 'lib/websocket/shutdown_hook.rb', line 22

def initialize(server)
  super()
  @server = server
  java.lang.Runtime.runtime.add_shutdown_hook(self)
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



20
21
22
# File 'lib/websocket/shutdown_hook.rb', line 20

def server
  @server
end

Instance Method Details

#runObject



28
29
30
31
32
33
# File 'lib/websocket/shutdown_hook.rb', line 28

def run
  $stdout.write "\r\e[0K"
  $stdout.flush
  ::WebSocket::Server.log.info 'Shutting down'
  server.shutdown if server.respond_to?(:shutdown)
end