Class ServiceTemplate

java.lang.Object
eu.cloudnetservice.driver.service.ServiceTemplate
All Implemented Interfaces:
Named, Cloneable, Comparable<ServiceTemplate>

public class ServiceTemplate extends Object implements Named, Comparable<ServiceTemplate>, Cloneable
A service template holds all files which can be copied onto a service. They are building the base structure of any dynamic service and can be included on them dynamically as well.
Since:
4.0
  • Field Details

    • LOCAL_STORAGE

      public static final String LOCAL_STORAGE
      The name of the local template storage.
      See Also:
    • prefix

      private final String prefix
    • name

      private final String name
    • storage

      private final String storage
    • priority

      private final int priority
    • alwaysCopyToStaticServices

      private final boolean alwaysCopyToStaticServices
  • Constructor Details

    • ServiceTemplate

      protected ServiceTemplate(@NonNull @NonNull String prefix, @NonNull @NonNull String name, @NonNull @NonNull String storage, int priority, boolean alwaysCopyToStaticServices)
      Constructs a new service template instance.
      Parameters:
      prefix - the prefix of the template.
      name - the actual name of the template.
      storage - the storage in which the template is stored.
      priority - the inclusion priority of the template.
      alwaysCopyToStaticServices - if the template should always get copied onto static services.
      Throws:
      NullPointerException - if one of the given parameters is null.
  • Method Details

    • builder

      @NonNull public static @NonNull ServiceTemplate.Builder builder()
      Constructs a new builder instance for a service template.
      Returns:
      a new service template builder.
    • builder

      Constructs a new builder for a service template which has all properties of the given template already set.

      When calling build directly after constructing a builder using this method, it will result in a service template which is equal but not the same as the given one.

      Parameters:
      template - the template to copy the properties of.
      Returns:
      a builder for a service template which has the properties of the given template already set.
      Throws:
      NullPointerException - if the given service template is null.
    • parse

      @Nullable public static @Nullable ServiceTemplate parse(@NonNull @NonNull String template)
      Parses a service template from the given input string if possible. The input template must be in the form
      1. storage:prefix/name
      2. prefix/name (in this case the storage of the template will be the local storage)

      Note: the returned service template only contains data actually given to the method, therefore the priority of the template will always be 0 and alwaysCopyToStaticServices false.

      Parameters:
      template - the input string to parse if possible.
      Returns:
      the parsed service template from the given input, null if parsing was not possible.
      Throws:
      NullPointerException - if the given input string is null.
    • name

      @NonNull public @NonNull String name()
      Get the unique name identifier of this object in the related scope.
      Specified by:
      name in interface Named
      Returns:
      the unique name identifier of this object in the related scope.
    • prefix

      @NonNull public @NonNull String prefix()
      Get the prefix of the template. The prefix is used to group templates together, for example for a service task.
      Returns:
      the prefix of the template.
    • storageName

      @NonNull public @NonNull String storageName()
      Get the name of the storage in which the template is located.
      Returns:
      the storage of the template.
    • priority

      public int priority()
      This priority is used to determine in which order the template should be loaded onto a service. For example a template with a priority of 10 (high priority) is installed after templates with a lower priority (for example 1). This can for example be used to control the order of file copies, for example when they potentially override each other.
      Returns:
      the priority of the template.
    • alwaysCopyToStaticServices

      public boolean alwaysCopyToStaticServices()
      Get if this template should always be copied onto static services. By default, a template is only copied onto a static service when it starts for the first time. Note that if enabled file from this template can override files which were created by the static service.
      Returns:
      true if this template should always be copied onto static services, false otherwise.
    • fullName

      @NonNull public @NonNull String fullName()
      Get the full name of the template without the storage prefix. If you need a name with storage, use toString instead.
      Returns:
      the full name of the template in the format: prefix/name.
    • toString

      @NonNull public @NonNull String toString()
      Overrides:
      toString in class Object
    • storage

      @NonNull public @NonNull TemplateStorage storage()
      Get the template storage in which this template is stored, throwing an exception if the template doesn't exist.
      Returns:
      the template storage in which this template is stored.
      Throws:
      NullPointerException - if the storage used in this template is unknown.
    • findStorage

      @Nullable public @Nullable TemplateStorage findStorage()
      Tries to find the storage in which this template is stored. This method returns null rather than throwing an exception if the storage doesn't exist.
      Returns:
      the template storage in which this template is stored, null if the template doesn't exist.
    • compareTo

      public @Range(from=-1L,to=1L) int compareTo(@NonNull @NonNull ServiceTemplate serviceTemplate)
      Specified by:
      compareTo in interface Comparable<ServiceTemplate>
    • clone

      public ServiceTemplate clone()
      Overrides:
      clone in class Object