Example usage for java.net InetSocketAddress InetSocketAddress

List of usage examples for java.net InetSocketAddress InetSocketAddress

Introduction

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

Prototype

private InetSocketAddress(int port, String hostname) 

Source Link

Usage

From source file:com.kappaware.logtrawler.adminserver.AdminServer.java

public AdminServer(Config config, Map<String, AgentHandler> agentHandlerByName) throws Exception {
    InetSocketAddress bindAddr = null;
    try {//from  w w w . ja v a 2s.  com
        String[] endp = config.getAdminEndpoint().split(":");
        if (endp.length != 2) {
            throw new Exception("");
        }
        int port = Integer.parseInt(endp[1]);
        bindAddr = new InetSocketAddress(endp[0], port);

    } catch (Throwable t) {
        throw new ConfigurationException(
                String.format("Missing or invalid admin endpoint:%s", config.getAdminEndpoint()));
    }

    this.server = new Server(bindAddr);

    IpMatcherImpl ipMatcher = new IpMatcherImpl();
    for (String segmentDef : config.getAdminAllowedNetwork()) {
        ipMatcher.addSegment(segmentDef);
    }
    AdminHandler adminHandler = new AdminHandler();
    adminHandler.register(HttpMethod.GET, "/config", new ConfigRequestHandler(config, ipMatcher));
    adminHandler.register(HttpMethod.GET,
            String.format("/([\\w]+)/(%s|%s|%s|%s|%s|%s)", Stats.Mode.all, Stats.Mode.stats, Stats.Mode.zombies,
                    Stats.Mode.actives, Stats.Mode.files, Stats.Mode.evictions),
            new StatsRequestHandler(agentHandlerByName, ipMatcher));
    server.setHandler(adminHandler);

    server.start();
    AbstractNetworkConnector anc = (AbstractNetworkConnector) (server.getConnectors()[0]);
    log.info(String.format("Admin REST server bound at %s:%d", anc.getHost(), anc.getLocalPort()));
}

From source file:fm.last.moji.FakeMogileFsServer.java

public InetSocketAddress getInetSocketAddress() {
    return new InetSocketAddress(trackerSocket.getInetAddress().getHostName(), trackerSocket.getLocalPort());
}

From source file:com.zimbra.common.net.ProtocolSocketFactoryWrapper.java

@Override
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException {
    int timeout = params != null ? params.getConnectionTimeout() : 0;
    if (timeout > 0) {
        Socket sock = factory.createSocket();
        sock.bind(new InetSocketAddress(localAddress, localPort));
        sock.connect(new InetSocketAddress(host, port), timeout);
        return sock;
    } else {//from  w  w w .j a v a2s.c o  m
        return factory.createSocket(host, port, localAddress, localPort);
    }
}

From source file:SocketAddressEncoder.java

public static InetSocketAddress decode(String str) throws UnknownHostException {
    StringTokenizer st = new StringTokenizer(str, ",");
    if (st.countTokens() != 6) {
        throw new Exception("Illegal amount of tokens");
    }/*from  w w w  . j  a  v  a 2s .  c o  m*/

    StringBuffer sb = new StringBuffer();
    try {
        sb.append(convertAndValidateNumber(st.nextToken()));
        sb.append('.');
        sb.append(convertAndValidateNumber(st.nextToken()));
        sb.append('.');
        sb.append(convertAndValidateNumber(st.nextToken()));
        sb.append('.');
        sb.append(convertAndValidateNumber(st.nextToken()));
    } catch (IllegalArgumentException e) {
        throw new Exception(e.getMessage());
    }

    InetAddress dataAddr = InetAddress.getByName(sb.toString());

    // get data server port
    int dataPort = 0;
    try {
        int hi = convertAndValidateNumber(st.nextToken());
        int lo = convertAndValidateNumber(st.nextToken());
        dataPort = (hi << 8) | lo;
    } catch (IllegalArgumentException ex) {
        throw new Exception("Invalid data port: " + str);
    }

    return new InetSocketAddress(dataAddr, dataPort);
}

From source file:io.github.bonigarcia.wdm.Downloader.java

public static Proxy createProxy() {
    String proxyString = System.getenv("HTTPS_PROXY");
    if (proxyString == null || proxyString.length() < 1)
        proxyString = System.getenv("HTTP_PROXY");
    if (proxyString == null || proxyString.length() < 1) {
        return null;
    }//  www . j a v a 2 s. c om
    proxyString = proxyString.replace("http://", "");
    proxyString = proxyString.replace("https://", "");
    StringTokenizer st = new StringTokenizer(proxyString, ":");
    if (st.countTokens() != 2)
        return null;
    String host = st.nextToken();
    String portString = st.nextToken();
    try {
        int port = Integer.parseInt(portString);
        return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:io.netlibs.bgp.config.nodes.impl.ClientConfigurationImpl.java

public ClientConfigurationImpl(final InetAddress addr, final int port) throws ConfigurationException {
    if (addr == null) {
        throw new ConfigurationException("null remote address not allowed");
    }//from   w w w .j  av  a2  s  . c om
    if (addr.isAnyLocalAddress()) {
        throw new ConfigurationException("wildcard remote address not allowed");
    }
    if ((port < 0) || (port > 65535)) {
        throw new ConfigurationException("port " + port + " not allowed");
    }

    this.remoteAddress = new InetSocketAddress(addr, port);
}

From source file:ca.viaware.dlna.streamserver.StreamServer.java

public StreamServer() throws IOException {
    JSONObject config = SettingsManager.getServerConfig().getJSONObject("streamServer");
    this.server = HttpServer.create(new InetSocketAddress(config.getString("host"), config.getInt("port")), 8);
}

From source file:com.diaw.lib.tool.FakeSocketFactory.java

public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException {
    final int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    final int soTimeout = HttpConnectionParams.getSoTimeout(params);

    final InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    final SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
        // we need to bind explicitly
        if (localPort < 0) {
            localPort = 0; // indicates "any"
        }//from   w  ww.  j  a va 2 s.  co m
        final InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);

    return sslsock;
}

From source file:iddb.runtime.cache.impl.CacheImpl.java

public CacheImpl() throws UnavailableCacheException {
    Properties props = new Properties();
    try {//from www  .jav  a  2s . c o  m
        props.load(getClass().getClassLoader().getResourceAsStream("memcache.properties"));
        client = new MemcachedClient(
                new InetSocketAddress(props.getProperty("host"), Integer.parseInt(props.getProperty("port"))));
        if (props.containsKey("expiration"))
            expiration = Integer.parseInt(props.getProperty("expiration"));
        if (props.containsKey("prefix"))
            prefix = props.getProperty("prefix");
        else
            prefix = "ipdb";
    } catch (Exception e) {
        log.error("Unable to load cache properties [{}]", e.getMessage());
        throw new UnavailableCacheException();
    }
    setNamespace("default");
    log.debug("Initialized memcache instance.");
}

From source file:is.artefact.flume.source.kafka.KafkaSourceEmbeddedZookeeper.java

public KafkaSourceEmbeddedZookeeper(int zkPort) {
    int tickTime = 2000;

    this.zkPort = zkPort;

    String dataDirectory = System.getProperty("java.io.tmpdir");
    dir = new File(dataDirectory, "zookeeper" + UUID.randomUUID()).getAbsoluteFile();

    try {//from   www  .jav  a2  s. c  om
        FileUtils.deleteDirectory(dir);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    try {
        this.zookeeper = new ZooKeeperServer(dir, dir, tickTime);
        this.factory = new NIOServerCnxnFactory();
        factory.configure(new InetSocketAddress(KafkaSourceEmbeddedKafka.HOST, zkPort), 0);
        factory.startup(zookeeper);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}