Class: Asciidoctor::Diagram::Java::CommandServer

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor-diagram/util/java_socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(java, classpath) ⇒ CommandServer

Returns a new instance of CommandServer.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/asciidoctor-diagram/util/java_socket.rb', line 14

def initialize(java, classpath)
  args = []
  args << '-Djava.awt.headless=true'
  args << '-cp'
  args << classpath.flatten.map { |jar| ::Asciidoctor::Diagram::Platform.host_os_path(jar).strip }.join(::Asciidoctor::Diagram::Platform.host_os_path_separator)
  args << 'org.asciidoctor.diagram.CommandServer'

  @server = IO.popen([java, *args])
  @port = @server.readline.strip.to_i
  @client = TCPSocket.new 'localhost', port
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



12
13
14
# File 'lib/asciidoctor-diagram/util/java_socket.rb', line 12

def port
  @port
end

Instance Method Details

#ioObject



26
27
28
# File 'lib/asciidoctor-diagram/util/java_socket.rb', line 26

def io
  @client
end

#shutdownObject



30
31
32
33
# File 'lib/asciidoctor-diagram/util/java_socket.rb', line 30

def shutdown
  # KILL is a bit heavy handed, but TERM does not seem to shut down the JVM on Windows.
  Process.kill('KILL', @server.pid)
end