Example usage for java.net InetSocketAddress getHostName

List of usage examples for java.net InetSocketAddress getHostName

Introduction

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

Prototype

public final String getHostName() 

Source Link

Document

Gets the hostname .

Usage

From source file:net.ymate.platform.serv.nio.support.NioSession.java

private String __doGetRemoteAddress() {
    if (status() != ISession.Status.CLOSED && __selectionKey != null) {
        if (__channel != null) {
            InetSocketAddress _addr = __doGetChannelInetAddress();
            if (_addr != null) {
                return _addr.getHostName() + ":" + _addr.getPort();
            }//from w  w  w.j a  va  2s  . c o  m
        }
    }
    return null;
}

From source file:org.ros.internal.node.DefaultNodeTest.java

@Test
public void testCreatePublicWithIpv4() throws Exception {
    String host = "1.2.3.4";
    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(host, masterServer.getUri());
    nodeConfiguration.setNodeName("node");
    Node node = nodeFactory.newNode(nodeConfiguration, false);
    InetSocketAddress nodeAddress = ((DefaultNode) node).getAddress();
    assertTrue(nodeAddress.getPort() > 0);
    assertEquals(nodeAddress.getHostName(), host);
    node.shutdown();//from w  ww . j  a va  2  s.c  o  m
}

From source file:org.ros.internal.node.DefaultNodeTest.java

@Test
public void testCreatePublicWithIpv6() throws Exception {
    String host = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(host, masterServer.getUri());
    nodeConfiguration.setNodeName("node");
    Node node = nodeFactory.newNode(nodeConfiguration, false);
    InetSocketAddress nodeAddress = ((DefaultNode) node).getAddress();
    assertTrue(nodeAddress.getPort() > 0);
    assertEquals(nodeAddress.getHostName(), host);
    node.shutdown();/*from ww w.  j a  v a  2 s  . c  om*/
}

From source file:org.sana.net.http.ssl.EasySSLSocketFactory.java

public Socket connectSocket(Socket arg0, InetSocketAddress arg1, InetSocketAddress arg2, HttpParams arg3)
        throws IOException, UnknownHostException, ConnectTimeoutException {
    return connectSocket(arg0, arg1.getHostName(), arg1.getPort(), arg2.getAddress(), arg2.getPort(), arg3);
}

From source file:org.ros.internal.node.DefaultNodeTest.java

@Test
public void testCreatePublic() throws Exception {
    Log log = Mockito.mock(Log.class);
    String host = InetAddress.getLocalHost().getCanonicalHostName();
    assertFalse(InetAddresses.isInetAddress(host));
    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(host, masterServer.getUri());
    //nodeConfiguration.set
    nodeConfiguration.setNodeName("node");
    Node node = nodeFactory.newNode(nodeConfiguration, false);
    InetSocketAddress nodeAddress = ((DefaultNode) node).getAddress();
    assertTrue(nodeAddress.getPort() > 0);
    assertEquals(nodeAddress.getHostName(), host);
    node.shutdown();//from   w  w  w. ja  v a  2  s .com
}

From source file:co.cask.cdap.client.util.RESTClientTest.java

private URI getBaseURI() throws URISyntaxException {
    InetSocketAddress bindAddress = httpService.getBindAddress();
    return new URI("http://" + bindAddress.getHostName() + ":" + bindAddress.getPort());
}

From source file:org.apache.tajo.ws.rs.resources.TestTablesResource.java

@Before
public void setUp() throws Exception {
    InetSocketAddress address = testBase.getTestingCluster().getConfiguration()
            .getSocketAddrVar(ConfVars.REST_SERVICE_ADDRESS);
    restServiceURI = new URI("http", null, address.getHostName(), address.getPort(), "/rest", null, null);
    tablesURI = new URI(restServiceURI + "/databases/" + defaultDatabaseName + "/tables");
    queriesURI = new URI(restServiceURI + "/queries");
    sessionsURI = new URI(restServiceURI + "/sessions");
    restClient = ClientBuilder.newBuilder().register(new GsonFeature(PlanGsonHelper.registerAdapters()))
            .register(LoggingFilter.class).property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true)
            .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true).build();
}

From source file:org.apache.hadoop.ha.SshFenceByTcpPort.java

@Override
public boolean tryFence(HAServiceTarget target, String argsStr) throws BadFencingConfigurationException {

    Args args = new Args(argsStr);
    InetSocketAddress serviceAddr = target.getAddress();
    String host = serviceAddr.getHostName();

    Session session;//from   ww w  .  j  av  a2s  .  c o m
    try {
        session = createSession(serviceAddr.getHostName(), args);
    } catch (JSchException e) {
        LOG.warn("Unable to create SSH session", e);
        return false;
    }

    LOG.info("Connecting to " + host + "...");

    try {
        session.connect(getSshConnectTimeout());
    } catch (JSchException e) {
        LOG.warn("Unable to connect to " + host + " as user " + args.user, e);
        return false;
    }
    LOG.info("Connected to " + host);

    try {
        return doFence(session, serviceAddr);
    } catch (JSchException e) {
        LOG.warn("Unable to achieve fencing on remote host", e);
        return false;
    } finally {
        session.disconnect();
    }
}

From source file:com.kixeye.chassis.support.test.eureka.ChassisEurekaTestConfiguration.java

@Order(0)
@Bean(initMethod = "start", destroyMethod = "stop")
public Server httpServer(@Value("${http.hostname}") String hostname, @Value("${http.port}") int port,
        ConfigurableWebApplicationContext webApplicationContext) {

    // set up servlets
    ServletHandler servlets = new ServletHandler();
    ServletContextHandler context = new ServletContextHandler(
            ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);/* w  w  w.ja v a 2 s  .  c  om*/
    context.setWelcomeFiles(new String[] { "/" });

    // set up spring with the servlet context
    setServletContext(context.getServletContext());

    // configure the spring mvc dispatcher
    DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext);

    // map application servlets
    context.addServlet(new ServletHolder(dispatcher), "/");

    servlets.setHandler(context);

    // create the server
    InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port)
            : new InetSocketAddress(hostname, port);
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    server.setConnectors(new Connector[] { connector });
    server.setHandler(servlets);

    return server;
}

From source file:hudson.gridmaven.gridlayer.PluginImpl.java

/**
 * Determines the HDFS URL.//ww w. j  a va2  s  .  com
 */
public String getHdfsUrl() throws MalformedURLException {
    InetSocketAddress a = getHdfsAddress();
    if (a == null)
        return null;
    return "hdfs://" + a.getHostName() + ":" + a.getPort() + "/";
}