List of usage examples for java.net InetSocketAddress getHostName
public final String getHostName()
From source file:org.apache.hadoop.hdfs.server.datanode.SecureDataNodeStarter.java
@Override public void init(DaemonContext context) throws Exception { System.err.println("Initializing secure datanode resources"); // We should only start up a secure datanode in a Kerberos-secured cluster Configuration conf = new Configuration(); // Skip UGI method to not log in if (!conf.get(HADOOP_SECURITY_AUTHENTICATION).equals("kerberos")) throw new RuntimeException("Cannot start secure datanode in unsecure cluster"); // Stash command-line arguments for regular datanode args = context.getArguments();//from ww w . j a v a2s . c om // Obtain secure port for data streaming to datanode InetSocketAddress socAddr = DataNode.getStreamingAddr(conf); int socketWriteTimeout = conf.getInt("dfs.datanode.socket.write.timeout", HdfsConstants.WRITE_TIMEOUT); ServerSocket ss = (socketWriteTimeout > 0) ? ServerSocketChannel.open().socket() : new ServerSocket(); ss.bind(socAddr, 0); // Check that we got the port we need if (ss.getLocalPort() != socAddr.getPort()) throw new RuntimeException("Unable to bind on specified streaming port in secure " + "context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort()); // Obtain secure listener for web server SelectChannelConnector listener = (SelectChannelConnector) HttpServer.createDefaultChannelConnector(); InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf); listener.setHost(infoSocAddr.getHostName()); listener.setPort(infoSocAddr.getPort()); // Open listener here in order to bind to port as root listener.open(); if (listener.getPort() != infoSocAddr.getPort()) throw new RuntimeException("Unable to bind on specified info port in secure " + "context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort()); if (ss.getLocalPort() >= 1023 || listener.getPort() >= 1023) throw new RuntimeException( "Cannot start secure datanode on non-privileged " + " ports. (streaming port = " + ss + " ) (http listener port = " + listener.getConnection() + "). Exiting."); System.err.println("Successfully obtained privileged resources (streaming port = " + ss + " ) (http listener port = " + listener.getConnection() + ")"); resources = new SecureResources(ss, listener); }
From source file:org.apache.hadoop.mapred.JobTrackerHAHttpRedirector.java
public synchronized void start() throws Exception { if (activeJobTrackerUrl == null) { return;/* w w w .j av a 2 s . c o m*/ } if (server == null) { @SuppressWarnings("deprecation") String infoAddr = NetUtils2.getServerAddress(conf, HAUtil.MR_JOBTRACKER_OLD_HTTP_ADDRESS_KEY, HAUtil.MR_JOBTRACKER_OLD_HTTP_PORT_KEY, HAUtil.MR_JOBTRACKER_HTTP_ADDRESS_KEY); LOG.info("Starting " + getClass().getSimpleName() + " on " + infoAddr); InetSocketAddress infoSocAddr = NetUtils.createSocketAddr(infoAddr); String infoBindAddress = infoSocAddr.getHostName(); int infoBindPort = infoSocAddr.getPort(); server = new HttpServer("static", infoBindAddress, infoBindPort, false); server.addInternalServlet("redirector", "/*", RedirectorServlet.class, false); server.setAttribute(ACTIVE_JOBTRACKER_BASEURL, activeJobTrackerUrl); server.start(); LOG.info("Started"); } else { throw new Exception("JobTrackerHAHttpRedirector already running"); } }
From source file:org.apache.hama.bsp.message.HadoopMessageManagerImpl.java
private final void startRPCServer(Configuration conf, InetSocketAddress peerAddress) { try {//from w w w . j a v a2 s. c o m this.server = RPC.getServer(this, peerAddress.getHostName(), peerAddress.getPort(), conf); LOG.debug("server : " + server); server.start(); LOG.info(" BSPPeer address:" + peerAddress.getHostName() + " port:" + peerAddress.getPort()); } catch (IOException e) { LOG.error("Fail to start RPC server!", e); throw new RuntimeException("RPC Server could not be launched!"); } }
From source file:org.necsave.NecsaveTransport.java
public Future<Boolean> sendMessage(final Message msg, final int platf) { if (platformAddrs.containsKey(platf)) { InetSocketAddress addr = platformAddrs.get(platf); return sendMessage(msg, addr.getHostName(), addr.getPort()); } else//from w w w .j a v a2 s . co m return ConcurrentUtils.constantFuture(Boolean.FALSE); }
From source file:com.facebook.infrastructure.net.io.ContentStreamState.java
ContentStreamState(TcpReader stream) { super(stream); SocketChannel socketChannel = stream.getStream(); InetSocketAddress remoteAddress = (InetSocketAddress) socketChannel.socket().getRemoteSocketAddress(); String remoteHost = remoteAddress.getHostName(); streamContext_ = StreamContextManager.getStreamContext(remoteHost); streamStatus_ = StreamContextManager.getStreamStatus(remoteHost); }
From source file:com.sharneng.net.misc.EchoServer.java
public EchoServer(InetSocketAddress from) throws IOException { this.from = from; serverSocket = new ServerSocket(); serverSocket.setReuseAddress(true);// w w w .ja va 2s . c om serverSocket.bind(from); String hostname = from.getHostName(); if (hostname == null) hostname = "*"; log.info("Ready to accept client connection on " + hostname + ":" + from.getPort()); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.RMZKFailoverController.java
@Override protected byte[] targetToData(HAServiceTarget target) { InetSocketAddress addr = target.getAddress(); return RMActiveNodeInfoProto.newBuilder().setHostname(addr.getHostName()).setPort(addr.getPort()) .setZkfcPort(target.getZKFCAddress().getPort()).setClusterid(localRMServiceTarget.getClusterId()) .setRmId(localRMServiceTarget.getRmId()).build().toByteArray(); }
From source file:org.apache.tajo.ws.rs.TajoRestService.java
@Override protected void serviceInit(Configuration conf) throws Exception { GsonFeature gsonFeature = new GsonFeature(PlanGsonHelper.registerAdapters()); ClientApplication clientApplication = new ClientApplication(masterContext); ResourceConfig resourceConfig = ResourceConfig.forApplication(clientApplication).register(gsonFeature) .register(LoggingFilter.class).property(ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true) .property(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, true); TajoConf tajoConf = (TajoConf) conf; InetSocketAddress address = tajoConf.getSocketAddrVar(TajoConf.ConfVars.REST_SERVICE_ADDRESS); URI restServiceURI = new URI("http", null, address.getHostName(), address.getPort(), "/rest", null, null); int workerCount = TajoConf.getIntVar(tajoConf, TajoConf.ConfVars.REST_SERVICE_RPC_SERVER_WORKER_THREAD_NUM); restServer = NettyRestServerFactory.createNettyRestServer(restServiceURI, resourceConfig, workerCount, false);// w ww . j av a 2 s.c o m super.serviceInit(conf); LOG.info("Tajo Rest Service initialized."); }
From source file:org.yccheok.jstock.network.ProxyDetector.java
/** * @return a String representing the hostname of the proxy, <tt>null</tt> if there is no proxy *//* w ww . j a v a 2 s .c o m*/ public String getHostname() { if (this.proxyToUse != null) { final SocketAddress socketAddress = this.proxyToUse.address(); if (socketAddress instanceof InetSocketAddress) { InetSocketAddress address = (InetSocketAddress) socketAddress; return address.getHostName(); } } return null; }
From source file:com.googlecode.fascinator.common.BasicHttpClient.java
/** * Gets an HTTP client. If authentication is required, the authenticate() * method must be called prior to this method. * //from w ww . ja v a 2s . c om * @param auth set true to use authentication, false to skip authentication * @return an HTTP client */ public HttpClient getHttpClient(boolean auth) { HttpClient client = new HttpClient(); try { URL url = new URL(baseUrl); Proxy proxy = ProxySelector.getDefault().select(url.toURI()).get(0); if (!proxy.type().equals(Proxy.Type.DIRECT)) { InetSocketAddress address = (InetSocketAddress) proxy.address(); String proxyHost = address.getHostName(); int proxyPort = address.getPort(); client.getHostConfiguration().setProxy(proxyHost, proxyPort); log.trace("Using proxy {}:{}", proxyHost, proxyPort); } } catch (Exception e) { log.warn("Failed to get proxy settings: " + e.getMessage()); } if (auth && credentials != null) { client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, credentials); log.trace("Credentials: username={}", credentials.getUserName()); } return client; }