Example usage for java.net InetSocketAddress getPort

List of usage examples for java.net InetSocketAddress getPort

Introduction

In this page you can find the example usage for java.net InetSocketAddress getPort.

Prototype

public final int getPort() 

Source Link

Document

Gets the port number.

Usage

From source file:eu.stratosphere.sopremo.server.SopremoServer.java

private void startServer() throws IOException {
    final int handlerCount = this.configuration.getInteger(SopremoConstants.SOPREMO_SERVER_HANDLER_COUNT_KEY,
            1);//from  w  w  w.  j a v  a  2s  .  co m
    InetSocketAddress rpcServerAddress = getServerAddress();
    this.server = RPC.getServer(this, rpcServerAddress.getHostName(), rpcServerAddress.getPort(), handlerCount);
    this.server.start();
}

From source file:com.navercorp.pinpoint.collector.receiver.thrift.udp.SpanStreamUDPPacketHandlerFactory.java

private ServerRequest<TBase<?, ?>> newServerRequest(Message<TBase<?, ?>> message,
        InetSocketAddress remoteSocketAddress) {
    final String remoteAddress = remoteSocketAddress.getAddress().getHostAddress();
    final int remotePort = remoteSocketAddress.getPort();

    return new DefaultServerRequest<>(message, remoteAddress, remotePort);
}

From source file:com.amazonaws.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
 *//*w w w  .  j  av a 2  s.  c  o 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:org.scassandra.http.client.CurrentClient.java

public ClosedConnectionReport closeConnection(CloseType closeType, InetSocketAddress address) {
    return closeConnectionsByUrl(closeType,
            "/" + address.getAddress().getHostAddress() + "/" + address.getPort());
}

From source file:org.apache.hadoop.hdfsproxy.ProxyHttpServer.java

/** {@inheritDoc} */
public Connector createBaseListener(Configuration conf) throws IOException {
    final String sAddr;
    if (null == (sAddr = conf.get("proxy.http.test.listener.addr"))) {
        SslSocketConnector sslListener = new SslSocketConnector();
        sslListener.setKeystore(conf.get("ssl.server.keystore.location"));
        sslListener.setPassword(conf.get("ssl.server.keystore.password", ""));
        sslListener.setKeyPassword(conf.get("ssl.server.keystore.keypassword", ""));
        sslListener.setKeystoreType(conf.get("ssl.server.keystore.type", "jks"));
        sslListener.setNeedClientAuth(true);
        System.setProperty("javax.net.ssl.trustStore", conf.get("ssl.server.truststore.location", ""));
        System.setProperty("javax.net.ssl.trustStorePassword", conf.get("ssl.server.truststore.password", ""));
        System.setProperty("javax.net.ssl.trustStoreType", conf.get("ssl.server.truststore.type", "jks"));
        return sslListener;
    }/*  www  .j ava2 s  .  co m*/
    // unit test
    InetSocketAddress proxyAddr = NetUtils.createSocketAddr(sAddr);
    SelectChannelConnector testlistener = new SelectChannelConnector();
    testlistener.setUseDirectBuffers(false);
    testlistener.setHost(proxyAddr.getHostName());
    testlistener.setPort(proxyAddr.getPort());
    return testlistener;
}

From source file:it.anyplace.sync.discovery.utils.AddressRanker.java

private int testTcpConnection(InetSocketAddress socketAddress) {
    return socketAddressScoreCache
            .getUnchecked(Pair.of(socketAddress.getAddress().getHostAddress(), socketAddress.getPort()));
}

From source file:org.jenkinsci.plugins.newrelicnotifier.api.NewRelicClientImpl.java

private CloseableHttpClient getHttpClient(URI url) {
    HttpClientBuilder builder = HttpClientBuilder.create();

    ProxyConfiguration proxyConfig = Jenkins.getInstance().proxy;
    if (proxyConfig != null) {
        Proxy proxy = proxyConfig.createProxy(url.getHost());
        if (proxy != null && proxy.type() == Proxy.Type.HTTP) {
            SocketAddress addr = proxy.address();
            if (addr != null && addr instanceof InetSocketAddress) {
                InetSocketAddress proxyAddr = (InetSocketAddress) addr;
                HttpHost proxyHost = new HttpHost(proxyAddr.getAddress().getHostAddress(), proxyAddr.getPort());
                DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
                builder = builder.setRoutePlanner(routePlanner);

                String proxyUser = proxyConfig.getUserName();
                if (proxyUser != null) {
                    String proxyPass = proxyConfig.getPassword();
                    CredentialsProvider cred = new BasicCredentialsProvider();
                    cred.setCredentials(new AuthScope(proxyHost),
                            new UsernamePasswordCredentials(proxyUser, proxyPass));
                    builder = builder.setDefaultCredentialsProvider(cred)
                            .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
                }//from  ww  w . j  av a2 s . c  o  m
            }
        }
    }

    return builder.build();
}

From source file:org.sonar.ide.intellij.wsclient.WSClientFactory.java

/**
 * Creates new Sonar web service client, which uses proxy settings from IntelliJ.
 *//*ww  w. j  ava 2  s .  co  m*/
private SonarClient createSonarClient(Host host) {
    SonarClient.Builder builder = SonarClient.builder().url(host.getHost()).login(host.getUsername())
            .password(host.getPassword());
    Proxy proxy = getIntelliJProxyFor(host);
    if (proxy != null) {
        InetSocketAddress address = (InetSocketAddress) proxy.address();
        HttpConfigurable proxySettings = HttpConfigurable.getInstance();
        builder.proxy(address.getHostName(), address.getPort());
        if (proxySettings.PROXY_AUTHENTICATION) {
            builder.proxyLogin(proxySettings.PROXY_LOGIN).proxyPassword(proxySettings.getPlainProxyPassword());
        }
    }
    return builder.build();
}

From source file:org.apache.niolex.config.service.impl.ReplicaServiceImpl.java

public void tryConnectToOtherServer(InetSocketAddress addr) {
    /**//from  w ww.  j  a v  a2s .  c  o  m
     * First of all, let's remove localhost from the list.
     */
    if (IP_SET.contains(addr.getAddress()) && localPort == addr.getPort()) {
        return;
    }
    final PacketClient client = new PacketClient();
    otherServers.put(addr.toString(), client);
    LOG.info("Want to connect to {}.", addr);
    client.setConnectTimeout(60000);
    client.setServerAddress(addr);
    ReConnectHandler handler = new ReConnectHandler();
    handler.addHandler(CodeMap.GROUP_DIF, diffHandler);
    handler.addHandler(CodeMap.GROUP_ADD, addHandler);
    client.setPacketHandler(handler);

    // Do try connect in another thread.
    new Thread() {
        public void run() {
            initConnection(client);
        }
    }.start();
}

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());// w  ww. j a v a 2s. 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);
    }
}