List of usage examples for java.net InetSocketAddress getPort
public final int getPort()
From source file:org.apache.flink.client.CliFrontend.java
/** * Writes the given job manager address to the associated configuration object * * @param address Address to write to the configuration * @param config The config to write to/*from w w w . j a v a 2s.co m*/ */ public static void setJobManagerAddressInConfig(Configuration config, InetSocketAddress address) { config.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, address.getHostString()); config.setInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, address.getPort()); }
From source file:be.vlaanderen.sesam.proxy.internal.BundleActivator.java
@Override public synchronized void onConfigurationChanged(List<Rule> rules) { // must update channels we are listening to Map<Integer, Channel> oldChannels = new HashMap<Integer, Channel>(); oldChannels.putAll(channels);//ww w . j a va 2s. c o m if (rules != null && rules.size() > 0) { for (Rule rule : rules) { Integer port = rule.getLocalRequestPort(); if (port != null && port > 0) { if (channels.containsKey(port)) { // port can be used multiple times so test on channels. oldChannels.remove(port); } else { Channel c = serverBootstrap.bind(new InetSocketAddress(port)); channels.put(port, c); log.info(" - Started listening on port: " + port); } } } } for (Entry<Integer, Channel> entry : oldChannels.entrySet()) { channels.remove(entry.getKey()); entry.getValue().unbind().addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) throws Exception { InetSocketAddress addr = (InetSocketAddress) future.getChannel().getLocalAddress(); log.info("Stopped listening on port: " + addr.getPort() + " -- " + (future.isSuccess() ? "Success" : "Fail")); } }); } }
From source file:gov.hhs.fha.nhinc.lift.proxy.client.ClientConnectorManager.java
/** * This method will create a tunnel of a type defined by the properties * facade and will then bind a local temporary port for a client app to use * to communicate through the proxy tunnel. Returns an address to the * local server a client can talk to./*from ww w .j a va 2 s .co m*/ * * @param token * @param serverProxyAddress * @param serverProxyPort * @return * @throws IOException */ public InetSocketAddress startConnector(RequestToken token, InetAddress serverProxyAddress, int serverProxyPort, int bufferSize, ConsumerProxyPropertiesFacade props, SocketClientManagerController controller) throws IOException { /* * Attempts to start up a connection with the desired server proxy. */ // Note that both client and server are closed when the thread completes log.debug("Creating Client instance to connect to server proxy: " + serverProxyAddress + ":" + serverProxyPort); Client client = props.getClientInstance(serverProxyAddress, serverProxyPort, token); /* * Start up a socket server bound to the local proxy hostname and to a * port unique to this request. */ InetAddress localProxyAddress = props.getClientProxyAddress(); log.debug("Local client proxy address set as: " + localProxyAddress); InetSocketAddress connectorAddress = new InetSocketAddress(localProxyAddress, 0); log.debug("Starting server socket for client to access on port: " + connectorAddress.getPort()); // Note that both client and server are closed when the thread completes ServerSocket server = new ServerSocket(); server.bind(connectorAddress); log.debug("Creating Server bound: " + server.getInetAddress() + ": " + server.getLocalPort()); ClientConnector connector = new ClientConnector(server, client, bufferSize, controller); Thread conn = new Thread(connector); log.debug("Starting new Client Connector thread."); conn.start(); return new InetSocketAddress(server.getInetAddress(), server.getLocalPort()); }
From source file:org.apache.htrace.impl.TestHTracedReceiverConf.java
@Test(timeout = 60000) public void testParseHostPort() throws Exception { InetSocketAddress addr = new Conf( HTraceConfiguration.fromKeyValuePairs(Conf.ADDRESS_KEY, "example.com:8080")).endpoint; Assert.assertEquals("example.com", addr.getHostName()); Assert.assertEquals(8080, addr.getPort()); addr = new Conf(HTraceConfiguration.fromKeyValuePairs(Conf.ADDRESS_KEY, "127.0.0.1:8081")).endpoint; Assert.assertEquals("127.0.0.1", addr.getHostName()); Assert.assertEquals(8081, addr.getPort()); addr = new Conf( HTraceConfiguration.fromKeyValuePairs(Conf.ADDRESS_KEY, "[ff02:0:0:0:0:0:0:12]:9096")).endpoint; Assert.assertEquals("ff02:0:0:0:0:0:0:12", addr.getHostName()); Assert.assertEquals(9096, addr.getPort()); }
From source file:com.ksc.http.conn.ssl.SdkTLSSocketFactory.java
/** * Invalidates all SSL/TLS sessions in {@code sessionContext} associated with {@code remoteAddress}. * * @param sessionContext collection of SSL/TLS sessions to be (potentially) invalidated * @param remoteAddress associated with sessions to invalidate *//*from w w w. j a v a2s.co m*/ private void clearSessionCache(final SSLSessionContext sessionContext, final InetSocketAddress remoteAddress) { final String hostName = remoteAddress.getHostName(); final int port = remoteAddress.getPort(); final Enumeration<byte[]> ids = sessionContext.getIds(); if (ids == null) { return; } while (ids.hasMoreElements()) { final byte[] id = ids.nextElement(); final SSLSession session = sessionContext.getSession(id); if (session != null && session.getPeerHost() != null && session.getPeerHost().equalsIgnoreCase(hostName) && session.getPeerPort() == port) { session.invalidate(); if (LOG.isDebugEnabled()) { LOG.debug("Invalidated session " + session); } } } }
From source file:ch.cyberduck.core.socket.HttpProxyAwareSocket.java
@Override public void connect(final SocketAddress endpoint, final int timeout) throws IOException { if (proxy.type() == Proxy.Type.HTTP) { super.connect(proxy.address(), timeout); final InetSocketAddress address = (InetSocketAddress) endpoint; final OutputStream out = this.getOutputStream(); IOUtils.write(String.format("CONNECT %s:%d HTTP/1.0\n\n", address.getHostName(), address.getPort()), out, Charset.defaultCharset()); final InputStream in = this.getInputStream(); final String response = new LineNumberReader(new InputStreamReader(in)).readLine(); if (null == response) { throw new SocketException(String.format("Empty response from HTTP proxy %s", ((InetSocketAddress) proxy.address()).getHostName())); }//from w w w. j av a 2s. c o m if (response.contains("200")) { in.skip(in.available()); } else { throw new SocketException(String.format("Invalid response %s from HTTP proxy %s", response, ((InetSocketAddress) proxy.address()).getHostName())); } } else { super.connect(endpoint, timeout); } }
From source file:org.apache.accumulo.trace.instrument.receivers.zipkin.ZipkinSpanReceiver.java
@Override protected Client createDestination(InetSocketAddress destination) throws Exception { if (destination == null) return null; log.debug("Connecting to " + destination.getHostName() + ":" + destination.getPort()); TTransport transport = new TFramedTransport(new TSocket(destination.getHostName(), destination.getPort())); try {//from w w w .j a v a2s . co m transport.open(); } catch (TTransportException e) { e.printStackTrace(); } TProtocol protocol = protocolFactory.getProtocol(transport); return new Scribe.Client(protocol); }
From source file:com.chiralBehaviors.slp.hive.hardtack.configuration.PushConfiguration.java
@Override public Engine construct() throws IOException { NetworkInterface intf = getNetworkInterface(); InetAddress address = Utils.getAddress(intf, ipv4); DatagramSocket p2pSocket = new DatagramSocket(new InetSocketAddress(address, Utils.allocatePort(address))); int i = 0;//from w w w.j av a 2s . c om for (InetSocketAddress aggregator : aggregators) { log.info(String.format("Adding aggregator: %s", aggregator)); if (aggregator.getAddress().isAnyLocalAddress()) { aggregators.set(i++, new InetSocketAddress(address, aggregator.getPort())); } } return new PushEngine(p2pSocket, getMac(), Generators.timeBasedGenerator(), aggregators, heartbeatPeriod, heartbeatUnit, Executors.newSingleThreadScheduledExecutor()); }
From source file:org.elasticsearch.example.SiteContentsIT.java
public void test() throws Exception { TestCluster cluster = cluster();/*from w ww. j a va 2s .co m*/ assumeTrue( "this test will not work from an IDE unless you pass tests.cluster pointing to a running instance", cluster instanceof ExternalTestCluster); ExternalTestCluster externalCluster = (ExternalTestCluster) cluster; try (CloseableHttpClient httpClient = HttpClients .createMinimal(new PoolingHttpClientConnectionManager(15, TimeUnit.SECONDS))) { for (InetSocketAddress address : externalCluster.httpAddresses()) { RestResponse restResponse = new RestResponse( new HttpRequestBuilder(httpClient).host(NetworkAddress.format(address.getAddress())) .port(address.getPort()).path("/_plugin/site-example/").method("GET").execute()); assertEquals(200, restResponse.getStatusCode()); String body = restResponse.getBodyAsString(); assertTrue("unexpected body contents: " + body, body.contains("<body>Page body</body>")); } } }
From source file:org.apache.hadoop.hdfs.DFSUtil.java
/** * Create a URI from the scheme and address *//*from ww w . java2 s. 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); } }