Java HTTP Port Find getNodeName(final String managementServerHostName, final int managementPort)

Here you can find the source of getNodeName(final String managementServerHostName, final int managementPort)

Description

get Node Name

License

Open Source License

Declaration

public static String getNodeName(final String managementServerHostName, final int managementPort) 

Method Source Code

//package com.java2s;
/*//www  .j  av a  2s  . c o m
 * JBoss, Home of Professional Open Source.
 * Copyright 2011, 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.
 */

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Properties;

public class Main {
    public static String getNodeName(final String managementServerHostName, final int managementPort) {
        // TODO: FIXME: Right now, we just return the "hostname" of the client as the node name of the server.
        // This works only when both the client (test) and server are on the same system.
        // We need to fix this once I know if there's any management operation exposed for retrieving the
        // jboss.node.name system property http://lists.jboss.org/pipermail/jboss-as7-dev/2011-November/004434.html
        final String nodeName = getNodeName();
        if (nodeName == null) {
            throw new IllegalStateException("jboss.node.name could not be determined");
        }
        return nodeName;
    }

    private static String getNodeName() {
        // Logic copied from org.jboss.as.server.ServerEnvironment constructor
        final Properties props = System.getProperties();
        final Map<String, String> env = System.getenv();
        // Calculate host and default server name
        String hostName = props.getProperty("jboss.host.name");
        String qualifiedHostName = props.getProperty("jboss.qualified.host.name");
        if (qualifiedHostName == null) {
            // if host name is specified, don't pick a qualified host name that isn't related to it
            qualifiedHostName = hostName;
            if (qualifiedHostName == null) {
                // 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 = 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";
            }
            qualifiedHostName = qualifiedHostName.trim().toLowerCase();
        }
        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);
        }

        // Set up the server name for management purposes
        String serverName = props.getProperty("jboss.server.name");
        if (serverName == null) {
            serverName = hostName;
        }
        // Set up the clustering node name
        String nodeName = props.getProperty("jboss.node.name");
        if (nodeName == null) {
            nodeName = serverName;
        }
        return nodeName;
    }
}

Related

  1. getImportedXmlSchemaPath(String namespace, String portType, String operation)
  2. getNextAvailable(int port)
  3. getNextAvailablePort()
  4. getNextAvailablePort(final int min, final int max, final Collection excepted)
  5. getNextAvailablePort(int port)
  6. getNonPrivilegedPort()
  7. getOpenPort()
  8. getPort(final int suggestedPort)
  9. getPort(int port)