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:org.apache.hadoop.net.TestNetUtils.java

private void verifyInetAddress(InetAddress addr, String host, String ip) {
    assertNotNull(addr);/*from w w w  .ja va 2  s. c om*/
    assertEquals(host, addr.getHostName());
    assertEquals(ip, addr.getHostAddress());
}

From source file:com.buaa.cfs.mount.RpcProgramMountd.java

@Override
public XDR umnt(XDR xdr, XDR out, int xid, InetAddress client) {
    String path = xdr.readString();
    if (LOG.isDebugEnabled()) {
        LOG.debug("MOUNT UMNT path: " + path + " client: " + client);
    }//from  w  w w .j  a  v  a  2  s .  co  m

    String host = client.getHostName();
    mounts.remove(new MountEntry(host, path));
    RpcAcceptedReply.getAcceptInstance(xid, new VerifierNone()).write(out);
    return out;
}

From source file:org.ecocean.ImageProcessor.java

public void run() {
    //        status = Status.INIT;

    if (StringUtils.isBlank(this.command)) {
        log.warn("Can't run processor due to empty command");
        return;//ww  w .ja  va2s  . c  o  m
    }

    if (StringUtils.isBlank(this.imageSourcePath)) {
        log.warn("Can't run processor due to empty source path");
        return;
    }

    if (StringUtils.isBlank(this.imageTargetPath)) {
        log.warn("Can't run processor due to empty target path");
        return;
    }

    String comment = CommonConfiguration.getProperty("imageComment", this.context);
    if (comment == null)
        comment = "%year All rights reserved. | wildbook.org";
    String cname = ContextConfiguration.getNameForContext(this.context);
    if (cname != null)
        comment += " | " + cname;
    String maId = "unknown";
    String rotation = "";
    if (this.parentMA != null) {
        if (this.parentMA.getUUID() != null) {
            maId = this.parentMA.getUUID();
            comment += " | parent " + maId;
        } else {
            maId = this.parentMA.setHashCode();
            comment += " | parent hash " + maId; //a stretch, but maybe should never happen?
        }
        if (this.parentMA.hasLabel("rotate90")) {
            rotation = "-flip -transpose";
        } else if (this.parentMA.hasLabel("rotate180")) {
            rotation = "-flip -flop";
        } else if (this.parentMA.hasLabel("rotate270")) {
            rotation = "-flip -transverse";
        }
    }
    comment += " | v" + Long.toString(System.currentTimeMillis());
    try {
        InetAddress ip = InetAddress.getLocalHost();
        comment += ":" + ip.toString() + ":" + ip.getHostName();
    } catch (UnknownHostException e) {
    }

    int year = Calendar.getInstance().get(Calendar.YEAR);
    comment = comment.replaceAll("%year", Integer.toString(year));
    //TODO should we handle ' better? -- this also assumes command uses '%comment' quoting  :/
    comment = comment.replaceAll("'", "");

    String fullCommand;
    fullCommand = this.command.replaceAll("%width", Integer.toString(this.width))
            .replaceAll("%height", Integer.toString(this.height))
            //.replaceAll("%imagesource", this.imageSourcePath)
            //.replaceAll("%imagetarget", this.imageTargetPath)
            .replaceAll("%maId", maId).replaceAll("%additional", rotation).replaceAll("%arg", this.arg);

    //walk thru transform array and replace "tN" with transform[N]
    if (this.transform.length > 0) {
        for (int i = 0; i < this.transform.length; i++) {
            fullCommand = fullCommand.replaceAll("%t" + Integer.toString(i), Float.toString(this.transform[i]));
        }
    }

    String[] command = fullCommand.split("\\s+");

    //we have to do this *after* the split-on-space cuz files may have spaces!
    for (int i = 0; i < command.length; i++) {
        if (command[i].equals("%imagesource"))
            command[i] = this.imageSourcePath;
        if (command[i].equals("%imagetarget"))
            command[i] = this.imageTargetPath;
        //note this assumes comment stands alone. :/
        if (command[i].equals("%comment"))
            command[i] = comment;
        System.out.println("COMMAND[" + i + "] = (" + command[i] + ")");
    }
    //System.out.println("done run()");
    //System.out.println("command = " + Arrays.asList(command).toString());

    ProcessBuilder pb = new ProcessBuilder();
    pb.command(command);
    /*
            Map<String, String> env = pb.environment();
            env.put("LD_LIBRARY_PATH", "/home/jon/opencv2.4.7");
    */
    //System.out.println("before!");

    try {
        Process proc = pb.start();
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
        String line;
        while ((line = stdInput.readLine()) != null) {
            System.out.println(">>>> " + line);
        }
        while ((line = stdError.readLine()) != null) {
            System.out.println("!!!! " + line);
        }
        proc.waitFor();
        System.out.println("DONE?????");
        ////int returnCode = p.exitValue();
    } catch (Exception ioe) {
        log.error("Trouble running processor [" + command + "]", ioe);
    }
    System.out.println("RETURN");
}

From source file:com.predic8.membrane.core.transport.ssl.SSLContextCollection.java

@Override
public Socket createSocket(InetAddress host, int port, InetAddress addr, int localPort, int connectTimeout)
        throws IOException {
    return getSSLContextForHostname(host.getHostName()).createSocket(host, port, addr, localPort,
            connectTimeout);/*from   ww  w. j  a v  a 2  s.  c  om*/
}

From source file:com.app.server.node.NodeServer.java

/**
 * This method implements the node server request
 *///from  w  ww .j ava  2  s  . com
public void run() {
    //deployer.start();
    try {
        ObjectName objName = new ObjectName("com.app.server:type=deployer,service=RMIDeployer");
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.createMBean("com.app.server.node.RMIDeployer", objName);
        mbeanServer.invoke(objName, "init", new Object[] { deployerList },
                new String[] { Vector.class.getName() });
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.setRmiregistryport(port + "");
        serverConfig.setCachedir("d:/AppServer/cache");
        mbeanServer.invoke(objName, "init", new Object[] { serviceList, serverConfig, mbeanServer },
                new String[] { Vector.class.getName(), ServerConfig.class.getName(),
                        MBeanServer.class.getName() });
        InetAddress inet = null;
        inet = InetAddress.getLocalHost();
        mbeanServer.invoke(objName, "deploy",
                new Object[] { new URL("file:///D:/AppServer/deploy/rmitest.rmi"), false, null,
                        inet.getHostName() + ":" + port },
                new String[] { URL.class.getName(), boolean.class.getName(), ClassLoader.class.getName(),
                        String.class.getName() });
        //deployer.deploy(new URL("file:///D:/AppServer/deploy/rmitest.rmi"),false,null,inet.getHostName()+":"+port);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.qpark.eip.core.spring.lockedoperation.dao.LockedOperationDaoImpl.java

private void setupHostValues() {
    if (this.hostName == null) {
        try {//from w w w  . ja v  a  2  s .  co  m
            InetAddress localaddr = InetAddress.getLocalHost();
            this.hostAddress = localaddr.getHostAddress();
            this.hostName = localaddr.getHostName();
        } catch (UnknownHostException e) {
            this.logger.error(e.getMessage(), e);
            this.hostName = "localhost";
        }
    }
}

From source file:net.sf.mpaxs.spi.computeHost.Settings.java

private String getOwnIP() {

    InetAddress inet2 = null;/*from  w w  w . j a v  a2s .c  om*/
    try {
        InetAddress inet1 = InetAddress.getLocalHost();
        inet2 = InetAddress.getByName(inet1.getHostName());
        return inet2.getHostAddress();
    } catch (UnknownHostException ex) {
        Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:org.apache.whirr.service.hadoop.HadoopNameNodeClusterActionHandler.java

private Properties createClientSideProperties(ClusterSpec clusterSpec, InetAddress namenode,
        InetAddress jobtracker) throws IOException {
    Properties config = new Properties();
    config.setProperty("hadoop.job.ugi", "root,root");
    config.setProperty("fs.default.name", String.format("hdfs://%s:8020/", namenode.getHostName()));
    config.setProperty("mapred.job.tracker", String.format("%s:8021", jobtracker.getHostName()));
    config.setProperty("hadoop.socks.server", "localhost:6666");
    config.setProperty("hadoop.rpc.socket.factory.class.default", "org.apache.hadoop.net.SocksSocketFactory");
    if (clusterSpec.getProvider().endsWith("ec2")) {
        config.setProperty("fs.s3.awsAccessKeyId", clusterSpec.getIdentity());
        config.setProperty("fs.s3.awsSecretAccessKey", clusterSpec.getCredential());
        config.setProperty("fs.s3n.awsAccessKeyId", clusterSpec.getIdentity());
        config.setProperty("fs.s3n.awsSecretAccessKey", clusterSpec.getCredential());
    }/*from  www.  j  a  v a 2 s .  com*/
    return config;
}

From source file:org.lilyproject.rowlog.impl.RemoteListenerHandler.java

public void start() throws RowLogException, InterruptedException, KeeperException {
    InetAddress inetAddress;
    try {//  w w w . j a v a  2 s .  c o  m
        inetAddress = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        throw new RowLogException("Failed to start remote listener", e);
    }
    String hostName = inetAddress.getHostName();
    InetSocketAddress inetSocketAddress = new InetSocketAddress(hostName, 0);
    channel = bootstrap.bind(inetSocketAddress);
    int port = ((InetSocketAddress) channel.getLocalAddress()).getPort();
    listenerId = hostName + ":" + port;
    rowLogConfMgr.addListener(rowLog.getId(), subscriptionId, listenerId);
}