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.hdfs.server.namenode.NameNode.java

public static URI getUri(InetSocketAddress namenode) {
    int port = namenode.getPort();
    String portString = port == DEFAULT_PORT ? "" : (":" + port);
    return URI.create("hdfs://" + namenode.getHostName() + portString);
}

From source file:org.apache.nifi.cluster.protocol.impl.ClusterServiceDiscovery.java

private String prettyPrint(final InetSocketAddress address) {
    if (address == null) {
        return "0.0.0.0:0";
    } else {// w  w w.j  a  v a2  s .  co m
        return address.getHostName() + ":" + address.getPort();
    }
}

From source file:org.apache.hadoop.hdfs.DFSUtil.java

/**
 * Create a URI from the scheme and address
 *///  w  ww  .  jav a 2s  .c  o  m
public static URI createUri(String scheme, InetSocketAddress address) {
    try {
        return new URI(scheme, null, address.getHostName(), address.getPort(), null, null, null);
    } catch (URISyntaxException ue) {
        throw new IllegalArgumentException(ue);
    }
}

From source file:org.ulteo.utils.ProxyManager.java

public void detect(String remoteHost) {
    Logger.debug("Detect proxy");
    List<Proxy> proxyList = null;
    System.setProperty("java.net.useSystemProxies", "true");
    ProxySelector ps = ProxySelector.getDefault();

    if (ps == null) {
        Logger.warn("Unable to detect a proxy: no proxySelector available");
        return;//w  w w  .j a v a2  s. c o m
    }
    try {
        URI uri = new URI("https://" + remoteHost);
        proxyList = ps.select(uri);
    } catch (URISyntaxException e) {
        Logger.warn("Unable to detect a proxy: bad URL");
        return;
    }
    if (proxyList != null) {
        for (Proxy proxy : proxyList) {
            InetSocketAddress addr = (InetSocketAddress) proxy.address();
            if (addr != null) {
                this.host = addr.getHostName();
                this.port = addr.getPort();
                System.setProperty("https.proxyHost", this.host);
                System.setProperty("https.proxyPort", new Integer(this.port).toString());
                Logger.debug("using proxy[" + this.host + ":" + this.port + "]");
                break;
            }
        }
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.AvatarNodeNew.java

/**
 * Returns the hostname:port for the AvatarNode. The default
 * port for the AvatarNode is one more than the port of the
 * underlying namenode./*from www . java2s .  co m*/
 */
public static InetSocketAddress getAddress(Configuration conf) {
    InetSocketAddress u = NameNode.getAddress(conf);
    int port = conf.getInt("dfs.avatarnode.port", u.getPort() + 1);
    return new InetSocketAddress(u.getHostName(), port);
}

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

private void login(JobConf conf) throws IOException {
    UserGroupInformation.setConfiguration(conf);
    InetSocketAddress infoSocAddr = NetUtils.createSocketAddr(historyInfoAddr);

    SecurityUtil.login(conf, JH_KEYTAB_FILE, JH_USER_NAME, infoSocAddr.getHostName());
    LOG.info("History server login successful");
}

From source file:org.apache.hadoop.hbase.stargate.TestTableResource.java

public void checkTableInfo(TableInfoModel model) {
    assertEquals(model.getName(), TABLE);
    Iterator<TableRegionModel> regions = model.getRegions().iterator();
    assertTrue(regions.hasNext());/*from   w  ww . j av  a2 s. c om*/
    while (regions.hasNext()) {
        TableRegionModel region = regions.next();
        boolean found = false;
        for (Map.Entry<HRegionInfo, HServerAddress> e : regionMap.entrySet()) {
            HRegionInfo hri = e.getKey();
            if (hri.getRegionNameAsString().equals(region.getName())) {
                found = true;
                byte[] startKey = hri.getStartKey();
                byte[] endKey = hri.getEndKey();
                InetSocketAddress sa = e.getValue().getInetSocketAddress();
                String location = sa.getHostName() + ":" + Integer.valueOf(sa.getPort());
                assertEquals(hri.getRegionId(), region.getId());
                assertTrue(Bytes.equals(startKey, region.getStartKey()));
                assertTrue(Bytes.equals(endKey, region.getEndKey()));
                assertEquals(location, region.getLocation());
                break;
            }
        }
        assertTrue(found);
    }
}

From source file:org.apache.hadoop.hbase.stargate.RegionsResource.java

@GET
@Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF })
public Response get(final @Context UriInfo uriInfo) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("GET " + uriInfo.getAbsolutePath());
    }//from  w  w  w.  jav  a  2s.  co m
    if (!servlet.userRequestLimit(user, 1)) {
        Response.status(509).build();
    }
    servlet.getMetrics().incrementRequests(1);
    try {
        String name = user.isAdmin() ? actualTableName : tableName;
        TableInfoModel model = new TableInfoModel(name);
        Map<HRegionInfo, HServerAddress> regions = getTableRegions();
        for (Map.Entry<HRegionInfo, HServerAddress> e : regions.entrySet()) {
            HRegionInfo hri = e.getKey();
            if (user.isAdmin()) {
                HServerAddress addr = e.getValue();
                InetSocketAddress sa = addr.getInetSocketAddress();
                model.add(new TableRegionModel(name, hri.getRegionId(), hri.getStartKey(), hri.getEndKey(),
                        sa.getHostName() + ":" + Integer.valueOf(sa.getPort())));
            } else {
                model.add(new TableRegionModel(name, hri.getRegionId(), hri.getStartKey(), hri.getEndKey()));
            }
        }
        ResponseBuilder response = Response.ok(model);
        response.cacheControl(cacheControl);
        return response.build();
    } catch (TableNotFoundException e) {
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    } catch (IOException e) {
        throw new WebApplicationException(e, Response.Status.SERVICE_UNAVAILABLE);
    }
}

From source file:org.jactr.eclipse.runtime.launching.norm.DefaultACTRLaunchConfiguration.java

@Override
protected AbstractSession startSession(ILaunch launch, ILaunchConfigurationWorkingCopy configuration,
        String mode) throws CoreException {

    if (mode.equals(ILaunchManager.DEBUG_MODE))
        configuration.setAttribute(ACTRLaunchConstants.ATTR_SUSPEND, true);

    ACTRSession session = new ACTRSession(launch, configuration);

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Created session " + session);

    /*//www .  j  a  v a 2s .  c o  m
     * we must start before we do much of anything else
     */
    session.start();

    if (mode.equals(ILaunchManager.DEBUG_MODE)) {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Adding debug target");
        // create the debug target and attach it
        ACTRDebugTarget target = new ACTRDebugTarget(session);
        launch.addDebugTarget(target);
    }

    InetSocketAddress addr = session.getConnectionAddress();

    configuration.setAttribute(ACTRLaunchConstants.ATTR_DEBUG_PORT, addr.getPort());

    configuration.setAttribute(ACTRLaunchConstants.ATTR_DEBUG_ADDRESS, addr.getHostName());

    configuration.setAttribute(ACTRLaunchConstants.ATTR_CREDENTIALS, session.getCredentials().toString());

    return session;
}

From source file:org.enterprisepower.net.portforward.Listener.java

public Listener(InetSocketAddress from, InetSocketAddress to) throws IOException {
    this.from = from;
    this.to = to;
    serverSocket = new ServerSocket();
    serverSocket.setReuseAddress(true);/*from w ww . j a v a2  s .  c  o m*/
    serverSocket.bind(from);
    String hostname = from.getHostName();
    if (hostname == null)
        hostname = "*";
    log.info("Ready to accept client connection on " + hostname + ":" + from.getPort());
}