Example usage for java.net InetSocketAddress getAddress

List of usage examples for java.net InetSocketAddress getAddress

Introduction

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

Prototype

public final InetAddress getAddress() 

Source Link

Document

Gets the InetAddress .

Usage

From source file:com.dianping.dpsf.jmx.DpsfResponsorMonitor.java

@MBeanMeta(ignore = true)
public Collection<String> requestorsAtPort(int port) {
    Collection<String> requestors = new HashSet<String>();
    RequestProcessor requestProcessor = getRequestProcessor(port);
    if (requestProcessor == null) {
        return Collections.emptySet();
    }//from   w w  w .  ja v  a 2  s .  c o  m
    ChannelGroup serverChannels = requestProcessor.getServerChannels();
    for (Channel channel : serverChannels) {
        InetSocketAddress remoteAddress = (InetSocketAddress) channel.getRemoteAddress();
        requestors.add(remoteAddress.getAddress().getHostAddress() + ":" + remoteAddress.getPort());
    }
    return requestors;
}

From source file:com.ksc.http.conn.ssl.SdkTLSSocketFactory.java

public Socket connectSocket(final int connectTimeout, final Socket socket, final HttpHost host,
        final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpContext context)
        throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("connecting to " + remoteAddress.getAddress() + ":" + remoteAddress.getPort());
    }/*from w ww.  j  a v a 2 s .c  o m*/
    Socket connectedSocket;
    try {
        connectedSocket = super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress,
                context);
        if (!masterSecretValidator.isMasterSecretValid(connectedSocket)) {
            throw log(new IllegalStateException("Invalid SSL master secret"));
        }
    } catch (final SSLException sslEx) {
        if (shouldClearSslSessionsPredicate.test(sslEx)) {
            // clear any related sessions from our cache
            if (LOG.isDebugEnabled()) {
                LOG.debug("connection failed due to SSL error, clearing TLS session cache", sslEx);
            }
            clearSessionCache(sslContext.getClientSessionContext(), remoteAddress);
        }
        throw sslEx;
    }

    if (connectedSocket instanceof SSLSocket) {
        SdkSSLSocket sslSocket = new SdkSSLSocket((SSLSocket) connectedSocket);
        return KscSdkMetrics.isHttpSocketReadMetricEnabled() ? new SdkSSLMetricsSocket(sslSocket) : sslSocket;
    }
    SdkSocket sdkSocket = new SdkSocket(connectedSocket);
    return KscSdkMetrics.isHttpSocketReadMetricEnabled() ? new SdkMetricsSocket(sdkSocket) : sdkSocket;
}

From source file:com.ngdata.sep.impl.SepConsumer.java

/**
 * @param subscriptionTimestamp timestamp of when the index subscription became active (or more accurately, not
 *        inactive)/*w ww  . jav a 2  s.c om*/
 * @param listener listeners that will process the events
 * @param threadCnt number of worker threads that will handle incoming SEP events
 * @param hostName hostname to bind to
 * @param payloadExtractor extracts payloads to include in SepEvents
 */
public SepConsumer(String subscriptionId, long subscriptionTimestamp, EventListener listener, int threadCnt,
        String hostName, ZooKeeperItf zk, Configuration hbaseConf, PayloadExtractor payloadExtractor)
        throws IOException, InterruptedException {
    Preconditions.checkArgument(threadCnt > 0, "Thread count must be > 0");
    this.subscriptionId = SepModelImpl.toInternalSubscriptionName(subscriptionId);
    this.subscriptionTimestamp = subscriptionTimestamp;
    this.listener = listener;
    this.zk = zk;
    this.hbaseConf = hbaseConf;
    this.sepMetrics = new SepMetrics(subscriptionId);
    this.payloadExtractor = payloadExtractor;
    this.executors = Lists.newArrayListWithCapacity(threadCnt);

    InetSocketAddress initialIsa = new InetSocketAddress(hostName, 0);
    if (initialIsa.getAddress() == null) {
        throw new IllegalArgumentException("Failed resolve of " + initialIsa);
    }
    String name = "regionserver/" + initialIsa.toString();
    this.rpcServer = new RpcServer(this, name, getServices(),
            /*HBaseRPCErrorHandler.class, OnlineRegions.class},*/
            initialIsa, // BindAddress is IP we got for this server.
            hbaseConf.getInt("hbase.regionserver.handler.count", 10),
            hbaseConf.getInt("hbase.regionserver.metahandler.count", 10), hbaseConf, HConstants.QOS_THRESHOLD);
    this.serverName = new ServerName(hostName, rpcServer.getListenerAddress().getPort(),
            System.currentTimeMillis());
    this.zkWatcher = new ZooKeeperWatcher(hbaseConf, this.serverName.toString(), null);

    // login the zookeeper client principal (if using security)
    ZKUtil.loginClient(hbaseConf, "hbase.zookeeper.client.keytab.file",
            "hbase.zookeeper.client.kerberos.principal", hostName);

    // login the server principal (if using secure Hadoop)
    User.login(hbaseConf, "hbase.regionserver.keytab.file", "hbase.regionserver.kerberos.principal", hostName);

    for (int i = 0; i < threadCnt; i++) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(100));
        executor.setRejectedExecutionHandler(new WaitPolicy());
        executors.add(executor);
    }
}

From source file:reactor.ipc.netty.tcp.TcpServerTests.java

@Test
public void exposesRemoteAddress() throws InterruptedException {
    final int port = SocketUtils.findAvailableTcpPort();
    final CountDownLatch latch = new CountDownLatch(1);

    NettyContext server = TcpServer.create(port).newHandler((in, out) -> {
        InetSocketAddress remoteAddr = in.remoteAddress();
        assertNotNull("remote address is not null", remoteAddr.getAddress());
        latch.countDown();/*www  . j ava  2  s  . c  o  m*/

        return Flux.never();
    }).block(Duration.ofSeconds(30));

    NettyContext client = TcpClient.create(port)
            .newHandler((in, out) -> out.sendString(Flux.just("Hello World!"))).block(Duration.ofSeconds(30));

    assertTrue("latch was counted down", latch.await(5, TimeUnit.SECONDS));

    client.dispose();
    server.dispose();
}

From source file:edu.umass.cs.reconfiguration.deprecated.ReconfigurableClientCreateTester.java

private InetSocketAddress getFirstRCReplica() {
    InetSocketAddress address = this.getReconfigurators().iterator().next();
    return new InetSocketAddress(address.getAddress(), ActiveReplica.getClientFacingPort(address.getPort()));
}

From source file:be.vlaanderen.sesam.proxy.internal.http.actors.WfsGetFeatureLoggingActor.java

private void logRequest(Conversation c, String request) {
    InetSocketAddress addr = (InetSocketAddress) c.getHandler().getInboundChannel().getRemoteAddress();

    StringBuilder sb = new StringBuilder();
    sb.append(DATEFORMATTER.format(new Date()));
    sb.append(" ");
    sb.append(addr.getAddress().getHostAddress());
    sb.append(" ");
    sb.append(c.getRequest().getMethod().getName());
    sb.append(" ");
    sb.append(request);/*www  . j  a v  a2 s  .  c om*/

    commlog.info(sb.toString());
}

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

/**
 * Substitute a default host in the case that an address has been configured
 * with a wildcard. This is used, for example, when determining the HTTP
 * address of the NN -- if it's configured to bind to 0.0.0.0, we want to
 * substitute the hostname from the filesystem URI rather than trying to
 * connect to 0.0.0.0./*from ww w . j  ava2s  . c o  m*/
 *
 * @param configuredAddress
 *     the address found in the configuration
 * @param defaultHost
 *     the host to substitute with, if configuredAddress
 *     is a local/wildcard address.
 * @return the substituted address
 * @throws IOException
 *     if it is a wildcard address and security is enabled
 */
@VisibleForTesting
public static String substituteForWildcardAddress(String configuredAddress, String defaultHost)
        throws IOException {
    InetSocketAddress sockAddr = NetUtils.createSocketAddr(configuredAddress);
    InetSocketAddress defaultSockAddr = NetUtils.createSocketAddr(defaultHost + ":0");
    final InetAddress addr = sockAddr.getAddress();
    if (addr != null && addr.isAnyLocalAddress()) {
        if (UserGroupInformation.isSecurityEnabled() && defaultSockAddr.getAddress().isAnyLocalAddress()) {
            throw new IOException("Cannot use a wildcard address with security. "
                    + "Must explicitly set bind address for Kerberos");
        }
        return defaultHost + ":" + sockAddr.getPort();
    } else {
        return configuredAddress;
    }
}

From source file:org.apache.tajo.master.ha.HAServiceHDFSImpl.java

private void createMasterFile(boolean isActive) throws IOException {
    String fileName = masterName.replaceAll(":", "_");
    Path path = null;/*  w w w. ja v a2s . c o m*/

    if (isActive) {
        path = new Path(activePath, fileName);
    } else {
        path = new Path(backupPath, fileName);
    }

    StringBuilder sb = new StringBuilder();
    InetSocketAddress address = getHostAddress(HAConstants.MASTER_CLIENT_RPC_ADDRESS);
    sb.append(address.getAddress().getHostAddress()).append(":").append(address.getPort()).append("_");

    address = getHostAddress(HAConstants.RESOURCE_TRACKER_RPC_ADDRESS);
    sb.append(address.getAddress().getHostAddress()).append(":").append(address.getPort()).append("_");

    address = getHostAddress(HAConstants.CATALOG_ADDRESS);
    sb.append(address.getAddress().getHostAddress()).append(":").append(address.getPort()).append("_");

    address = getHostAddress(HAConstants.MASTER_INFO_ADDRESS);
    sb.append(address.getAddress().getHostAddress()).append(":").append(address.getPort());

    FSDataOutputStream out = fs.create(path);

    try {
        out.writeUTF(sb.toString());
        out.hflush();
        out.close();
    } catch (FileAlreadyExistsException e) {
        createMasterFile(false);
    }

    if (isActive) {
        isActiveStatus = true;
    } else {
        isActiveStatus = false;
    }

    startPingChecker();
}

From source file:be.vlaanderen.sesam.monitor.MonitorTask.java

public void run() {
    if (running.get()) {
        // Do not run (the same instance) concurrent (has state).
        log.warn("Task: " + getName() + " is still running! (skipping)");
        return;//from   w ww .  j av a2 s  .  c o  m

    } else {
        running.set(true);
        start = System.currentTimeMillis();
        timewaited = 0;

        try {
            log.debug("Running task: " + getName());

            InetSocketAddress addr = new InetSocketAddress(getRequestHostname(), getRequestPort());
            if (addr.getAddress() == null) {
                logResult(NOTIFICATIONTYPE_EXCEPTION,
                        "Kon ip-adres van host niet vinden, foute hostnaam of niet in DNS? (Host: "
                                + getRequestHostname() + ")");
                running.set(false);

            } else {
                OutboundHandler out = new OutboundHandler();
                ChannelFuture cf = clientService.createClientChannel(out, addr, getResponseTimeoutMillis());
                boolean res = cf.awaitUninterruptibly(getResponseTimeoutMillis());
                if (res) {
                    timewaited = System.currentTimeMillis() - start;
                    if (cf.isSuccess()) {
                        out.sendRequest(cf.getChannel());
                    } // else is handled by exceptioncaught
                } else {
                    logResult(NOTIFICATIONTYPE_TIMEOUT);
                    cf.cancel();
                    running.set(false);
                }
            }
        } catch (Exception e) {
            logResult(NOTIFICATIONTYPE_EXCEPTION, e.getMessage());
            running.set(false);
        }
    }
}