List of usage examples for java.net InetSocketAddress getHostName
public final String getHostName()
From source file:org.apache.hadoop.yarn.ipc.HadoopYarnRPC.java
@Override public Server getServer(Class protocol, Object instance, InetSocketAddress addr, Configuration conf, SecretManager<? extends TokenIdentifier> secretManager, int numHandlers) { LOG.info("Creating a HadoopYarnRpc server for protocol " + protocol + " with " + numHandlers + " handlers"); LOG.info("Configured SecurityInfo class name is " + conf.get(YarnConfiguration.YARN_SECURITY_INFO)); RPC.setProtocolEngine(conf, protocol, AvroSpecificRpcEngine.class); final RPC.Server hadoopServer; try {//from w w w . ja v a2 s. c o m hadoopServer = RPC.getServer(protocol, instance, addr.getHostName(), addr.getPort(), numHandlers, false, conf, secretManager); } catch (IOException e) { throw new YarnException(e); } Server server = new Server() { @Override public void close() { hadoopServer.stop(); } @Override public int getPort() { return hadoopServer.getListenerAddress().getPort(); } @Override public void join() throws InterruptedException { hadoopServer.join(); } @Override public void start() { hadoopServer.start(); } }; return server; }
From source file:org.apache.tajo.cli.tools.TajoAdmin.java
public void runCommand(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); String param = ""; int cmdType = 0; String hostName = null;/*from w w w . java 2 s . co m*/ Integer port = null; if (cmd.hasOption("h")) { hostName = cmd.getOptionValue("h"); } if (cmd.hasOption("p")) { port = Integer.parseInt(cmd.getOptionValue("p")); } String queryId = null; if (cmd.hasOption("list")) { cmdType = 1; } else if (cmd.hasOption("desc")) { cmdType = 2; } else if (cmd.hasOption("cluster")) { cmdType = 3; } else if (cmd.hasOption("kill")) { cmdType = 4; queryId = cmd.getOptionValue("kill"); } else if (cmd.hasOption("showmasters")) { cmdType = 5; } // if there is no "-h" option, InetSocketAddress address = tajoConf.getSocketAddrVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS, TajoConf.ConfVars.TAJO_MASTER_UMBILICAL_RPC_ADDRESS); if (hostName == null) { hostName = address.getHostName(); } if (port == null) { port = address.getPort(); } if (cmdType == 0) { printUsage(); return; } if ((hostName == null) ^ (port == null)) { System.err.println("ERROR: cannot find valid Tajo server address"); return; } else if (hostName != null && port != null) { tajoConf.setVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS, NetUtils.getHostPortString(hostName, port)); tajoClient = new TajoClientImpl(ServiceTrackerFactory.get(tajoConf)); } else if (hostName == null && port == null) { tajoClient = new TajoClientImpl(ServiceTrackerFactory.get(tajoConf)); } switch (cmdType) { case 1: processList(writer); break; case 2: processDesc(writer); break; case 3: processCluster(writer); break; case 4: processKill(writer, queryId); break; case 5: processMasters(writer); break; default: printUsage(); break; } writer.flush(); }
From source file:org.jenkinsci.plugins.GitLabSecurityRealm.java
/** * Returns the proxy to be used when connecting to the given URI. *//*from www . j av a2s . com*/ private HttpHost getProxy(HttpUriRequest method) throws URIException { Jenkins jenkins = Jenkins.getInstance(); if (jenkins == null) { return null; // defensive check } ProxyConfiguration proxy = jenkins.proxy; if (proxy == null) { return null; // defensive check } Proxy p = proxy.createProxy(method.getURI().getHost()); switch (p.type()) { case DIRECT: return null; // no proxy case HTTP: InetSocketAddress sa = (InetSocketAddress) p.address(); return new HttpHost(sa.getHostName(), sa.getPort()); case SOCKS: default: return null; // not supported yet } }
From source file:org.apache.hadoop.ipc.TestSaslRPC.java
public void testDigestAuthMethod(boolean useIp) throws Exception { setTokenServiceUseIp(useIp);/*from w w w. ja va 2 s . c o m*/ TestTokenSecretManager sm = new TestTokenSecretManager(); Server server = RPC.getServer(new TestSaslImpl(), ADDRESS, 0, 5, true, conf, sm); server.start(); final UserGroupInformation current = UserGroupInformation.getCurrentUser(); final InetSocketAddress addr = NetUtils.getConnectAddress(server); TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current.getUserName())); Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId, sm); SecurityUtil.setTokenService(token, addr); LOG.info("Service IP address for token is " + token.getService()); InetSocketAddress tokenAddr = SecurityUtil.getTokenServiceAddr(token); String expectedHost, gotHost; if (useIp) { expectedHost = addr.getAddress().getHostAddress(); gotHost = tokenAddr.getAddress().getHostAddress(); } else { gotHost = tokenAddr.getHostName(); expectedHost = ADDRESS; } Assert.assertEquals(expectedHost, gotHost); Assert.assertEquals(expectedHost + ":" + addr.getPort(), token.getService().toString()); current.addToken(token); current.doAs(new PrivilegedExceptionAction<Object>() { public Object run() throws IOException { TestSaslProtocol proxy = null; try { proxy = (TestSaslProtocol) RPC.getProxy(TestSaslProtocol.class, TestSaslProtocol.versionID, addr, conf); Assert.assertEquals(AuthenticationMethod.TOKEN, proxy.getAuthMethod()); } finally { if (proxy != null) { RPC.stopProxy(proxy); } } return null; } }); server.stop(); }
From source file:org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer.java
/** * @see org.apache.james.protocols.lib.jmx.ServerMBean#getBoundAddresses() *//*w w w . j av a 2 s .c o m*/ public String[] getBoundAddresses() { List<InetSocketAddress> addresses = getListenAddresses(); String[] addrs = new String[addresses.size()]; for (int i = 0; i < addresses.size(); i++) { InetSocketAddress address = addresses.get(i); addrs[i] = address.getHostName() + ":" + address.getPort(); } return addrs; }
From source file:eu.operando.proxy.OperandoProxyStatus.java
private void updateStatusView() { OperandoProxyStatus proxyStatus = OperandoProxyStatus.STOPPED; OperandoProxyLink proxyLink = OperandoProxyLink.INVALID; boolean isProxyRunning = MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class); boolean isProxyPaused = MainUtil.isProxyPaused(mainContext); if (isProxyRunning) { if (isProxyPaused) { proxyStatus = OperandoProxyStatus.PAUSED; } else {/* ww w. j a v a 2 s . c o m*/ proxyStatus = OperandoProxyStatus.ACTIVE; } } try { Proxy proxy = APL.getCurrentHttpProxyConfiguration(); InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); if (proxyAddress != null) { //TODO: THIS SHOULD BE DYNAMIC String proxyHost = proxyAddress.getHostName(); int proxyPort = proxyAddress.getPort(); if (proxyHost.equals("127.0.0.1") && proxyPort == 8899) { proxyLink = OperandoProxyLink.VALID; } } } catch (Exception e) { e.printStackTrace(); } String info = ""; try { InputStream is = getResources().openRawResource(R.raw.info_template); info = IOUtils.toString(is); IOUtils.closeQuietly(is); } catch (IOException e) { e.printStackTrace(); } info = info.replace("@@status@@", proxyStatus.name()); info = info.replace("@@link@@", proxyLink.name()); webView.loadDataWithBaseURL("", info, "text/html", "UTF-8", ""); webView.setBackgroundColor(Color.TRANSPARENT); //TRANSPARENT }
From source file:com.tesora.dve.mysqlapi.repl.MyReplicationSlaveService.java
@Override public void handleGroupMembershipEvent(MembershipEventType eventType, InetSocketAddress inetSocketAddress) { if (eventType == MembershipEventType.MEMBER_REMOVED) { String memberAddress = inetSocketAddress.getHostName(); try {//w w w . ja v a 2 s. com System.out.println("Member removed. Updating service: " + getName()); String externalServiceAddress = GroupManager.getCoordinationServices() .getExternalServiceRegisteredAddress(getName()); System.out.println("Member removed. External service started on (" + externalServiceAddress + ") and machine leaving is (" + memberAddress + ")"); // for now keep the service registered // if (StringUtils.equals(memberAddress, externalServiceAddress)) { // System.out.println("Member removed. Site starting the service has stopped communicating."); // // // force deregistration of existing service // GroupManager.getCoordinationServices().deregisterExternalService(getName()); // // if (GroupManager.getCoordinationServices().isInQuorum()) { // System.out.println("Member removed. In quorum starting external services."); // try { // ExternalServiceFactory.register(getName(), getPlugin()); // } catch (Exception e) { // l ogger.warn("Failed to register external service '" + getName() + "'", e); // } // } // } } catch (Exception e) { try { logger.warn("Failed to register external service '" + getName() + "'", e); } catch (PEException e1) { } } } }
From source file:org.trypticon.xmpp.bot.BaseBot.java
/** * Connects to the server, opens a stream and logs in. * * @return <code>true</code> if connection is successful. */// w ww . jav a2 s .co m public boolean connect() { JSOImplementation jso = JSO.getInstance(); Element connectionElement = config.getChild("connection"); JID clientJID = JID.valueOf(connectionElement.getChildTextTrim("jid")); JID serverJID = new JID(null, clientJID.getDomain(), null); try { InetSocketAddress address = SrvLookup.resolveXmppClient(clientJID.getDomain()); String hostname = connectionElement.getChildTextTrim("hostname"); if (hostname == null) { hostname = address.getHostName(); } boolean tls = "true".equals(connectionElement.getChildTextTrim("tls")); String portString = connectionElement.getChildTextTrim("port"); int port = (portString == null) ? -1 : Integer.parseInt(portString); if (port == -1) { if (tls) { port = 5223; } else { port = address.getPort(); } } streamSource = new StartTLSSocketStreamSource(hostname, port); streamSource.getTLSContext().init(null, DummyTrustManager.asArray(), null); // Old-style TLS requires negotiation before sending any data. if (tls) { streamSource.negotiateClientTLS(); } } catch (IOException e) { log.error("Failure to create stream source", e); return false; } catch (GeneralSecurityException e) { log.error("TLS is not supported by your JRE", e); return false; } // Create the stream... stream = jso.createStream(Utilities.CLIENT_NAMESPACE); // Attach listeners to the stream. attachListeners(); // Try to connect. try { stream.connect(streamSource); stream.getOutboundContext().setTo(serverJID); stream.getOutboundContext().setVersion("1.0"); stream.open(5000); } catch (StreamException e) { log.error("Failure to connect to stream", e); return false; } // Consume stream features. String password = connectionElement.getChildTextTrim("password"); try { String version = stream.getInboundContext().getVersion(); if ("1.0".equals(version)) { saslLogin(clientJID, password); } else if ("".equals(version)) { authLogin(clientJID, password); } else { log.warn("Version '" + version + "' was not an expected version number"); } } catch (PacketException e) { log.error("Packet error while authenticating", e); return false; } catch (StreamException e) { log.error("Stream error while authenticating", e); return false; } // Set presence to online, but with negative priority. Servers compliant with XMPP will therefore // not send us any messages which were sent to the bare JID. try { String priorityString = connectionElement.getChildTextTrim("priority"); int priority = (priorityString == null) ? -1 : Integer.parseInt(priorityString); Presence presence = (Presence) stream.getDataFactory() .createPacketNode(new NSI("presence", Utilities.CLIENT_NAMESPACE)); presence.setPriority(priority); stream.send(presence); } catch (StreamException e) { log.error("Failure to set presence", e); return false; } return true; }
From source file:hudson.TcpSlaveAgentListener.java
/** * Initiates the shuts down of the listener. *//*from www . j a v a2 s .c o m*/ public void shutdown() { shuttingDown = true; try { SocketAddress localAddress = serverSocket.getLocalAddress(); if (localAddress instanceof InetSocketAddress) { InetSocketAddress address = (InetSocketAddress) localAddress; Socket client = new Socket(address.getHostName(), address.getPort()); client.setSoTimeout(1000); // waking the acceptor loop should be quick new PingAgentProtocol().connect(client); } } catch (IOException e) { LOGGER.log(Level.FINE, "Failed to send Ping to wake acceptor loop", e); } try { serverSocket.close(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to close down TCP port", e); } }
From source file:org.apache.tajo.worker.TajoWorker.java
private int initWebServer() { InetSocketAddress address = systemConf.getSocketAddrVar(ConfVars.WORKER_INFO_ADDRESS); try {//from w ww . j av a 2 s .c o m webServer = StaticHttpServer.getInstance(this, "worker", address.getHostName(), address.getPort(), true, null, systemConf, null); webServer.start(); systemConf.setVar(TajoConf.ConfVars.WORKER_INFO_ADDRESS, NetUtils.getHostPortString( NetUtils.getConnectAddress(new InetSocketAddress(address.getHostName(), webServer.getPort())))); LOG.info("Worker info server started:" + webServer.getPort()); } catch (IOException e) { LOG.error(e.getMessage(), e); } return webServer.getPort(); }