Class QemuConnector

java.lang.Object
org.jgrapes.core.internal.ComponentVertex
org.jgrapes.core.Component
org.jdrupes.vmoperator.runner.qemu.QemuConnector
All Implemented Interfaces:
Iterable<org.jgrapes.core.ComponentType>, org.jgrapes.core.Channel, org.jgrapes.core.ComponentType, org.jgrapes.core.Eligible, org.jgrapes.core.Manager
Direct Known Subclasses:
AgentConnector, QemuMonitor

public abstract class QemuConnector extends org.jgrapes.core.Component
A component that handles the communication with QEMU over a socket.

Derived classes should log the messages exchanged on the socket if the log level is set to fine.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.jgrapes.core.Channel

    org.jgrapes.core.Channel.Default
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final com.fasterxml.jackson.databind.ObjectMapper
     

    Fields inherited from class org.jgrapes.core.Component

    logger

    Fields inherited from interface org.jgrapes.core.Channel

    BROADCAST, SELF
  • Constructor Summary

    Constructors
    Constructor
    Description
    QemuConnector(org.jgrapes.core.Channel componentChannel)
    Instantiates a new QEMU connector.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onClientConnected(org.jgrapes.net.events.ClientConnected event, org.jgrapes.net.SocketIOChannel channel)
    Check if this is from opening the agent socket and if true, save the socket in the context and associate the channel with the context.
    void
    onClosed(org.jgrapes.io.events.Closed<?> event, org.jgrapes.net.SocketIOChannel channel)
    On closed.
    void
    onConnectError(org.jgrapes.io.events.ConnectError event)
    Called when a connection attempt fails.
    void
    onFileChanged(org.jgrapes.util.events.FileChanged event)
    Watch for the creation of the swtpm socket and start the qemu process if it has been created.
    void
    onInput(org.jgrapes.io.events.Input<?> event, org.jgrapes.net.SocketIOChannel channel)
    Handle data from the socket connection.
    void
    onStart(org.jgrapes.core.events.Start event)
    Note the runner’s event processor and delete the socket.
    protected abstract void
    Process agent input.
    protected Optional<org.jgrapes.net.SocketIOChannel>
    Return the QEMU channel if the connection has been established.
    protected org.jgrapes.core.EventPipeline
    rep()
    Return the runner’s event pipeline.
    protected boolean
    Send the given command to QEMU.
    protected void
    Called when the connector has been connected to the socket.
    protected Optional<Writer>
    Return the Writer for the connection if the connection has been established.

    Methods inherited from class org.jgrapes.core.Component

    channel, component, defaultCriterion, isEligibleFor, setName

    Methods inherited from class org.jgrapes.core.internal.ComponentVertex

    activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface org.jgrapes.core.Manager

    stream
  • Field Details

    • mapper

      protected static final com.fasterxml.jackson.databind.ObjectMapper mapper
  • Constructor Details

    • QemuConnector

      public QemuConnector(org.jgrapes.core.Channel componentChannel) throws IOException
      Instantiates a new QEMU connector.
      Parameters:
      componentChannel - the component channel
      Throws:
      IOException - Signals that an I/O exception has occurred.
  • Method Details

    • onStart

      @Handler public void onStart(org.jgrapes.core.events.Start event) throws IOException
      Note the runner’s event processor and delete the socket.
      Parameters:
      event - the event
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • rep

      protected org.jgrapes.core.EventPipeline rep()
      Return the runner’s event pipeline.
      Returns:
      the event pipeline
    • onFileChanged

      @Handler public void onFileChanged(org.jgrapes.util.events.FileChanged event)
      Watch for the creation of the swtpm socket and start the qemu process if it has been created.
      Parameters:
      event - the event
    • onClientConnected

      @Handler public void onClientConnected(org.jgrapes.net.events.ClientConnected event, org.jgrapes.net.SocketIOChannel channel)
      Check if this is from opening the agent socket and if true, save the socket in the context and associate the channel with the context.
      Parameters:
      event - the event
      channel - the channel
    • qemuChannel

      protected Optional<org.jgrapes.net.SocketIOChannel> qemuChannel()
      Return the QEMU channel if the connection has been established.
      Returns:
      the socket IO channel
    • writer

      protected Optional<Writer> writer()
      Return the Writer for the connection if the connection has been established.
      Returns:
      the optional
    • sendCommand

      protected boolean sendCommand(String command) throws IOException
      Send the given command to QEMU.

      A newline is appended to the command automatically.

      Parameters:
      command - the command
      Returns:
      true, if successful
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • socketConnected

      protected void socketConnected()
      Called when the connector has been connected to the socket.
    • onConnectError

      @Handler public void onConnectError(org.jgrapes.io.events.ConnectError event)
      Called when a connection attempt fails.
      Parameters:
      event - the event
    • onInput

      @Handler public void onInput(org.jgrapes.io.events.Input<?> event, org.jgrapes.net.SocketIOChannel channel)
      Handle data from the socket connection.
      Parameters:
      event - the event
      channel - the channel
    • processInput

      protected abstract void processInput(String line) throws IOException
      Process agent input.
      Parameters:
      line - the line
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • onClosed

      @Handler public void onClosed(org.jgrapes.io.events.Closed<?> event, org.jgrapes.net.SocketIOChannel channel)
      On closed.
      Parameters:
      event - the event
      channel - the channel