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:org.apache.hadoop.security.TestSecurityUtil.java

private void verifyValues(InetSocketAddress addr, String host, String ip, int port) {
    assertTrue(!addr.isUnresolved());/*  w  ww.  j  av a2s.  c o  m*/
    // don't know what the standard resolver will return for hostname.
    // should be host for host; host or ip for ip is ambiguous
    if (!SecurityUtil.useIpForTokenService) {
        assertEquals(host, addr.getHostName());
        assertEquals(host, addr.getAddress().getHostName());
    }
    assertEquals(ip, addr.getAddress().getHostAddress());
    assertEquals(port, addr.getPort());
}

From source file:com.asakusafw.yaess.jobqueue.client.HttpJobClientTest.java

/**
 * Initializes the test./* w ww.j ava 2s .  c om*/
 * @throws Exception if some errors were occurred
 */
@Before
public void setUp() throws Exception {
    BasicHttpProcessor proc = new BasicHttpProcessor();
    proc.addInterceptor(new ResponseDate());
    proc.addInterceptor(new ResponseServer());
    proc.addInterceptor(new ResponseContent());
    proc.addInterceptor(new ResponseConnControl());
    proc.addInterceptor(new RequestBasicAuth());
    proc.addInterceptor(new ResponseBasicUnauthorized());
    server = new LocalTestServer(proc, null);
    server.start();
    InetSocketAddress address = server.getServiceAddress();
    baseUrl = new URL("http", address.getHostName(), address.getPort(), "/").toExternalForm();
}

From source file:org.apache.hadoop.hbase.security.AbstractTestSecureIPC.java

/**
 * Sets up a RPC Server and a Client. Does a RPC checks the result. If an exception is thrown
 * from the stub, this function will throw root cause of that exception.
 *///w  w w  . j a va 2 s . c  o  m
private void callRpcService(User clientUser) throws Exception {
    SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class);
    Mockito.when(securityInfoMock.getServerPrincipal()).thenReturn(HBaseKerberosUtils.KRB_PRINCIPAL);
    SecurityInfo.addInfo("TestProtobufRpcProto", securityInfoMock);

    InetSocketAddress isa = new InetSocketAddress(HOST, 0);

    RpcServerInterface rpcServer = new RpcServer(null, "AbstractTestSecureIPC",
            Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(SERVICE, null)), isa, serverConf,
            new FifoRpcScheduler(serverConf, 1));
    rpcServer.start();
    try (RpcClient rpcClient = RpcClientFactory.createClient(clientConf,
            HConstants.DEFAULT_CLUSTER_ID.toString())) {
        InetSocketAddress address = rpcServer.getListenerAddress();
        if (address == null) {
            throw new IOException("Listener channel is closed");
        }
        BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(
                ServerName.valueOf(address.getHostName(), address.getPort(), System.currentTimeMillis()),
                clientUser, 0);
        TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface stub = TestRpcServiceProtos.TestProtobufRpcProto
                .newBlockingStub(channel);
        List<String> results = new ArrayList<>();
        TestThread th1 = new TestThread(stub, results);
        final Throwable exception[] = new Throwable[1];
        Collections.synchronizedList(new ArrayList<Throwable>());
        Thread.UncaughtExceptionHandler exceptionHandler = new Thread.UncaughtExceptionHandler() {
            public void uncaughtException(Thread th, Throwable ex) {
                exception[0] = ex;
            }
        };
        th1.setUncaughtExceptionHandler(exceptionHandler);
        th1.start();
        th1.join();
        if (exception[0] != null) {
            // throw root cause.
            while (exception[0].getCause() != null) {
                exception[0] = exception[0].getCause();
            }
            throw (Exception) exception[0];
        }
    } finally {
        rpcServer.stop();
    }
}

From source file:org.cloudata.core.fs.PipeBasedCommitLogFileSystem.java

public boolean ping(String tabletName) throws IOException {
    ServerSet serverSet = serverLocationManager.getTabletServerSet(tabletName);
    if (serverSet == null) {
        return false;
    }//  w  w w  .j  a va  2  s  .  c  o m

    try {
        for (InetSocketAddress address : serverSet.getAddressList()) {
            String lockPath = Constants.COMMITLOG_SERVER + "/" + address.getHostName() + ":"
                    + address.getPort();
            if (zk.exists(LockUtil.getZKPath(conf, lockPath), false) == null) {
                return false;
            }
        }
    } catch (Exception e) {
        return false;
    }

    return true;
}

From source file:de.javakaffee.web.msm.integration.MemcachedFailoverIntegrationTest.java

private String toString(final String nodeId, final InetSocketAddress address) {
    return nodeId + ":" + address.getHostName() + ":" + address.getPort();
}

From source file:org.apache.hadoop.mapred.resourceutilization.Collector.java

protected void initialize(Configuration conf) throws IOException {
    InetSocketAddress socAddr = Collector.getAddress(conf);
    int handlerCount = conf.getInt("mapred.resourceutilization.handler.count", 10);

    // create rpc server
    this.server = RPC.getServer(this, socAddr.getHostName(), socAddr.getPort(), handlerCount, false, conf);

    // The rpc-server port can be ephemeral... ensure we have the correct info
    this.serverAddress = this.server.getListenerAddress();
    LOG.info("Collector up at: " + this.serverAddress);

    // start RPC server
    this.server.start();

    // How long does the TaskTracker reports expire
    timeLimit = conf.getLong("mapred.resourceutilization.timelimit", DEFAULT_TIME_LIMIT);

    // How long do we consider a job is finished after it stops
    stopTimeLimit = conf.getLong("mapred.resourceutilization.stoptimelimit", DEFAULT_STOP_TIME_LIMIT);

    // How often do we aggregate the reports
    aggregatePeriod = conf.getLong("mapred.resourceutilization.aggregateperiod", DEFAULT_AGGREGATE_SLEEP_TIME);

    // Start the daemon thread to aggregate the TaskTracker reports
    this.aggregateDaemon = new Daemon(new AggregateRun());
    this.aggregateDaemon.start();
}

From source file:org.mapfish.print.config.Config.java

/**
 * Get or create the http client to be used to fetch all the map data.
 *///from w w  w.j ava 2s .  c om
public HttpClient getHttpClient(URI uri) {
    MultiThreadedHttpConnectionManager connectionManager = getConnectionManager();
    HttpClient httpClient = new HttpClient(connectionManager);

    // httpclient is a bit pesky about loading everything in memory...
    // disabling the warnings.
    Logger.getLogger(HttpMethodBase.class).setLevel(Level.ERROR);

    // configure proxies for URI
    ProxySelector selector = ProxySelector.getDefault();

    List<Proxy> proxyList = selector.select(uri);
    Proxy proxy = proxyList.get(0);

    if (!proxy.equals(Proxy.NO_PROXY)) {
        InetSocketAddress socketAddress = (InetSocketAddress) proxy.address();
        String hostName = socketAddress.getHostName();
        int port = socketAddress.getPort();

        httpClient.getHostConfiguration().setProxy(hostName, port);
    }

    for (SecurityStrategy sec : security)
        if (sec.matches(uri)) {
            sec.configure(uri, httpClient);
            break;
        }
    return httpClient;
}

From source file:org.apache.hadoop.raid.TestRaidUI.java

@Test
public void testRaidUI() throws Exception {
    Configuration localConf = new Configuration(conf);
    cnode = RaidNode.createRaidNode(null, localConf);
    InetSocketAddress infoSocAddr = dfsCluster.getNameNode().getHttpAddress();
    InjectionHandler h = new TestRaidHTTPInjectionHandler();
    InjectionHandler.set(h);// w  ww.  j  a  va  2s  .c om

    LOG.info("First call will fail with timeout because RaidNode UI will "
            + "hang for 10 seconds. Check TestRaidHTTPInjectionHandler when " + "counter == 1");
    long stime = System.currentTimeMillis();
    String httpContent = DFSUtil.getHTMLContent(new URI("http", null, infoSocAddr.getHostName(),
            infoSocAddr.getPort(), "/dfshealth.jsp", null, null));
    LOG.info("Output1: " + httpContent);
    long duration = System.currentTimeMillis() - stime;
    long expectTimeout = JspHelper.RAID_UI_CONNECT_TIMEOUT + JspHelper.RAID_UI_READ_TIMEOUT;
    assertTrue("Should take less than " + expectTimeout + "ms actual time: " + duration,
            duration < expectTimeout + 1000);
    assertTrue("Should get timeout error", httpContent.contains("Raidnode didn't response"));
    assertFalse("Shouldn't get right result", httpContent.contains("WARNING Corrupt files"));

    LOG.info("Second call will fail with error because RaidNode UI throw "
            + "an IOException. Check TestRaidHTTPInjectionHandler when counter == 2");
    httpContent = DFSUtil.getHTMLContent(new URI("http", null, infoSocAddr.getHostName(), infoSocAddr.getPort(),
            "/dfshealth.jsp", null, null));
    LOG.info("Output2: " + httpContent);
    assertTrue("Should get error", httpContent.contains("Raidnode is unreachable"));
    assertFalse("Shouldn't get right result", httpContent.contains("WARNING Corrupt files"));

    LOG.info("Third call will succeed");
    httpContent = DFSUtil.getHTMLContent(new URI("http", null, infoSocAddr.getHostName(), infoSocAddr.getPort(),
            "/dfshealth.jsp", null, null));
    LOG.info("Output3: " + httpContent);
    assertTrue("Should get right result", httpContent.contains("WARNING Corrupt files"));
}

From source file:org.apache.hadoop.mapred.UtilizationCollector.java

protected void initialize(Configuration conf) throws IOException {
    InetSocketAddress socAddr = UtilizationCollector.getAddress(conf);
    int handlerCount = conf.getInt("mapred.resourceutilization.handler.count", 10);

    // create rpc server
    this.server = RPC.getServer(this, socAddr.getHostName(), socAddr.getPort(), handlerCount, false, conf);

    // The rpc-server port can be ephemeral... ensure we have the correct info
    this.serverAddress = this.server.getListenerAddress();
    LOG.info("Collector up at: " + this.serverAddress);

    // start RPC server
    this.server.start();

    // How long does the TaskTracker reports expire
    timeLimit = conf.getLong("mapred.resourceutilization.timelimit", DEFAULT_TIME_LIMIT);

    // How long do we consider a job is finished after it stops
    stopTimeLimit = conf.getLong("mapred.resourceutilization.stoptimelimit", DEFAULT_STOP_TIME_LIMIT);

    // How often do we aggregate the reports
    aggregatePeriod = conf.getLong("mapred.resourceutilization.aggregateperiod", DEFAULT_AGGREGATE_SLEEP_TIME);

    // Start the daemon thread to aggregate the TaskTracker reports
    this.aggregateDaemon = new Daemon(new AggregateRun());
    this.aggregateDaemon.start();
}

From source file:org.whitesource.agent.client.WssServiceClientImpl.java

private void findDefaultProxy() {
    ProxySearch proxySearch = new ProxySearch();
    proxySearch.addStrategy(ProxySearch.Strategy.JAVA);
    proxySearch.addStrategy(ProxySearch.Strategy.ENV_VAR);
    proxySearch.addStrategy(ProxySearch.Strategy.OS_DEFAULT);
    proxySearch.addStrategy(ProxySearch.Strategy.BROWSER);
    ProxySelector proxySelector = proxySearch.getProxySelector();

    if (proxySelector != null) {
        ProxySelector.setDefault(proxySelector);
        try {/*from   ww w . j a  va  2 s  . c  o  m*/
            List<Proxy> proxyList = proxySelector.select(new URI(serviceUrl));
            if (proxyList != null && !proxyList.isEmpty()) {
                for (Proxy proxy : proxyList) {
                    InetSocketAddress address = (InetSocketAddress) proxy.address();
                    if (address != null) {
                        String host = address.getHostName();
                        int port = address.getPort();
                        String username = System.getProperty(HTTP_PROXY_USER);
                        String password = System.getProperty(HTTP_PROXY_PASSWORD);
                        setProxy(host, port, username, password);
                    }
                }
            }
        } catch (URISyntaxException e) {
            logger.error("Bad service url: " + serviceUrl, e);
        }
    }
}