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.



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

def initialize(java, classpath)
  args = []
  args << '-Djava.awt.headless=true'
  args << '-cp'
  args << classpath.flatten.join(File::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.



10
11
12
# File 'lib/asciidoctor-diagram/util/java_socket.rb', line 10

def port
  @port
end

Instance Method Details

#ioObject



24
25
26
# File 'lib/asciidoctor-diagram/util/java_socket.rb', line 24

def io
  @client
end

#shutdownObject



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

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