Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.wildfly.core.launcher;
 
 import java.util.List;
 
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(s):
James R. Perkins
 
 @SuppressWarnings("unused")
 
     private static final String DOMAIN_BASE_DIR = "jboss.domain.base.dir";
     private static final String DOMAIN_CONFIG_DIR = "jboss.domain.config.dir";
     private static final String DOMAIN_LOG_DIR = "jboss.domain.log.dir";
 
     private final Path javaHome;
     private Path hostControllerJavaHome;
     private Path serverJavaHome;
     private Path baseDir;
     private final Arguments hostControllerJavaOpts;
     private final Arguments processControllerJavaOpts;

    
Creates a new command builder for a domain instance of WildFly.

Note the wildflyHome and javaHome are not validated using the constructor. The static of(java.nio.file.Path) is preferred.

Parameters:
wildflyHome the WildFly home directory
javaHome the default Java home directory
 
     private DomainCommandBuilder(final Path wildflyHomefinal Path javaHome) {
         super(wildflyHome);
         this. = javaHome;
          = new Arguments();
          = new Arguments();
     }

    
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
 
     public static DomainCommandBuilder of(final Path wildflyHome) {
         return new DomainCommandBuilder(validateWildFlyDir(wildflyHome), validateJavaHome(System.getProperty("java.home")));
     }

    
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
 
     public static DomainCommandBuilder of(final String wildflyHome) {
         return new DomainCommandBuilder(validateWildFlyDir(wildflyHome), validateJavaHome(System.getProperty("java.home")));
     }

    
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
    public static DomainCommandBuilder of(final String wildflyHomefinal String javaHome) {
        return new DomainCommandBuilder(validateWildFlyDir(wildflyHome), validateJavaHome(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
    public static DomainCommandBuilder of(final Path wildflyHomefinal Path javaHome) {
        return new DomainCommandBuilder(validateWildFlyDir(wildflyHome), validateJavaHome(javaHome));
    }

    
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
    public DomainCommandBuilder setBackup() {
        addServerArgument("--backup");
        return this;
    }

    
Sets the option (--cached-dc) to boot using a locally cached copy of the domain configuration.

Returns:
the builder
See also:
setBackup()
        addServerArgument("--cached-dc");
        return this;
    }

    
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
        if (address != null) {
            addServerArg("--interprocess-hc-address"address);
        }
        return this;
    }

    
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:
java.lang.NumberFormatException if the port is not a valid integer
        if (port != null) {
            setInterProcessHostControllerPort(Integer.parseInt(port));
        }
        return this;
    }


    
Sets the port on which the host controller should listen for communication from the process controller (interprocess-hc-address). Ignores null values less than 0.

Parameters:
port the port
Returns:
the builder
    public DomainCommandBuilder setInterProcessHostControllerPort(final int port) {
        if (port > -1) {
            addServerArg("--interprocess-hc-port", Integer.toString(port));
        }
        return this;
    }

    
Sets the system property jboss.domain.master.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
    public DomainCommandBuilder setMasterAddressHint(final String address) {
        if (address != null) {
            addServerArg("--master-address"address);
        }
        return this;
    }

    
Sets the system property jboss.domain.master.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:
java.lang.NumberFormatException if the port is not a valid integer
    public DomainCommandBuilder setMasterPortHint(final String port) {
        if (port != null) {
            setMasterPortHint(Integer.parseInt(port));
        }
        return this;
    }

    
Sets the system property jboss.domain.master.port. In a default slave host configuration this is used to configure the port of the master host controller. Ignores null 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
    public DomainCommandBuilder setMasterPortHint(final int port) {
        if (port > -1) {
            addServerArg("--master-port", Integer.toString(port));
        }
        return this;
    }

    
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
    public DomainCommandBuilder setProcessControllerAddress(final String address) {
        if (address != null) {
            addServerArg("--pc-address"address);
        }
        return this;
    }

    
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:
java.lang.NumberFormatException if the port is not a valid integer
    public DomainCommandBuilder setProcessControllerPort(final String port) {
        if (port != null) {
            setProcessControllerPort(Integer.parseInt(port));
        }
        return this;
    }

    
Sets the port on which the process controller listens for communication from processes it controls. Ignores null values less than 0.

Parameters:
port the port
Returns:
the builder
    public DomainCommandBuilder setProcessControllerPort(final int port) {
        if (port > -1) {
            addServerArg("--pc-port", Integer.toString(port));
        }
        return this;
    }

    
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
    public DomainCommandBuilder setBaseDirectory(final String baseDir) {
        this. = validateAndNormalizeDir(baseDirtrue);
        return this;
    }

    
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
    public DomainCommandBuilder setBaseDirectory(final Path baseDir) {
        this. = validateAndNormalizeDir(baseDirtrue);
        return this;
    }

    
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
    public DomainCommandBuilder setHostControllerJavaHome(final String javaHome) {
        if (javaHome == null) {
            this. = null;
        } else {
            this. = validateJavaHome(javaHome);
        }
        return this;
    }

    
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
    public DomainCommandBuilder setHostControllerJavaHome(final Path javaHome) {
        if (javaHome == null) {
            this. = null;
        } else {
            this. = validateJavaHome(javaHome);
        }
        return this;
    }

    
Returns the Java home path the host controller will use.

If the path was not previously set the default Java home will be used.

Returns:
the path to the Java home for the host controller
    public Path getHostControllerJavaHome() {
        if ( == null) {
            return getJavaHome();
        }
        return ;
    }

    
Sets the configuration file for the host controller (host.xml). The file must be in the AbstractCommandBuilder.setConfigurationDirectory(java.lang.String) directory. A value of null is ignored.

Parameters:
configFile the configuration file name
Returns:
the builder
    public DomainCommandBuilder setHostConfiguration(final String configFile) {
        if (configFile != null) {
            addServerArg("--host-config"configFile);
        }
        return this;
    }

    
Returns the configuration file set or null if one was not set.

Returns:
the configuration file set or null if not set
    public String getHostConfiguration() {
        return getServerArg("--host-config");
    }

    
Sets the read only configuration file for the host controller (host.xml). The file must be in the AbstractCommandBuilder.setConfigurationDirectory(java.lang.String) 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
    public DomainCommandBuilder setReadOnlyHostConfiguration(final String configFile) {
        if (configFile != null) {
            addServerArg("--read-only-host-config"configFile);
        }
        return this;
    }


    
Returns the configuration file setReadOnlyHostConfiguration(java.lang.String) set} or null if one was not set.

Returns:
the configuration file set or null if not set
        return getServerArg("--read-only-host-config");
    }

    
Sets the configuration file for the domain (domain.xml). The file must be in the AbstractCommandBuilder.setConfigurationDirectory(java.lang.String) directory. A value of null is ignored.

This will override any previous value set.

Parameters:
configFile the configuration file name
Returns:
the builder
    public DomainCommandBuilder setDomainConfiguration(final String configFile) {
        addServerArg("-c"configFile);
        return this;
    }

    
Returns the configuration file set or null if one was not set.

Returns:
the configuration file set or null if not set
    public String getDomainConfiguration() {
        return getServerArg("-c");
    }

    
Sets the read only configuration file for the domain (domain.xml). The file must be in the AbstractCommandBuilder.setConfigurationDirectory(java.lang.String) 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
    public DomainCommandBuilder setReadOnlyDomainConfiguration(final String configFile) {
        if (configFile != null) {
            addServerArg("--read-only-domain-config"configFile);
        }
        return this;
    }


    
Returns the configuration file setReadOnlyDomainConfiguration(java.lang.String) set} or null if one was not set.

Returns:
the configuration file set or null if not set
        return getServerArg("--read-only-domain-config");
    }

    
Adds a JVM argument to the host controller ignoring null values.

Parameters:
arg the argument to add
Returns:
the builder
        if (arg != null && !arg.trim().isEmpty()) {
            final Argument argument = Arguments.parse(arg);
            if (argument.getKey().equals()) {
                if (argument.getValue() != null) {
                    setBaseDirectory(argument.getValue());
                }
            } else if (argument.getKey().equals()) {
                if (argument.getValue() != null) {
                    setConfigurationDirectory(argument.getValue());
                }
            } else if (argument.getKey().equals()) {
                if (argument.getValue() != null) {
                    setLogDirectory(argument.getValue());
                }
            } else {
                .add(argument);
            }
        }
        return this;
    }

    
Adds a JVM arguments to the host controller ignoring null values.

Parameters:
args the arguments to add
Returns:
the builder
    public DomainCommandBuilder addHostControllerJavaOptions(final String... args) {
        if (args != null) {
            for (String arg : args) {
                addHostControllerJavaOption(arg);
            }
        }
        return this;
    }

    
Adds a JVM arguments to the host controller ignoring null values.

Parameters:
args the arguments to add
Returns:
the builder
        if (args != null) {
            for (String arg : args) {
                addHostControllerJavaOption(arg);
            }
        }
        return this;
    }

    
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
    public DomainCommandBuilder setHostControllerJavaOptions(final String... args) {
        .clear();
        return addHostControllerJavaOptions(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
        .clear();
        return addHostControllerJavaOptions(args);
    }

    
Returns the JVM arguments for the host controller.

Returns:
the JVM arguments
        return .asList();
    }

    
Adds a JVM argument to the process controller ignoring null values.

Parameters:
arg the argument to add
Returns:
the builder
        if (arg != null && !arg.trim().isEmpty()) {
            final Argument argument = Arguments.parse(arg);
            if (argument.getKey().equals()) {
                setUseSecurityManager(true);
            } else {
                .add(argument);
            }
        }
        return this;
    }

    
Adds a JVM arguments to the process controller ignoring null values.

Parameters:
args the arguments to add
Returns:
the builder
        if (args != null) {
            for (String arg : args) {
                addProcessControllerJavaOption(arg);
            }
        }
        return this;
    }

    
Adds a JVM arguments to the process controller ignoring null values.

Parameters:
args the arguments to add
Returns:
the builder
        if (args != null) {
            for (String arg : args) {
                addProcessControllerJavaOption(arg);
            }
        }
        return this;
    }

    
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
        return addProcessControllerJavaOptions(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
        return addProcessControllerJavaOptions(args);
    }

    
Returns the JVM arguments used for the process controller.

Returns:
the JVM arguments
        return .asList();
    }


    
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
    public DomainCommandBuilder setServerJavaHome(final String javaHome) {
        if (javaHome == null) {
            this. = null;
        } else {
            this. = validateJavaHome(javaHome);
        }
        return this;
    }


    
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
    public DomainCommandBuilder setServerJavaHome(final Path javaHome) {
        if (javaHome == null) {
            this. = null;
        } else {
            this. = validateJavaHome(javaHome);
        }
        return this;
    }

    
Returns the Java home path the servers will use.

If the path was not previously set the default Java home will be used.

Returns:
the path to the Java home for the servers
    public Path getServerJavaHome() {
        if ( == null) {
            return getJavaHome();
        }
        return ;
    }
    @Override
    public List<StringbuildArguments() {
        final List<Stringcmd = new ArrayList<>();
        // Process Controller
        cmd.add("-D[Process Controller]");
        addSystemPropertyArg(cmdgetWildFlyHome());
        // PROCESS_CONTROLLER_JAVA_OPTS
        cmd.add(getSystemPackages());
        cmd.add(getBootLogArgument("process-controller.log"));
        cmd.add(getLoggingPropertiesArgument("logging.properties"));
        cmd.add("-jar");
        cmd.add(getModulesJarName());
        if (useSecurityManager()) {
            cmd.add();
        }
        cmd.add("-mp");
        cmd.add(getModulePaths());
        cmd.add("org.jboss.as.process-controller");
        cmd.add("-jboss-home");
        cmd.add(getWildFlyHome().toString());
        cmd.add("-jvm");
        cmd.add(getHostControllerJavaCommand());
        cmd.add("-mp");
        cmd.add(getModulePaths());
        // Host Controller
        cmd.add("--");
        cmd.add(getBootLogArgument("host-controller.log"));
        cmd.add(getLoggingPropertiesArgument("logging.properties"));
        // HOST_CONTROLLER_JAVA_OPTS
        cmd.add(getSystemPackages());
        cmd.addAll(.asList());
        cmd.add("--");
        cmd.add("-default-jvm");
        cmd.add(getServerJavaCommand());
        cmd.addAll(getServerArguments());
        return cmd;
    }
    @Override
    public List<Stringbuild() {
        final List<Stringcmd = new ArrayList<>();
        cmd.add(getJavaCommand());
        cmd.addAll(buildArguments());
        return cmd;
    }
    @Override
    public Path getJavaHome() {
        return ;
    }
    @Override
    public Path getBaseDirectory() {
        if ( == null) {
            return normalizePath("domain");
        }
        return ;
    }
    @Override
    protected DomainCommandBuilder getThis() {
        return this;
    }
        if ( != null) {
            return getJavaCommand();
        }
        return getJavaCommand();
    }
    private String getServerJavaCommand() {
        if ( != null) {
            return getJavaCommand();
        }
        return getJavaCommand();
    }
New to GrepCode? Check out our FAQ X