Example usage for java.net InetAddress getHostName

List of usage examples for java.net InetAddress getHostName

Introduction

In this page you can find the example usage for java.net InetAddress getHostName.

Prototype

public String getHostName() 

Source Link

Document

Gets the host name for this IP address.

Usage

From source file:com.pinterest.secor.parser.MessageParser.java

public Message transformedMessage(Message message) {
    String inputString = new String(message.getPayload());
    Message returnMessage = message;//from  www.jav a  2 s .  com
    try {
        org.json.JSONObject output = new org.json.JSONObject(inputString);

        String machineName = "defaultMachine";
        try {
            java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost();
            machineName = localMachine.getHostName();
        } catch (Exception e) {

        }
        String csv = "";

        int i = 0;

        String unique_id = output.getString("unique_id");
        String sdk = output.getString("sdk");
        String dBname = output.getString("DBname");
        String event = output.getString("e");
        String user_id = output.getString("user_id");
        String attributes = output.getString("a");
        long timestamp = output.getLong("t");

        String value = user_id + "," + sdk;
        String key = machineName + "-" + String.valueOf(System.currentTimeMillis());

        attributes = attributes.replaceAll("\\;", "-");

        csv += String.valueOf(timestamp) + ";" + unique_id + ";" + attributes + ";" + user_id + ";" + sdk;

        returnMessage = new Message(message.getTopic(), message.getKafkaPartition(), message.getOffset(),
                message.getKafkaKey(), csv.getBytes(Charset.forName("UTF-8")));

        //File file1 = FileUtils.getFile("~/Documents/keyMappings.txt");
        //FileUtils.write(file1,key+"="+value+"\n",true);
        //File file2 = FileUtils.getFile("~/Documents/eventAttributes.txt");
        //FileUtils.write(file2,"dbName="+dBname+"_"+"event="+event+"-->"+title);

    } catch (Exception e) {
        LOG.error("Error----" + e.getMessage());
    }
    return returnMessage;
}

From source file:mitm.common.mail.MessageIDCreator.java

private String getHostname() {
    String hostname = null;//w ww  .  ja  v  a  2 s .  com

    InetAddress localHost = null;

    try {
        localHost = InetAddress.getLocalHost();

        if (localHost != null) {
            hostname = StringUtils.trimToNull(localHost.getHostName());
        }
    } catch (Exception e) {
        /*
         * Can happen if the name of the host is invalid  
         */
        logger.debug("Error getting localhost", e);
    }

    if (hostname == null) {
        hostname = "localhost";
    }

    return hostname;
}

From source file:SimpleAuthenticator.java

protected PasswordAuthentication getPasswordAuthentication() {

    // given a prompt?
    String prompt = getRequestingPrompt();
    if (prompt == null)
        prompt = "Please login...";

    // protocol/*from   ww  w . j  a  v a 2 s .  com*/
    String protocol = getRequestingProtocol();
    if (protocol == null)
        protocol = "Unknown protocol";

    // get the host
    String host = null;
    InetAddress inet = getRequestingSite();
    if (inet != null)
        host = inet.getHostName();
    if (host == null)
        host = "Unknown host";

    // port
    String port = "";
    int portnum = getRequestingPort();
    if (portnum != -1)
        port = ", port " + portnum + " ";

    // Build the info string
    String info = "Connecting to " + protocol + " mail service on host " + host + port;

    //JPanel d = new JPanel();
    // XXX - for some reason using a JPanel here causes JOptionPane
    // to display incorrectly, so we workaround the problem using
    // an anonymous JComponent.
    JComponent d = new JComponent() {
    };

    GridBagLayout gb = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    d.setLayout(gb);
    c.insets = new Insets(2, 2, 2, 2);

    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 0.0;
    d.add(constrain(new JLabel(info), gb, c));
    d.add(constrain(new JLabel(prompt), gb, c));

    c.gridwidth = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    d.add(constrain(new JLabel("Username:"), gb, c));

    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    String user = getDefaultUserName();
    JTextField username = new JTextField(user, 20);
    d.add(constrain(username, gb, c));

    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    c.weightx = 0.0;
    d.add(constrain(new JLabel("Password:"), gb, c));

    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    JPasswordField password = new JPasswordField("", 20);
    d.add(constrain(password, gb, c));
    // XXX - following doesn't work
    if (user != null && user.length() > 0)
        password.requestFocus();
    else
        username.requestFocus();

    int result = JOptionPane.showConfirmDialog(frame, d, "Login", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);

    if (result == JOptionPane.OK_OPTION)
        return new PasswordAuthentication(username.getText(), password.getText());
    else
        return null;
}

From source file:org.apache.whirr.service.hbase.HBaseMasterClusterActionHandler.java

@Override
protected void afterConfigure(ClusterActionEvent event) throws IOException {
    ClusterSpec clusterSpec = event.getClusterSpec();
    Cluster cluster = event.getCluster();

    // TODO: wait for regionservers to come up?

    LOG.info("Completed configuration of {}", clusterSpec.getClusterName());
    Instance instance = cluster.getInstanceMatching(role(ROLE));
    InetAddress masterPublicAddress = instance.getPublicAddress();

    LOG.info("Web UI available at http://{}", masterPublicAddress.getHostName());
    String quorum = ZooKeeperCluster.getHosts(cluster);
    Properties config = createClientSideProperties(masterPublicAddress, quorum);
    createClientSideHadoopSiteFile(clusterSpec, config);
    createProxyScript(clusterSpec, cluster);
    event.setCluster(new Cluster(cluster.getInstances(), config));
}

From source file:com.edmunds.etm.common.api.AgentInstance.java

/**
 * Gets the host name.//from w ww .j  a va  2 s  .com
 *
 * @return host name
 */
public String getHostName() {
    if (hostName == null) {
        try {
            InetAddress addr = InetAddress.getByName(ipAddress);
            hostName = addr.getHostName();
        } catch (UnknownHostException e) {
            return "Unknown";
        }
    }
    return hostName;
}

From source file:com.taobao.tddl.common.util.TDDLMBeanServer.java

private TDDLMBeanServer() {
    // MBServer//w ww  .  j a va 2  s . co  m
    String hostName = null;
    try {
        InetAddress addr = InetAddress.getLocalHost();

        hostName = addr.getHostName();
    } catch (IOException e) {
        log.error(LogPrefix + "Get HostName Error", e);
        hostName = "localhost";
    }
    String host = System.getProperty("hostName", hostName);
    try {
        boolean useJmx = Boolean.parseBoolean(System.getProperty("tddl.useJMX", "true"));
        if (useJmx) {
            mbs = ManagementFactory.getPlatformMBeanServer();
            int port = Integer.parseInt(System.getProperty("tddl.rmi.port", "6679"));
            String rmiName = System.getProperty("tddl.rmi.name", "tddlJmxServer");
            Registry reg = null;
            try {
                reg = LocateRegistry.getRegistry(port);
                reg.list();
            } catch (Exception e) {
                reg = null;
            }
            if (null == reg) {
                reg = LocateRegistry.createRegistry(port);
            }
            reg.list();
            String serverURL = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/" + rmiName;
            JMXServiceURL url = new JMXServiceURL(serverURL);
            final JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url,
                    null, mbs);
            connectorServer.start();
            Runtime.getRuntime().addShutdownHook(new Thread() {
                @Override
                public void run() {
                    try {
                        System.err.println("JMXConnector stop");
                        connectorServer.stop();
                    } catch (IOException e) {
                        log.error(LogPrefix + e);
                    }
                }
            });
            log.warn(LogPrefix + "jmx url: " + serverURL);
        }
    } catch (Exception e) {
        log.error(LogPrefix + "create MBServer error", e);
    }
}

From source file:org.adblockplus.android.configurators.ManualProxyConfigurator.java

@Override
public boolean registerProxy(final InetAddress address, final int port) {
    this.proxyProperties = new ProxyProperties(address.getHostName(), port, "");
    this.startNoTrafficCheck();
    return true;/*w w  w . ja va 2s .  com*/
}

From source file:org.apache.synapse.startup.quartz.StartUpController.java

private boolean processPinnedServers(TaskDescription taskDescription, SynapseEnvironment synapseEnvironment) {
    String thisServerName = synapseEnvironment.getServerContextInformation().getServerConfigurationInformation()
            .getServerName();/*w ww.jav  a  2s .com*/
    if (thisServerName == null || thisServerName.equals("")) {
        try {
            InetAddress address = InetAddress.getLocalHost();
            thisServerName = address.getHostName();
        } catch (UnknownHostException e) {
            logger.warn("Could not get the host name", e);
        }
        if (thisServerName == null || thisServerName.equals("")) {
            thisServerName = "localhost";
        }
    }
    logger.debug("Synapse server name : " + thisServerName);
    List pinnedServers = taskDescription.getPinnedServers();
    if (pinnedServers != null && !pinnedServers.isEmpty()) {
        if (!pinnedServers.contains(thisServerName)) {
            logger.info("Server name not in pinned servers list. Not starting Task : " + getName());
            return false; // do not continue the caller of this method.
        }
    }
    return true;
}

From source file:org.apache.zeppelin.shell.TerminalInterpreter.java

public void createTerminalDashboard(String noteId, String paragraphId, int port) {
    String hostName = "", hostIp = "";
    URL urlTemplate = Resources.getResource("ui_templates/terminal-dashboard.jinja");
    String template = null;//from  ww  w.  j a  v  a  2  s  .  co m
    try {
        template = Resources.toString(urlTemplate, Charsets.UTF_8);
        InetAddress addr = InetAddress.getLocalHost();
        hostName = addr.getHostName().toString();
        hostIp = RemoteInterpreterUtils.findAvailableHostAddress();
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }

    Jinjava jinjava = new Jinjava();
    HashMap<String, Object> jinjaParams = new HashMap();
    Date now = new Date();
    String terminalServerUrl = "http://" + hostIp + ":" + port + "?noteId=" + noteId + "&paragraphId="
            + paragraphId + "&t=" + now.getTime();
    jinjaParams.put("HOST_NAME", hostName);
    jinjaParams.put("HOST_IP", hostIp);
    jinjaParams.put("TERMINAL_SERVER_URL", terminalServerUrl);
    String terminalDashboardTemplate = jinjava.render(template, jinjaParams);

    LOGGER.info(terminalDashboardTemplate);
    try {
        intpContext.out.setType(InterpreterResult.Type.ANGULAR);
        InterpreterResultMessageOutput outputUI = intpContext.out.getOutputAt(0);
        outputUI.clear();
        outputUI.write(terminalDashboardTemplate);
        outputUI.flush();
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:org.springframework.cloud.etcd.discovery.EtcdDiscoveryProperties.java

private HostInfo initHostInfo() {
    InetAddress ipAddress = getIpAddress();
    return new HostInfo(ipAddress.getHostAddress(), ipAddress.getHostName());
}