Class MachineService
java.lang.Object
de.bytestore.hostinger.process.service.MachineService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidattach(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.Retrieves the MachineExtensionConfig for the given providerIO.intcount()Retrieves the count of Machine objects from the database.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.voidonApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) voidThis method registers the cached event types for machines usage.voidRestarts the given Machine object.voidStarts processing for the provided machine using extensions from the machine service.Executes the stats action for the given Machine object and returns the ProcessStats result.Retrieves the status of the given Machine object.voidStops the machine.Retrieves the VNC socket for the given Machine object.voidwebhooks()This method registers event types for the MachineService class with the WebhookHandler.voidWakes up the specified machine by calling the "wol" method on all registeredMachineExtensionPointinstances that match the provider of the givenMachineobject.
-
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
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
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
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
-
status
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
Restarts the given Machine object.- Parameters:
machinesIO- the Machine object that needs to be restarted
-
stop
Stops the machine. -
wol
Wakes up the specified machine by calling the "wol" method on all registeredMachineExtensionPointinstances that match the provider of the givenMachineobject. -
logs
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
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 attachconsoleIO- the ProcessConsole object to attach- Throws:
Exception- if there is an error during the attach process
-
start
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
-