Class ServiceId.Builder
java.lang.Object
eu.cloudnetservice.driver.service.ServiceId.Builder
- Enclosing class:
ServiceId
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallowedNodes(@NonNull Collection<String> allowedNodes) Sets the nodes which are allowed to pick up and manage services using the service id.build()Builds a new service id instance based on this builder.environment(@Nullable ServiceEnvironmentType environment) Sets the environment which should be used for services using the service id.environment(@NonNull String environmentName) Sets the name of the environment to use for services using the service id.modifyAllowedNodes(@NonNull Consumer<Collection<String>> modifier) Modifies the nodes which are allowed to pick up and manage services using the service id.nameSplitter(@NonNull String nameSplitter) Sets the name splitter to use between the task name of the service and the numeric id of the service when creating the display name of it.nodeUniqueId(@Nullable String nodeUniqueId) Sets the unique id of the node which is required to pick up and manage the service associated with the service id.Sets the name of the task to use for the service id.taskServiceId(int taskServiceId) Sets the numeric id of the service within the task.Sets the unique id (version 4) of the service id.
-
Field Details
-
uniqueId
-
taskName
-
taskServiceId
protected int taskServiceId -
nodeUniqueId
-
environmentName
-
nameSplitter
-
environment
-
allowedNodes
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
uniqueId
Sets the unique id (version 4) of the service id. If the given unique id is already taken by any other service running within the CloudNet cluster it gets replaced by a random unique id.- Parameters:
uniqueId- the unique id to use for the service.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given unique id is null.
-
taskName
Sets the name of the task to use for the service id. The name must conform to the naming pattern defined in the service info snapshot class.- Parameters:
taskName- the name of the task to use for the service id.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given task name is null.IllegalArgumentException- if the given task does not match the task naming pattern.
-
taskServiceId
Sets the numeric id of the service within the task. If the given unique id is already in use by any other service running within the cluster, the given id will be counted up until it reached the numeric limit or a free id was found.- Parameters:
taskServiceId- the base task id to use.- Returns:
- the same instance as used to call the method, for chaining.
-
nodeUniqueId
Sets the unique id of the node which is required to pick up and manage the service associated with the service id. If the given node is not available within the cluster, services associated with the service id will not get started at all.- Parameters:
nodeUniqueId- the unique id of the node which is required to pick up the node, null for no specific node.- Returns:
- the same instance as used to call the method, for chaining.
-
nameSplitter
Sets the name splitter to use between the task name of the service and the numeric id of the service when creating the display name of it. The given name splitter must conform to the naming pattern defined in the service task class.- Parameters:
nameSplitter- the name splitter to use for services using the created id.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given name splitter is null.IllegalArgumentException- if the given name splitter does not follow the naming pattern.
-
environment
Sets the name of the environment to use for services using the service id. The environment must be registered on the node which is picking up the service.- Parameters:
environmentName- the name of the environment which should be used for services.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given environment name is null.
-
environment
@NonNull public @NonNull ServiceId.Builder environment(@Nullable @Nullable ServiceEnvironmentType environment) Sets the environment which should be used for services using the service id. This method will set both, the name and resolved environment type. If null is given this method will not reset anything previously passed to it and silently ignore the setting.- Parameters:
environment- the environment to use for the service.- Returns:
- the same instance as used to call the method, for chaining.
-
allowedNodes
@NonNull public @NonNull ServiceId.Builder allowedNodes(@NonNull @NonNull Collection<String> allowedNodes) Sets the nodes which are allowed to pick up and manage services using the service id. If an empty collection is given all nodes are allowed to pick up the service. If no node of the given ones is available to pick up a service, creations will fail.This method will override all previously added nodes which are allowed to start the service. The given collection will be copied into the builder which means that further modification after the method call will not reflect into the builder and vice-versa.
- Parameters:
allowedNodes- the nodes which are allowed to pick up the service.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given node unique id collection is null.
-
modifyAllowedNodes
@NonNull public @NonNull ServiceId.Builder modifyAllowedNodes(@NonNull @NonNull Consumer<Collection<String>> modifier) Modifies the nodes which are allowed to pick up and manage services using the service id. If no node of the given ones is available to pick up a service, creations will fail.- Parameters:
modifier- the modifier to be applied to the already added allowed nodes of this builder.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given node unique id collection is null.
-
build
Builds a new service id instance based on this builder.- Returns:
- the created service id.
- Throws:
NullPointerException- if no task or environment was given.IllegalArgumentException- if the task id is invalid.
-