Class DomainCommandBuilder

  • All Implemented Interfaces:
    CommandBuilder

    public class DomainCommandBuilder
    extends JBossModulesCommandBuilder
    implements CommandBuilder
    Builds a list of commands used to launch a domain instance of WildFly.

    This builder is not thread safe and the same instance should not be used in multiple threads.

    The default Java home directory is used for the process controller and optionally for the host controller and the servers launched.

    Author:
    James R. Perkins
    • Method Detail

      • of

        public static DomainCommandBuilder of​(Path wildflyHome)
        Creates a command builder for a domain instance of WildFly.

        Uses the system property java.home to find the java executable required for the default Java home.

        Parameters:
        wildflyHome - the path to the WildFly home directory
        Returns:
        a new builder
      • of

        public static DomainCommandBuilder of​(String wildflyHome)
        Creates a command builder for a domain instance of WildFly.

        Uses the system property java.home to find the java executable required for the default Java home.

        Parameters:
        wildflyHome - the path to the WildFly home directory
        Returns:
        a new builder
      • of

        public static DomainCommandBuilder of​(String wildflyHome,
                                              String javaHome)
        Creates a command builder for a domain instance of WildFly.
        Parameters:
        wildflyHome - the path to the WildFly home directory
        javaHome - the path to the default Java home directory
        Returns:
        a new builder
      • of

        public static DomainCommandBuilder of​(Path wildflyHome,
                                              Path javaHome)
        Creates a command builder for a domain instance of WildFly.
        Parameters:
        wildflyHome - the path to the WildFly home directory
        javaHome - the path default to the Java home directory
        Returns:
        a new builder
      • setBackup

        public DomainCommandBuilder setBackup()
        Sets the option (--backup to keep a copy of the persistent domain configuration even if this host is not a domain controller.
        Returns:
        the builder
      • setCachedDomainController

        public DomainCommandBuilder setCachedDomainController()
        Sets the option (--cached-dc) to boot using a locally cached copy of the domain configuration.
        Returns:
        the builder
        See Also:
        setBackup()
      • setInterProcessHostControllerAddress

        public DomainCommandBuilder setInterProcessHostControllerAddress​(String address)
        Sets the address on which the host controller should listen for communication from the process controller (interprocess-hc-address). Ignores null values.
        Parameters:
        address - the address
        Returns:
        the builder
      • setInterProcessHostControllerPort

        public DomainCommandBuilder setInterProcessHostControllerPort​(String port)
        Sets the port on which the host controller should listen for communication from the process controller ( interprocess-hc-address). Ignores null values or values less than 0.
        Parameters:
        port - the port
        Returns:
        the builder
        Throws:
        NumberFormatException - if the port is not a valid integer
      • setInterProcessHostControllerPort

        public DomainCommandBuilder setInterProcessHostControllerPort​(int port)
        Sets the port on which the host controller should listen for communication from the process controller ( interprocess-hc-address). Ignores values less than 0.
        Parameters:
        port - the port
        Returns:
        the builder
      • setMasterAddressHint

        public DomainCommandBuilder setMasterAddressHint​(String address)
        Sets the system property jboss.domain.primary.address. In a default slave host configuration this is used to configure the address of the master host controller. Ignores null values.

        Note: This option only works if the standard system property has not been removed from the remote host. If the system property was removed the address provided has no effect.

        Parameters:
        address - the address
        Returns:
        the builder
      • setMasterPortHint

        public DomainCommandBuilder setMasterPortHint​(String port)
        Sets the system property jboss.domain.primary.port. In a default slave host configuration this is used to configure the port of the master host controller. Ignores null values or values less than 0.

        Note: This option only works if the standard system property has not been removed from the remote host. If the system property was removed the port provided has no effect.

        Parameters:
        port - the port
        Returns:
        the builder
        Throws:
        NumberFormatException - if the port is not a valid integer
      • setMasterPortHint

        public DomainCommandBuilder setMasterPortHint​(int port)
        Sets the system property jboss.domain.primary.port. In a default slave host configuration this is used to configure the port of the master host controller. Ignores values less than 0.

        Note: This option only works if the standard system property has not been removed from the remote host. If the system property was removed the port provided has no effect.

        Parameters:
        port - the port
        Returns:
        the builder
      • setProcessControllerAddress

        public DomainCommandBuilder setProcessControllerAddress​(String address)
        Sets the address on which the process controller listens for communication from processes it controls. Ignores null values.
        Parameters:
        address - the address
        Returns:
        the builder
      • setProcessControllerPort

        public DomainCommandBuilder setProcessControllerPort​(String port)
        Sets the port on which the process controller listens for communication from processes it controls. Ignores null values or values less than 0.
        Parameters:
        port - the port
        Returns:
        the builder
        Throws:
        NumberFormatException - if the port is not a valid integer
      • setProcessControllerPort

        public DomainCommandBuilder setProcessControllerPort​(int port)
        Sets the port on which the process controller listens for communication from processes it controls. Ignores values less than 0.
        Parameters:
        port - the port
        Returns:
        the builder
      • setBaseDirectory

        public DomainCommandBuilder setBaseDirectory​(String baseDir)
        Sets the base directory to use.

        The default is $JBOSS_HOME/standalone.

        Parameters:
        baseDir - the base directory or null to resolve the base directory
        Returns:
        the builder
      • setBaseDirectory

        public DomainCommandBuilder setBaseDirectory​(Path baseDir)
        Sets the base directory to use.

        The default is $JBOSS_HOME/standalone.

        Parameters:
        baseDir - the base directory or null to resolve the base directory
        Returns:
        the builder
      • setHostControllerJavaHome

        public DomainCommandBuilder setHostControllerJavaHome​(String javaHome)
        Sets the Java home for the host controller.

        If the javaHome is not null then the java executable will be resolved and used to launch the host processor. If the javaHome is null the same java executable will be used to launch the host controller that launched the process controller.

        Parameters:
        javaHome - the java home to set, can be null to use the default
        Returns:
        the builder
      • setHostControllerJavaHome

        public DomainCommandBuilder setHostControllerJavaHome​(Path javaHome)
        Sets the Java home for the host controller.

        If the javaHome is not null then the java executable will be resolved and used to launch the host processor. If the javaHome is null the same java executable will be used to launch the host controller that launched the process controller.

        Parameters:
        javaHome - the java home to set, can be null to use the default
        Returns:
        the builder
      • getHostControllerJavaHome

        public Path getHostControllerJavaHome()
        Returns the Java home path the host controller will use.
        Returns:
        the path to the Java home for the host controller
      • setHostConfiguration

        public DomainCommandBuilder setHostConfiguration​(String configFile)
        Sets the configuration file for the host controller (host.xml). The file must be in the configuration directory. A value of null is ignored.
        Parameters:
        configFile - the configuration file name
        Returns:
        the builder
      • getHostConfiguration

        public String getHostConfiguration()
        Returns the configuration file set or null if one was not set.
        Returns:
        the configuration file set or null if not set
      • setReadOnlyHostConfiguration

        public DomainCommandBuilder setReadOnlyHostConfiguration​(String configFile)
        Sets the read only configuration file for the host controller (host.xml). The file must be in the configuration directory. A value of null is ignored

        This will override any previous value set.

        Parameters:
        configFile - the configuration file name or null
        Returns:
        the builder
      • getReadOnlyHostConfiguration

        public String getReadOnlyHostConfiguration()
        Returns the configuration file setReadOnlyHostConfiguration(String) set} or null if one was not set.
        Returns:
        the configuration file set or null if not set
      • setDomainConfiguration

        public DomainCommandBuilder setDomainConfiguration​(String configFile)
        Sets the configuration file for the domain (domain.xml). The file must be in the configuration directory. A value of null is ignored.

        This will override any previous value set.

        Parameters:
        configFile - the configuration file name
        Returns:
        the builder
      • getDomainConfiguration

        public String getDomainConfiguration()
        Returns the configuration file set or null if one was not set.
        Returns:
        the configuration file set or null if not set
      • setReadOnlyDomainConfiguration

        public DomainCommandBuilder setReadOnlyDomainConfiguration​(String configFile)
        Sets the read only configuration file for the domain (domain.xml). The file must be in the configuration directory. A value of null is ignored

        This will override any previous value set.

        Parameters:
        configFile - the configuration file name or null
        Returns:
        the builder
      • getReadOnlyDomainConfiguration

        public String getReadOnlyDomainConfiguration()
        Returns the configuration file setReadOnlyDomainConfiguration(String) set} or null if one was not set.
        Returns:
        the configuration file set or null if not set
      • addHostControllerJavaOption

        public DomainCommandBuilder addHostControllerJavaOption​(String arg)
        Adds a JVM argument to the host controller ignoring null values.
        Parameters:
        arg - the argument to add
        Returns:
        the builder
      • addHostControllerJavaOptions

        public DomainCommandBuilder addHostControllerJavaOptions​(String... args)
        Adds a JVM arguments to the host controller ignoring null values.
        Parameters:
        args - the arguments to add
        Returns:
        the builder
      • addHostControllerJavaOptions

        public DomainCommandBuilder addHostControllerJavaOptions​(Iterable<String> args)
        Adds a JVM arguments to the host controller ignoring null values.
        Parameters:
        args - the arguments to add
        Returns:
        the builder
      • setHostControllerJavaOptions

        public DomainCommandBuilder setHostControllerJavaOptions​(String... args)
        Sets the JVM arguments for the host controller ignoring null values in the array.

        If the array is null the host controller JVM arguments are cleared and no new ones are added

        Parameters:
        args - the arguments to add
        Returns:
        the builder
      • setHostControllerJavaOptions

        public DomainCommandBuilder setHostControllerJavaOptions​(Iterable<String> args)
        Sets the JVM arguments for the host controller ignoring null values in the collection.

        If the collection is null the host controller JVM arguments are cleared and no new ones are added

        Parameters:
        args - the arguments to add
        Returns:
        the builder
      • getHostControllerJavaOptions

        public List<String> getHostControllerJavaOptions()
        Returns the JVM arguments for the host controller.
        Returns:
        the JVM arguments
      • addProcessControllerJavaOption

        public DomainCommandBuilder addProcessControllerJavaOption​(String arg)
        Adds a JVM argument to the process controller ignoring null values.
        Parameters:
        arg - the argument to add
        Returns:
        the builder
      • addProcessControllerJavaOptions

        public DomainCommandBuilder addProcessControllerJavaOptions​(String... args)
        Adds a JVM arguments to the process controller ignoring null values.
        Parameters:
        args - the arguments to add
        Returns:
        the builder
      • addProcessControllerJavaOptions

        public DomainCommandBuilder addProcessControllerJavaOptions​(Iterable<String> args)
        Adds a JVM arguments to the process controller ignoring null values.
        Parameters:
        args - the arguments to add
        Returns:
        the builder
      • setProcessControllerJavaOptions

        public DomainCommandBuilder setProcessControllerJavaOptions​(String... args)
        Sets the JVM arguments for the process controller ignoring null values in the array.

        If the array is null the process controller JVM arguments are cleared and no new ones are added

        Parameters:
        args - the arguments to add
        Returns:
        the builder
      • setProcessControllerJavaOptions

        public DomainCommandBuilder setProcessControllerJavaOptions​(Iterable<String> args)
        Sets the JVM arguments for the process controller ignoring null values in the collection.

        If the collection is null the process controller JVM arguments are cleared and no new ones are added

        Parameters:
        args - the arguments to add
        Returns:
        the builder
      • getProcessControllerJavaOptions

        public List<String> getProcessControllerJavaOptions()
        Returns the JVM arguments used for the process controller.
        Returns:
        the JVM arguments
      • setServerJavaHome

        public DomainCommandBuilder setServerJavaHome​(String javaHome)
        Sets the Java home for the servers that are launched in the domain.

        If the javaHome is not null then the java executable will be resolved and used to launch the servers in the domain. If the javaHome is null the same java executable will be used to launch the servers in the domain that launched the process controller.

        Parameters:
        javaHome - the java home to set, can be null to use the default
        Returns:
        the builder
      • setServerJavaHome

        public DomainCommandBuilder setServerJavaHome​(Path javaHome)
        Sets the Java home for the servers that are launched in the domain.

        If the javaHome is not null then the java executable will be resolved and used to launch the servers in the domain. If the javaHome is null the same java executable will be used to launch the servers in the domain that launched the process controller.

        Parameters:
        javaHome - the java home to set, can be null to use the default
        Returns:
        the builder
      • setStability

        public DomainCommandBuilder setStability​(String stability)
        Sets the stability level of the standalone server process.
        Parameters:
        stability - a stability level
        Returns:
        a reference to this builder
      • getServerJavaHome

        public Path getServerJavaHome()
        Returns the Java home path the servers will use.
        Returns:
        the path to the Java home for the servers
      • getJavaHome

        public Path getJavaHome()
        Returns the Java home directory where the java executable command can be found.

        If the directory was not set the system property value, java.home, should be used.

        Returns:
        the path to the Java home directory
      • getBaseDirectory

        public Path getBaseDirectory()
        Returns the base directory for the server.

        Example: For standalone the base directory would be $JBOSS_HOME/standalone.

        Returns:
        the base directory
      • getThis

        protected DomainCommandBuilder getThis()
        Returns the concrete builder.
        Returns:
        the concrete builder
      • setUseSecurityManager

        public T setUseSecurityManager​(boolean useSecMgr)
        Description copied from class: JBossModulesCommandBuilder
        Sets whether or not the security manager option, -secmgr, should be used.
        Overrides:
        setUseSecurityManager in class JBossModulesCommandBuilder
        Parameters:
        useSecMgr - true to use the a security manager, otherwise false
        Returns:
        the builder
      • setModuleDirs

        public T setModuleDirs​(Iterable<String> moduleDirs)
        Description copied from class: JBossModulesCommandBuilder
        Replaces any previously set module directories with the collection of module directories.

        The default module directory will NOT be used if this method is invoked.

        Overrides:
        setModuleDirs in class JBossModulesCommandBuilder
        Parameters:
        moduleDirs - the collection of module directories to use
        Returns:
        the builder
      • setModuleDirs

        public T setModuleDirs​(String... moduleDirs)
        Description copied from class: JBossModulesCommandBuilder
        Replaces any previously set module directories with the array of module directories.

        The default module directory will NOT be used if this method is invoked.

        Overrides:
        setModuleDirs in class JBossModulesCommandBuilder
        Parameters:
        moduleDirs - the array of module directories to use
        Returns:
        the builder
      • getLogDirectory

        public Path getLogDirectory()
        Returns the log directory for the server.
        Returns:
        the log directory
      • setLogDirectory

        public T setLogDirectory​(String path)
        Sets the log directory to be used for log files.

        If set to null, the default, the log directory will be resolved.

        Parameters:
        path - the path to the log directory or null to have the log directory resolved
        Returns:
        the builder
        Throws:
        IllegalArgumentException - if the directory is not a valid directory
      • setLogDirectory

        public T setLogDirectory​(Path path)
        Sets the log directory to be used for log files.

        If set to null, the default, the log directory will be resolved.

        Parameters:
        path - the path to the log directory or null to have the log directory resolved
        Returns:
        the builder
        Throws:
        IllegalArgumentException - if the directory is not a valid directory
      • getConfigurationDirectory

        public Path getConfigurationDirectory()
        Returns the configuration directory for the server.
        Returns:
        the configuration directory
      • setConfigurationDirectory

        public T setConfigurationDirectory​(String path)
        Sets the configuration directory to be used for configuration files.

        If set to null, the default, the configuration directory will be resolved.

        Parameters:
        path - the path to the configuration directory or null to have the configuration directory resolved
        Returns:
        the builder
        Throws:
        IllegalArgumentException - if the directory is not a valid directory
      • setConfigurationDirectory

        public T setConfigurationDirectory​(Path path)
        Sets the configuration directory to be used for configuration files.

        If set to null, the default, the configuration directory will be resolved.

        Parameters:
        path - the path to the configuration directory or null to have the configuration directory resolved
        Returns:
        the builder
        Throws:
        IllegalArgumentException - if the directory is not a valid directory
      • setAdminOnly

        public T setAdminOnly()
        Sets the server argument --admin-only.
        Returns:
        the builder
      • setStartSuspended

        public T setStartSuspended()
        Sets the server argument --start-mode=suspend.
        Returns:
        the builder
      • setBindAddressHint

        public T setBindAddressHint​(String address)
        Sets the system property jboss.bind.address to the address given.

        This will override any previous value set via JBossModulesCommandBuilder.addServerArgument(String).

        Note: This option only works if the standard system property has not been removed from the interface. If the system property was removed the address provided has no effect.

        Parameters:
        address - the address to set the bind address to
        Returns:
        the builder
      • setBindAddressHint

        public T setBindAddressHint​(String interfaceName,
                                    String address)
        Sets the system property jboss.bind.address.$INTERFACE to the address given where $INTERFACE is the interfaceName parameter. For example in the default configuration passing management for the interfaceName parameter would result in the system property jboss.bind.address.management being set to the address provided.

        This will override any previous value set via JBossModulesCommandBuilder.addServerArgument(String).

        Note: This option only works if the standard system property has not been removed from the interface. If the system property was removed the address provided has no effect.

        Parameters:
        interfaceName - the name of the interface of the binding address
        address - the address to bind the management interface to
        Returns:
        the builder
      • setMulticastAddressHint

        public T setMulticastAddressHint​(String address)
        Sets the system property jboss.default.multicast.address to the address given.

        This will override any previous value set via JBossModulesCommandBuilder.addServerArgument(String).

        Note: This option only works if the standard system property has not been removed from the interface. If the system property was removed the address provided has no effect.

        Parameters:
        address - the address to set the multicast system property to
        Returns:
        the builder
      • addPropertiesFile

        public T addPropertiesFile​(String file)
        Adds a properties file to be passed to the server. Note that the file must exist.
        Parameters:
        file - the file to add
        Returns:
        the builder
        Throws:
        IllegalArgumentException - if the file does not exist or is not a regular file
      • addPropertiesFile

        public T addPropertiesFile​(Path file)
        Adds a properties file to be passed to the server. Note that the file must exist.
        Parameters:
        file - the file to add
        Returns:
        the builder
        Throws:
        IllegalArgumentException - if the file does not exist or is not a regular file
      • setPropertiesFile

        public T setPropertiesFile​(String file)
        Sets the properties file to use for the server or null to remove the file. Note that the file must exist.

        This will override any previous values set.

        Parameters:
        file - the properties file to use or null
        Returns:
        the builder
        Throws:
        IllegalArgumentException - if the file does not exist or is not a regular file
      • setPropertiesFile

        public T setPropertiesFile​(Path file)
        Sets the properties file to use for the server or null to remove the file. Note that the file must exist.

        This will override any previous values set.

        Parameters:
        file - the properties file to use or null
        Returns:
        the builder
        Throws:
        IllegalArgumentException - if the file does not exist or is not a regular file
      • getLoggingPropertiesArgument

        protected String getLoggingPropertiesArgument​(String fileName)
        Returns the command line argument that specifies the logging configuration.
        Parameters:
        fileName - the name of the configuration file
        Returns:
        the command line argument
      • getBootLogArgument

        protected String getBootLogArgument​(String fileName)
        Returns the command line argument that specifies the path the log file that should be used.

        This is generally only used on the initial boot of the server in standalone. The server will rewrite the configuration file with hard-coded values.

        Parameters:
        fileName - the name of the file
        Returns:
        the command line argument
      • normalizePath

        protected Path normalizePath​(String path)
        Resolves the path to the path relative to the WildFly home directory.
        Parameters:
        path - the name of the relative path
        Returns:
        the normalized path
      • normalizePath

        protected Path normalizePath​(Path parent,
                                     String path)
        Resolves the path relative to the parent and normalizes it.
        Parameters:
        parent - the parent path
        path - the path
        Returns:
        the normalized path
      • addSystemPropertyArg

        protected static void addSystemPropertyArg​(List<String> cmd,
                                                   String key,
                                                   Object value)