Example usage for java.net InetSocketAddress toString

List of usage examples for java.net InetSocketAddress toString

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Constructs a string representation of this InetSocketAddress.

Usage

From source file:com.zimbra.common.httpclient.HttpProxyConfig.java

public static ProxyHostConfiguration getProxyConfig(HostConfiguration hc, String uriStr) {
    if (!LC.client_use_system_proxy.booleanValue())
        return null;

    URI uri = null;//  w w w  .  j ava  2  s  .  c  om
    try {
        uri = new URI(uriStr);
    } catch (URISyntaxException x) {
        ZimbraLog.net.info(uriStr, x);
        return null;
    }

    //no need to filter out localhost as the DefaultProxySelector will do that.

    List<Proxy> proxies = ProxySelectors.defaultProxySelector().select(uri);
    for (Proxy proxy : proxies) {
        switch (proxy.type()) {
        case DIRECT:
            return null;
        case HTTP:
            InetSocketAddress addr = (InetSocketAddress) proxy.address();
            if (ZimbraLog.net.isDebugEnabled()) {
                ZimbraLog.net.debug("URI %s to use HTTP proxy %s", safePrint(uri), addr.toString());
            }
            ProxyHostConfiguration nhc = new ProxyHostConfiguration(hc);
            nhc.setProxy(addr.getHostName(), addr.getPort());
            if (proxy instanceof AuthProxy) {
                nhc.setUsername(((AuthProxy) proxy).getUsername());
                nhc.setPassword(((AuthProxy) proxy).getPassword());
            }
            return nhc;
        case SOCKS: //socks proxy can be handled at socket factory level
        default:
            continue;
        }
    }
    return null;
}

From source file:net.sbbi.upnp.jmx.UPNPMBeanDevicesRequestsHandler.java

public final static UPNPMBeanDevicesRequestsHandler getInstance(InetSocketAddress bindAddress) {
    String key = bindAddress.toString();
    synchronized (instances) {
        UPNPMBeanDevicesRequestsHandler handler = (UPNPMBeanDevicesRequestsHandler) instances.get(key);
        if (handler == null) {
            handler = new UPNPMBeanDevicesRequestsHandler(bindAddress);
            instances.put(key, handler);
        }/*from w  w  w .  j a v a2  s .  c  o  m*/
        return handler;
    }
}

From source file:com.uber.stream.kafka.mirrormaker.controller.reporter.HelixKafkaMirrorMakerMetricsReporter.java

static Graphite getGraphite(ControllerConf config) {
    if (config.getGraphiteHost() == null || config.getGraphitePort() == 0) {
        LOGGER.warn("No Graphite built!");
        return null;
    }//  ww w  . ja  v  a2 s . c o  m
    InetSocketAddress graphiteAddress = new InetSocketAddress(config.getGraphiteHost(),
            config.getGraphitePort());
    LOGGER.info(String.format("Trying to connect to Graphite with address: %s", graphiteAddress.toString()));
    return new Graphite(graphiteAddress);
}

From source file:com.github.mrstampy.kitchensync.message.KiSyMessageCreator.java

/**
 * Creates the ping time message.// ww  w  . j a  v a  2s.c o m
 *
 * @param originator
 *          the originator
 * @param destination
 *          the destination
 * @param pingTime
 *          the ping time
 * @return the ki sy message
 */
public static KiSyMessage createPingTime(InetSocketAddress originator, InetSocketAddress destination,
        Long pingTime) {
    log.trace("PingTime, originator = {}, destination = {}, pingTime = {}", originator, destination, pingTime);

    KiSyMessage message = new KiSyMessage(originator, KiSyMessageType.PING_TIME);

    message.addMessagePart("destination", destination.toString());
    message.addMessagePart("pingTime", KiSyUtils.toMillis(pingTime));

    return message;
}

From source file:org.apache.hadoop.hbase.thrift2.ThriftServer.java

private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory, THBaseService.Processor processor,
        TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws TTransportException {
    TServerTransport serverTransport = new TServerSocket(inetSocketAddress);
    log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
    serverArgs.processor(processor);// w w w  .  j  a  v  a  2s  .  c  om
    serverArgs.transportFactory(transportFactory);
    serverArgs.protocolFactory(protocolFactory);
    return new TThreadPoolServer(serverArgs);
}

From source file:org.apache.hadoop.hbase.thrift2.ThriftServer.java

private static TServer getTNonBlockingServer(TProtocolFactory protocolFactory,
        THBaseService.Processor processor, TTransportFactory transportFactory,
        InetSocketAddress inetSocketAddress) throws TTransportException {
    TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
    log.info("starting HBase Nonblocking Thrift server on " + inetSocketAddress.toString());
    TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport);
    serverArgs.processor(processor);//from   w w  w  .j  av a  2 s .co  m
    serverArgs.transportFactory(transportFactory);
    serverArgs.protocolFactory(protocolFactory);
    return new TNonblockingServer(serverArgs);
}

From source file:net.sbbi.upnp.jmx.UPNPMBeanDevicesDiscoveryHandler.java

public final static UPNPMBeanDevicesDiscoveryHandler getInstance(InetSocketAddress bindAddress) {
    String key = bindAddress.toString();
    synchronized (instances) {
        UPNPMBeanDevicesDiscoveryHandler handler = (UPNPMBeanDevicesDiscoveryHandler) instances.get(key);
        if (handler == null) {
            handler = new UPNPMBeanDevicesDiscoveryHandler(bindAddress);
            instances.put(key, handler);
        }//  www. j a v a 2  s . co  m
        return handler;
    }
}

From source file:org.apache.hadoop.hbase.thrift2.ThriftServer.java

private static TServer getTHsHaServer(TProtocolFactory protocolFactory, THBaseService.Processor processor,
        TTransportFactory transportFactory, InetSocketAddress inetSocketAddress, ThriftMetrics metrics)
        throws TTransportException {
    TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
    log.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString());
    THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);
    ExecutorService executorService = createExecutor(serverArgs.getWorkerThreads(), metrics);
    serverArgs.executorService(executorService);
    serverArgs.processor(processor);/*from ww  w. ja  va  2 s  . co m*/
    serverArgs.transportFactory(transportFactory);
    serverArgs.protocolFactory(protocolFactory);
    return new THsHaServer(serverArgs);
}

From source file:com.alibaba.wasp.ipc.WaspRPC.java

/**
 * @param retries//from ww w .j  a  v a 2 s  .co m
 *          current retried times.
 * @param maxAttmpts
 *          max attempts
 * @param protocol
 *          protocol interface
 * @param addr
 *          address of remote service
 * @param ce
 *          ConnectException
 * @throws org.apache.hadoop.hbase.client.RetriesExhaustedException
 */
private static void handleConnectionException(int retries, int maxAttmpts, Class<?> protocol,
        InetSocketAddress addr, ConnectException ce) throws RetriesExhaustedException {
    if (maxAttmpts >= 0 && retries >= maxAttmpts) {
        LOG.info("Server at " + addr + " could not be reached after " + maxAttmpts + " tries, giving up.");
        throw new RetriesExhaustedException("Failed setting up proxy " + protocol + " to " + addr.toString()
                + " after attempts=" + maxAttmpts, ce);
    }
}

From source file:org.apache.hadoop.hdfs.client.impl.BlockReaderTestUtil.java

/**
 * Get a BlockReader for the given block.
 *///from w  ww. java2  s  .  c om
public static BlockReader getBlockReader(final DistributedFileSystem fs, LocatedBlock testBlock, int offset,
        long lenToRead) throws IOException {
    InetSocketAddress targetAddr = null;
    ExtendedBlock block = testBlock.getBlock();
    DatanodeInfo[] nodes = testBlock.getLocations();
    targetAddr = NetUtils.createSocketAddr(nodes[0].getXferAddr());

    return new BlockReaderFactory(fs.getClient().getConf()).setInetSocketAddress(targetAddr).setBlock(block)
            .setFileName(targetAddr.toString() + ":" + block.getBlockId())
            .setBlockToken(testBlock.getBlockToken()).setStartOffset(offset).setLength(lenToRead)
            .setVerifyChecksum(true).setClientName("BlockReaderTestUtil").setDatanodeInfo(nodes[0])
            .setClientCacheContext(ClientContext.getFromConf(fs.getConf()))
            .setCachingStrategy(CachingStrategy.newDefaultStrategy()).setConfiguration(fs.getConf())
            .setAllowShortCircuitLocalReads(true).setTracer(FsTracer.get(fs.getConf()))
            .setRemotePeerFactory(new RemotePeerFactory() {
                @Override
                public Peer newConnectedPeer(InetSocketAddress addr, Token<BlockTokenIdentifier> blockToken,
                        DatanodeID datanodeId) throws IOException {
                    Peer peer = null;
                    Socket sock = NetUtils.getDefaultSocketFactory(fs.getConf()).createSocket();
                    try {
                        sock.connect(addr, HdfsConstants.READ_TIMEOUT);
                        sock.setSoTimeout(HdfsConstants.READ_TIMEOUT);
                        peer = DFSUtilClient.peerFromSocket(sock);
                    } finally {
                        if (peer == null) {
                            IOUtils.closeQuietly(sock);
                        }
                    }
                    return peer;
                }
            }).build();
}