Class MachineService

java.lang.Object
de.bytestore.hostinger.process.service.MachineService

@Service @Component public class MachineService extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    attach(Machine machineIO, ProcessConsole consoleIO)
    Attaches a Machine object to a ProcessConsole object by executing the attach method on all registered MachineExtensionPoint instances that match the provider of the Machine object.
    config(Machine machinesIO)
     
    config(String providerIO)
    Retrieves the MachineExtensionConfig for the given providerIO.
    int
    Retrieves the count of Machine objects from the database.
    logs(Machine machinesIO)
    Returns the log entry for the given Machine object by executing the log method of the registered extensions of the MachineExtensionPoint interface that match the provider of the Machine object.
    void
    onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event)
     
    void
    This method registers the cached event types for machines usage.
    void
    restart(Machine machinesIO)
    Restarts the given Machine object.
    void
    start(Machine machinesIO)
    Starts processing for the provided machine using extensions from the machine service.
    stats(Machine machinesIO)
    Executes the stats action for the given Machine object and returns the ProcessStats result.
    status(Machine machinesIO)
    Retrieves the status of the given Machine object.
    void
    stop(Machine machinesIO)
    Stops the machine.
    vnc(Machine machineIO)
    Retrieves the VNC socket for the given Machine object.
    void
    This method registers event types for the MachineService class with the WebhookHandler.
    void
    wol(Machine machinesIO)
    Wakes up the specified machine by calling the "wol" method on all registered MachineExtensionPoint instances that match the provider of the given Machine object.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MachineService

      public MachineService()
  • Method Details

    • onApplicationStarted

      @EventListener public void onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event)
    • webhooks

      public void webhooks()
      This method registers event types for the MachineService class with the WebhookHandler. The event types include "machine.restart", "machine.stop", and "machine.wol".
    • stats

      public ProcessStats stats(Machine machinesIO) throws RuntimeException
      Executes the stats action for the given Machine object and returns the ProcessStats result.
      Parameters:
      machinesIO - the Machine object for which the stats action needs to be executed
      Returns:
      the ProcessStats object containing the statistics data (cpu, memory, swap, disk, download, upload)
      Throws:
      RuntimeException - if there is an error getting the machine stats
    • vnc

      public VNCSocket vnc(Machine machineIO)
      Retrieves the VNC socket for the given Machine object.
      Parameters:
      machineIO - the Machine object for which the VNC socket needs to be retrieved
      Returns:
      the VNCSocket object representing the VNC socket configuration
    • config

      public MachineExtensionConfig config(String providerIO)
      Retrieves the MachineExtensionConfig for the given providerIO.
      Parameters:
      providerIO - the provider name for which the MachineExtensionConfig needs to be retrieved
      Returns:
      the MachineExtensionConfig object representing the configuration for the given provider
      Throws:
      Exception - if there is an error during the config retrieval process
    • config

      public MachineExtensionConfig config(Machine machinesIO)
    • status

      public ProcessStatus status(Machine machinesIO)
      Retrieves the status of the given Machine object.
      Parameters:
      machinesIO - the Machine object for which the status needs to be retrieved
      Returns:
      The ProcessStatus representing the current status of the Machine object. Returns ProcessStatus.NOT_FOUND if there is an error retrieving the status or if the status is not found.
      Throws:
      Exception - if there is an error retrieving the status
    • restart

      public void restart(Machine machinesIO)
      Restarts the given Machine object.
      Parameters:
      machinesIO - the Machine object that needs to be restarted
    • stop

      public void stop(Machine machinesIO)
      Stops the machine.
    • wol

      public void wol(Machine machinesIO)
      Wakes up the specified machine by calling the "wol" method on all registered MachineExtensionPoint instances that match the provider of the given Machine object.
      Parameters:
      machinesIO - the Machine object representing the machine to wake up
      Throws:
      Exception - if there is an error during the wake-on-LAN process
    • logs

      public String logs(Machine machinesIO)
      Returns the log entry for the given Machine object by executing the log method of the registered extensions of the MachineExtensionPoint interface that match the provider of the Machine object.
      Parameters:
      machinesIO - the Machine object for which the log entry needs to be retrieved
      Returns:
      the log entry as a String
      Throws:
      Exception - if there is an error during the log retrieval process
    • count

      public int count()
      Retrieves the count of Machine objects from the database.
      Returns:
      the count of Machine objects as an Integer
    • registerCached

      public void registerCached()
      This method registers the cached event types for machines usage. It calculates the average memory, CPU, and disk usage of all machines and registers them as Webhook events. The method uses the systemService to store the calculated values for future use.
    • attach

      public void attach(Machine machineIO, ProcessConsole consoleIO)
      Attaches a Machine object to a ProcessConsole object by executing the attach method on all registered MachineExtensionPoint instances that match the provider of the Machine object.
      Parameters:
      machineIO - the Machine object to attach
      consoleIO - the ProcessConsole object to attach
      Throws:
      Exception - if there is an error during the attach process
    • start

      public void start(Machine machinesIO)
      Starts processing for the provided machine using extensions from the machine service.
      Parameters:
      machinesIO - the machine instance for which the process needs to be started