Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012, 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.jboss.as.host.controller;
 
 import static org.jboss.as.host.controller.HostControllerMessages.MESSAGES;
 
 import java.io.File;
 import java.util.Map;
 
Encapsulates the runtime environment for a host controller. This is parsed when the host controller is initially started, a process reload reuses the host controller environment.

Author(s):
Brian Stansberry
 
 public class HostControllerEnvironment extends ProcessEnvironment {
 
 
     /////////////////////////////////////////////////////////////////////////
     //                   Configuration Value Identifiers                   //
     /////////////////////////////////////////////////////////////////////////
 
    
Constant that holds the name of the system property for specifying the home directory.
 
     public static final String HOME_DIR = "jboss.home.dir";

    
Constant that holds the name of the system property for specifying the directory returned from getModulesDir().

Defaults to HOME_DIR/modules/

This system property has no real meaning and should not be regarded as providing any sort of useful information. The "modules" directory is the default location from which JBoss Modules looks to find modules. However, this behavior is in no way controlled by this system property, nor is it guaranteed that modules will be loaded from only one directory, nor is it guaranteed that the "modules" directory will be one of the directories used. Finally, the structure and contents of any directories from which JBoss Modules loads resources is not something available from this class. Users wishing to interact with the modular classloading system should use the APIs provided by JBoss Modules

Deprecated:
has no useful meaning
 
     @Deprecated
     public static final String MODULES_DIR = "jboss.modules.dir";

    
Constant that holds the name of the system property for specifying getDomainBaseDir() the domain base directory}.

Defaults to HOME_DIR/domain.

 
     public static final String DOMAIN_BASE_DIR = "jboss.domain.base.dir";

    
Constant that holds the name of the system property for specifying getDomainConfigurationDir() the domain configuration directory}.

Defaults to DOMAIN_BASE_DIR/configuration .

 
     public static final String DOMAIN_CONFIG_DIR = "jboss.domain.config.dir";

    
Constant that holds the name of the system property for specifying getDomainDataDir() the domain data directory}.

Defaults to DOMAIN_BASE_DIR/data.

    public static final String DOMAIN_DATA_DIR = "jboss.domain.data.dir";

    
Constant that holds the name of the system property for specifying getDomainContentDir() the domain content repository directory}.

Defaults to DOMAIN_DATA_DIR/content.

    public static final String DOMAIN_CONTENT_DIR = "jboss.domain.content.dir";

    
Deprecated variant of DOMAIN_CONTENT_DIR.

Deprecated:
use DOMAIN_CONTENT_DIR
    @Deprecated
    public static final String DOMAIN_DEPLOYMENT_DIR = "jboss.domain.deployment.dir";

    
Constant that holds the name of the system property for specifying getDomainLogDir() the domain log directory}.

Defaults to DOMAIN_BASE_DIR/log.

    public static final String DOMAIN_LOG_DIR = "jboss.domain.log.dir";

    
Constant that holds the name of the system property for specifying getDomainServersDir() the managed domain server parent directory}.

Defaults to DOMAIN_BASE_DIR/servers.

    public static final String DOMAIN_SERVERS_DIR = "jboss.domain.servers.dir";

    
Constant that holds the name of the system property for specifying getDomainTempDir() the domain temporary file storage directory}.

Defaults to DOMAIN_BASE_DIR/tmp .

    public static final String DOMAIN_TEMP_DIR = "jboss.domain.temp.dir";

    
Constant that holds the name of the system property for specifying the local part of the name of the host that this server is running on.
    public static final String HOST_NAME = "jboss.host.name";

    
Constant that holds the name of the system property for specifying the fully-qualified name of the host that this server is running on.
    public static final String QUALIFIED_HOST_NAME = "jboss.qualified.host.name";

    
Common alias between domain and standalone mode. Uses jboss.domain.temp.dir on domain mode, and jboss.server.temp.dir on standalone server mode.
    public static final String CONTROLLER_TEMP_DIR = "jboss.controller.temp.dir";

    
The default system property used to store bind address information from the command-line (-b).
    public static final String JBOSS_BIND_ADDRESS = "jboss.bind.address";

    
Prefix for the system property used to store qualified bind address information from the command-line (-bxxx).
    public static final String JBOSS_BIND_ADDRESS_PREFIX =  + ".";

    
The default system property used to store multicast address information from the command-line (-u).
    public static final String JBOSS_DEFAULT_MULTICAST_ADDRESS = "jboss.default.multicast.address";

    
The default system property used to store the master Host Controller's native management interface address from the command line.
    public static final String JBOSS_DOMAIN_MASTER_ADDRESS = "jboss.domain.master.address";

    
The default system property used to store the master Host Controller's native of the master port from the command line.
    public static final String JBOSS_DOMAIN_MASTER_PORT = "jboss.domain.master.port";

    
The system property used to store the name of the default domain configuration file. If not set, the default domain configuration file is "domain.xml". The default domain configuration file is only relevant if the user does not use the -c or --domain-config command line switches to explicitly set the domain configuration file.
    public static final String JBOSS_DOMAIN_DEFAULT_CONFIG = "jboss.domain.default.config";

    
The system property used to store the name of the default host configuration file. If not set, the default domain configuration file is "host.xml". The default domain configuration file is only relevant if the user does not use the --host-config command line switch to explicitly set the host configuration file.
    public static final String JBOSS_HOST_DEFAULT_CONFIG = "jboss.host.default.config";
    private final Map<StringStringhostSystemProperties;
    private final InetAddress processControllerAddress;
    private final Integer processControllerPort;
    private final InetAddress hostControllerAddress;
    private final Integer hostControllerPort;
    private final File homeDir;
    private final File modulesDir;
    private final File domainBaseDir;
    private final File domainConfigurationDir;
    private final String domainConfig;
    private final String initialDomainConfig;
    private final File domainContentDir;
    private final File domainDataDir;
    private final File domainLogDir;
    private final File domainServersDir;
    private final File domainTempDir;
    private final File defaultJVM;
    private final boolean isRestart;
    private final boolean backupDomainFiles;
    private final boolean useCachedDc;
    private final RunningMode initialRunningMode;
    private final ProductConfig productConfig;
    private final String qualifiedHostName;
    private final String hostName;
    private final String modulePath;
    private volatile String hostControllerName;
    public HostControllerEnvironment(Map<StringStringhostSystemPropertiesboolean isRestartString modulePath,
                                     InetAddress processControllerAddressInteger processControllerPortInetAddress hostControllerAddress,
                                     Integer hostControllerPortString defaultJVMString domainConfigString initialDomainConfigString hostConfig,
                                     String initialHostConfigRunningMode initialRunningModeboolean backupDomainFilesboolean useCachedDcProductConfig productConfig) {
        if (hostSystemProperties == null) {
            throw .nullVar("hostSystemProperties");
        }
        this. = Collections.unmodifiableMap(hostSystemProperties);
        if (modulePath == null) {
            throw .nullVar("modulePath");
        }
        if (processControllerAddress == null) {
            throw .nullVar("processControllerAddress");
        }
        if (processControllerPort == null) {
            throw .nullVar("processControllerPort");
        }
        if (hostControllerAddress == null) {
            throw .nullVar("hostControllerAddress");
        }
        if (hostControllerPort == null) {
            throw .nullVar("hostControllerPort");
        }
        this. = processControllerPort;
        this. = processControllerAddress;
        this. = hostControllerAddress;
        this. = hostControllerPort;
        this. = isRestart;
        this. = modulePath;
        this. = initialRunningMode;
        this. = new HostRunningModeControl(initialRunningMode.);
        // Calculate host and default server name
        String hostName = hostSystemProperties.get();
        String qualifiedHostName = hostSystemProperties.get();
        if (qualifiedHostName == null) {
            Map<StringStringenv = null;
            // if host name is specified, don't pick a qualified host name that isn't related to it
            qualifiedHostName = hostName;
            if (qualifiedHostName == null) {
                env = WildFlySecurityManager.getSystemEnvironmentPrivileged();
                // POSIX-like OSes including Mac should have this set
                qualifiedHostName = env.get("HOSTNAME");
            }
            if (qualifiedHostName == null) {
                // Certain versions of Windows
                qualifiedHostName = env.get("COMPUTERNAME");
            }
            if (qualifiedHostName == null) {
                try {
                    qualifiedHostName = NetworkUtils.canonize(InetAddress.getLocalHost().getHostName());
                } catch (UnknownHostException e) {
                    qualifiedHostName = null;
                }
            }
            if (qualifiedHostName != null && qualifiedHostName.matches("^\\d+\\.\\d+\\.\\d+\\.\\d+$|:")) {
                // IP address is not acceptable
                qualifiedHostName = null;
            }
            if (qualifiedHostName == null) {
                // Give up
                qualifiedHostName = "unknown-host.unknown-domain";
            } else {
                qualifiedHostName = qualifiedHostName.trim().toLowerCase();
            }
        }
        this. = qualifiedHostName;
        this. = qualifiedHostName;
        if (hostName == null) {
            // Use the host part of the qualified host name
            final int idx = qualifiedHostName.indexOf('.');
            hostName = idx == -1 ? qualifiedHostName : qualifiedHostName.substring(0, idx);
        }
        this. = hostName;
        File home = getFileFromProperty();
        this. = home;
        if ( == null) {
            throw .missingHomeDirConfiguration();
        }
        if (!.exists() || !.isDirectory()) {
            throw .homeDirectoryDoesNotExist();
        }
        WildFlySecurityManager.setPropertyPrivileged(this..getAbsolutePath());
        @SuppressWarnings("deprecation")
        File tmp = getFileFromProperty();
        if (tmp == null) {
            tmp = new File(this."modules");
        } else if (!tmp.exists() || !tmp.isDirectory()) {
            throw .modulesDirectoryDoesNotExist(tmp);
        }
        this. = tmp;
        @SuppressWarnings("deprecation")
        String deprecatedModDir = ;
        WildFlySecurityManager.setPropertyPrivileged(deprecatedModDirthis..getAbsolutePath());
        tmp = getFileFromProperty();
        if (tmp == null) {
            tmp = new File(this."domain");
        }
        if (!tmp.exists()) {
            throw .domainBaseDirectoryDoesNotExist(tmp);
        } else if (!tmp.isDirectory()) {
            throw .domainBaseDirectoryIsNotADirectory(tmp);
        }
        this. = tmp;
        WildFlySecurityManager.setPropertyPrivileged(this..getAbsolutePath());
        tmp = getFileFromProperty();
        if (tmp == null) {
            tmp = new File(this."configuration");
        }
        if (!tmp.exists() || !tmp.isDirectory()) {
            throw .configDirectoryDoesNotExist(tmp);
        }
        this. = tmp;
        WildFlySecurityManager.setPropertyPrivileged(this..getAbsolutePath());
        final String defaultHostConfig = WildFlySecurityManager.getPropertyPrivileged("host.xml");
         = new ConfigurationFile(defaultHostConfiginitialHostConfig == null ? hostConfig : initialHostConfiginitialHostConfig == null);
        this. = domainConfig;
        this. = initialDomainConfig;
        tmp = getFileFromProperty();
        if (tmp == null) {
            tmp = new File(this."data");
        }
        this. = tmp;
        if (.exists()) {
            if (!.isDirectory()) {
                throw .domainDataDirectoryIsNotDirectory();
            }
        } else {
            if (!.mkdirs()) {
                throw .couldNotCreateDomainDataDirectory();
            }
        }
        WildFlySecurityManager.setPropertyPrivileged(this..getAbsolutePath());
        @SuppressWarnings("deprecation")
        String deprecatedDepDir = ;
        tmp = getFileFromProperty();
        if (tmp == null) {
            tmp = getFileFromProperty(deprecatedDepDir);
        }
        if (tmp == null) {
            tmp = new File(this."content");
        }
        this. = tmp;
        if (.exists()) {
            if (!.isDirectory()) {
                throw .domainContentDirectoryIsNotDirectory();
            }
        } else if (!.mkdirs()) {
        }
        WildFlySecurityManager.setPropertyPrivileged(this..getAbsolutePath());
        WildFlySecurityManager.setPropertyPrivileged(deprecatedDepDirthis..getAbsolutePath());
        tmp = getFileFromProperty();
        if (tmp == null) {
            tmp = new File(this."log");
        }
        if (tmp.exists()) {
            if (!tmp.isDirectory()) {
                throw .logDirectoryIsNotADirectory(tmp);
            }
        } else if (!tmp.mkdirs()) {
            throw .couldNotCreateLogDirectory(tmp);
        }
        this. = tmp;
        WildFlySecurityManager.setPropertyPrivileged(this..getAbsolutePath());
        tmp = getFileFromProperty();
        if (tmp == null) {
            tmp = new File(this."servers");
        }
        if (tmp.exists()) {
            if (!tmp.isDirectory()) {
                throw .serversDirectoryIsNotADirectory(tmp);
            }
        } else if (!tmp.mkdirs()) {
            throw .couldNotCreateServersDirectory(tmp);
        }
        this. = tmp;
        WildFlySecurityManager.setPropertyPrivileged(this..getAbsolutePath());
        tmp = getFileFromProperty();
        if (tmp == null) {
            tmp = new File(this."tmp");
        }
        if (tmp.exists()) {
            if (!tmp.isDirectory()) {
                throw .domainTempDirectoryIsNotADirectory(tmp);
            }
        } else if (!tmp.mkdirs()){
            throw .couldNotCreateDomainTempDirectory(tmp);
        }
        this. = tmp;
        WildFlySecurityManager.setPropertyPrivileged(this..getAbsolutePath());
        if(defaultJVM != null) {
            if (defaultJVM.equals("java")) {
                defaultJVM = DefaultJvmUtils.findJavaExecutable(DefaultJvmUtils.getCurrentJvmHome());
            }
            this. = new File(defaultJVM);
        } else {
            this. = null;
        }
        this. = backupDomainFiles;
        this. = useCachedDc;
        this. = productConfig;
    }

    
Gets the address the process controller passed to this process to use in communicating with it.

Returns:
the process controller's address
        return ;
    }

    
Gets the port number the process controller passed to this process to use in communicating with it.

Returns:
the process controller's port
    public Integer getProcessControllerPort() {
        return ;
    }

    
Gets the address the process controller told this Host Controller to use for communication with it. Not related to communication with management clients.

Returns:
the address used for inter-process communication with the Process Controller
        return ;
    }

    
Gets the port the process controller told this Host Controller to use for communication with it. Not related to communication with management clients.

Returns:
the port used for inter-process communication with the Process Controller
    public Integer getHostControllerPort() {
        return ;
    }

    
Gets whether this was a restarted host controller.

Returns:
if it was restarted
    public boolean isRestart() {
        return ;
    }

    
Whether we should maintain a copy of the domain configuration file even though we are not the master host controller for the domain. This is only relevant if we are not the master host controller.

Returns:
true if we should grab the files
    public boolean isBackupDomainFiles() {
        return ;
    }

    
Whether we should try to start up with a locally cached copy of the domain configuration file rather than trying to connect to a master host controller. This only has an effect if we are not configured to act as the master host controller for the domain.

Returns:
true if we start with a locally cached copy of the domain configuration file
    public boolean isUseCachedDc() {
        return ;
    }

    
Gets the org.jboss.as.controller.RunningMode that was in effect when this Host Controller was launched.

Returns:
the initial running mode
        return ;
    }

    
Get the HostRunningModeControl containing the current running mode of the host controller

Returns:
the running mode control
        return ;
    }

    
Gets the org.jboss.as.version.ProductConfig detected at startup.

Returns:
the product config. Will not be null
    public ProductConfig getProductConfig() {
        return ;
    }

    
Gets the root directory for this JBoss installation.

Returns:
the root directory
    public File getHomeDir() {
        return ;
    }

    
A filesystem location that has no real meaning and should not be regarded as providing any sort of useful information. The "modules" directory is the default location from which JBoss Modules looks to find modules. However, this behavior is in no way controlled by the value returned by this method, nor is it guaranteed that modules will be loaded from only one directory, nor is it guaranteed that the "modules" directory will be one of the directories used. Finally, the structure and contents of any directories from which JBoss Modules loads resources is not something available from this class. Users wishing to interact with the modular classloading system should use the APIs provided by JBoss Modules.

Deprecated:
has no reliable meaning
Returns:
a file
    @Deprecated
    public File getModulesDir() {
        return ;
    }

    
Gets the base directory in which managed domain files are stored.

Defaults to JBOSS_HOME/domain

Returns:
the domain base directory.
    public File getDomainBaseDir() {
        return ;
    }

    
Gets the directory in which managed domain configuration files are stored.

Defaults to getDomainBaseDir() domainBaseDir}/configuration

Returns:
the domain configuration directory.
    public File getDomainConfigurationDir() {
        return ;
    }

    
Gets the directory in which a Host Controller or Process Controller can store private internal state that should survive a process restart.

Defaults to getDomainBaseDir() domainBaseDir}/data

Returns:
the internal state persistent storage directory for the Host Controller and Process Controller.
    public File getDomainDataDir() {
        return ;
    }

    
Gets the directory in which a Host Controller will store domain-managed user content (e.g. deployments or rollout plans.)

Defaults to getDomainDataDir() domainDataDir}/content

Returns:
the domain managed content storage directory
    public File getDomainContentDir() {
        return ;
    }

    
Deprecated previous name for getDomainContentDir().

Deprecated:
use getDomainContentDir()
Returns:
the domain managed content storage directory.
    @Deprecated
    public File getDomainDeploymentDir() {
        return ;
    }

    
Gets the directory in which a Host Controller or Process Controller can write log files.

Defaults to getDomainBaseDir() domainBaseDir}/log

Returns:
the log file directory for the Host Controller and Process Controller.
    public File getDomainLogDir() {
        return ;
    }

    
Gets the directory under domain managed servers will write any persistent data. Each server will have its own subdirectory.

Defaults to getDomainBaseDir() domainBaseDir}/servers

Returns:
the root directory for domain managed servers
    public File getDomainServersDir() {
        return ;
    }

    
Gets the directory in which a Host Controller or Process Controller can store private internal state that does not need to survive a process restart.

Defaults to getDomainBaseDir() domainBaseDir}/tmp

Returns:
the internal state temporary storage directory for the Host Controller and Process Controller.
    public File getDomainTempDir() {
        return ;
    }

    
Gets the location of the default java executable to use when launch managed domain servers.

Returns:
the location of the default java executable
    public File getDefaultJVM() {
        return ;
    }

    
Initial set of system properties provided to this Host Controller at boot via the command line.

Returns:
the properties
    public Map<StringStringgetHostSystemProperties() {
        return ;
    }

    
Get the fully-qualified host name detected at server startup.

Returns:
the qualified host name
    public String getQualifiedHostName() {
        return ;
    }

    
Get the local host name detected at server startup. Note that this is not the same as the host controller name. Defaults to the portion of the qualified host name following the first '.'.

Returns:
the local host name
    public String getHostName() {
        return ;
    }

    
Gets the name by which this host controller is known in the domain. Default to the qualified host name if the name attribute is not specified on the root element of the host configuration file (e.g. host.xml).

Returns:
the name of the host controller
    public String getHostControllerName() {
        return ;
    }
    @Override
    protected String getProcessName() {
        return ;
    }
    @Override
    protected void setProcessName(String processName) {
        if (processName != null) {
            this. = processName;
        }
    }
    @Override
    protected boolean isRuntimeSystemPropertyUpdateAllowed(String propertyNameString propertyValueboolean bootTime) {
        // Currently any system-property in host.xml should not be applied to the HC runtime. This method
        // should not be invoked.
    }
    @Override
    protected void systemPropertyUpdated(String propertyNameString propertyValue) {
        // no-op
    }
        return ;
    }
        return ;
    }
        return ;
    }
        return ;
    }

    
This shouldn't really be a property of this class, but we expose it in the management API resource for the HC environment, so we store it here.

Parameters:
domainConfigurationFile the config file, or null in a slave HC without --backup --cached-dc
    void setDomainConfigurationFile(ConfigurationFile domainConfigurationFile) {
        this. = domainConfigurationFile;
    }
    String getModulePath() {
        return ;
    }

    
Get a File from configuration.

Parameters:
name the name of the property
Returns:
the CanonicalFile form for the given name.
    private File getFileFromProperty(final String name) {
        String value = .get(name);
        File result = (value != null) ? new File(value) : null;
        // AS7-1752 see if a non-existent relative path exists relative to the home dir
        if (result != null &&  != null && !result.exists() && !result.isAbsolute()) {
            File relative = new File(value);
            if (relative.exists()) {
                result = relative;
            }
        }
        return result;
    }
New to GrepCode? Check out our FAQ X