Example usage for java.net InetSocketAddress createUnresolved

List of usage examples for java.net InetSocketAddress createUnresolved

Introduction

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

Prototype

public static InetSocketAddress createUnresolved(String host, int port) 

Source Link

Document

Creates an unresolved socket address from a hostname and a port number.

Usage

From source file:com.wso2.rfid.Main.java

public static void main(String[] args) throws IOException {
    Properties configs = new Properties();
    configs.load(/* w  w  w  . j  a v  a  2  s.c om*/
            new FileInputStream(System.getProperty("rpi.agent.home") + File.separator + "config.properties"));

    Server server = new Server(InetSocketAddress.createUnresolved("127.0.0.1", 8084));
    ServletHandler handler = new ServletHandler();
    server.setHandler(handler);
    handler.addServletWithMapping(RFIDReaderServlet.class, "/rfid");
    String controlCenterURL = configs.getProperty("control.center.url");
    System.out.println("Using RPi Control Center: " + controlCenterURL);
    String tokenEndpoint = configs.getProperty("token.endpoint");
    System.out.println("Using token endpoint: " + tokenEndpoint);
    APICall.setTokenEndpoint(tokenEndpoint);
    String primaryNwInterface = configs.getProperty("primary.nw.interface");
    String userRegEndpoint = configs.getProperty("user.registration.endpoint");
    System.out.println("Using user registration endpoint: " + userRegEndpoint);
    APICall.setUserRegistrationEndpoint(userRegEndpoint);
    scheduler.scheduleWithFixedDelay(new MonitoringTask(controlCenterURL, primaryNwInterface), 0, 10,
            TimeUnit.SECONDS);

    try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() throws IOException {
    serverSocket = new ServerSocket();
    serverSocket.setSoTimeout(10000);//  w  w w .  j a  v a2 s .c  o  m

    serverSocket.bind(InetSocketAddress.createUnresolved("java2s.com", 8080), 1000);
}

From source file:Main.java

public Main() throws IOException {
    serverSocket = new ServerSocket(8008, 1000);
    serverSocket.setSoTimeout(10000);//from  ww w. ja  v a2 s.  c o  m

    serverSocket.bind(InetSocketAddress.createUnresolved("java2s.com", 8080), 1000);
}

From source file:com.twitter.distributedlog.client.serverset.DLZkServerSet.java

private static Iterable<InetSocketAddress> getZkAddresses(URI uri) {
    String zkServers = getZKServersFromDLUri(uri);
    String[] zkServerList = StringUtils.split(zkServers, ',');
    ImmutableList.Builder<InetSocketAddress> builder = ImmutableList.builder();
    for (String zkServer : zkServerList) {
        HostAndPort hostAndPort = HostAndPort.fromString(zkServer).withDefaultPort(2181);
        builder.add(InetSocketAddress.createUnresolved(hostAndPort.getHostText(), hostAndPort.getPort()));
    }// ww  w  . ja  v a 2 s.c o m
    return builder.build();
}

From source file:com.mastfrog.scamper.Address.java

public InetSocketAddress toSocketAddress() {
    return InetSocketAddress.createUnresolved(host, port);
}

From source file:com.spotify.apollo.http.server.ApolloRequestHandlerTest.java

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    ServerInfo serverInfo = ServerInfos.create("id", InetSocketAddress.createUnresolved("localhost", 80));

    requestHandler = new ApolloRequestHandler(serverInfo, mockDelegate);

    httpServletRequest = mockRequest("PUT", "http://somehost/a/b?q=abc&b=adf&q=def");
}

From source file:com.subgraph.vega.internal.http.requests.connection.SocksModeClientConnectionOperator.java

@Override
public void openConnection(OperatedClientConnection conn, HttpHost target, InetAddress local,
        HttpContext context, HttpParams params) throws IOException {
    if (!isSocksMode) {
        super.openConnection(conn, target, local, context, params);
        return;//from  w  ww . ja  v  a2  s  . c o  m
    }
    final Scheme scheme = schemeRegistry.getScheme(target.getSchemeName());
    final SchemeSocketFactory sf = scheme.getSchemeSocketFactory();

    final int port = scheme.resolvePort(target.getPort());
    Socket sock = sf.createSocket(params);
    conn.opening(sock, target);
    InetSocketAddress remoteAddress = InetSocketAddress.createUnresolved(target.getHostName(), port);
    InetSocketAddress localAddress = null;
    if (local != null) {
        localAddress = new InetSocketAddress(local, 0);
    }
    try {
        Socket connsock = sf.connectSocket(sock, remoteAddress, localAddress, params);
        if (sock != connsock) {
            sock = connsock;
            conn.opening(sock, target);
        }
        prepareSocket(sock, context, params);
        conn.openCompleted(sf.isSecure(sock), params);
        return;
    } catch (ConnectException ex) {
        throw new HttpHostConnectException(target, ex);
    }
}

From source file:cloudfoundry.norouter.f5.dropsonde.LoggingPoolPopulator.java

public void updateLoggingPool() {
    synchronized (this) {
        final InetSocketAddress poolMember = InetSocketAddress
                .createUnresolved(norouterProperties.getHostAddress(), f5Properties.getLoggingPort());
        final String loggingPoolName = f5Properties.getLoggingPoolName();
        try {/*from www  .java 2  s  .  c  om*/
            final Pool loggingPool = client.getPool(loggingPoolName);
            if (!containsSelf(loggingPool.getMembers(), poolMember)) {
                LOGGER.info("Added member {} to pool {}", poolMember, loggingPoolName);
                client.addPoolMember(loggingPoolName, poolMember);
            }
        } catch (ResourceNotFoundException e) {
            LOGGER.info("Creating pool {} with initial member {}", loggingPoolName, poolMember);
            final Pool pool = Pool.create().name(loggingPoolName).monitor(Monitors.TCP_HALF_OPEN)
                    .addMember(poolMember)
                    .description("Pool used for norouter HSL to forward Dropsonde events to Loggregator.")
                    .build();
            client.createPool(pool);
        }
    }
}

From source file:net.logstash.logback.appender.DestinationParser.java

/**
 * Constructs {@link InetSocketAddress}es by parsing the given {@link String} value.
 * <p>/*from   ww  w . ja  v a 2s .co  m*/
 * The string is a comma separated list of destinations in the form of hostName[:portNumber].
 * <p>
 * 
 * For example, "host1.domain.com,host2.domain.com:5560"
 * <p>
 * 
 * If portNumber is not provided, then the given defaultPort will be used.
 */
public static List<InetSocketAddress> parse(String destinations, int defaultPort) {

    /*
     * Multiple destinations can be specified on one single line, separated by comma
     */
    String[] destinationStrings = StringUtils.split(StringUtils.trimToEmpty(destinations), ',');

    List<InetSocketAddress> destinationList = new ArrayList<InetSocketAddress>(destinationStrings.length);

    for (String entry : destinationStrings) {

        /*
         * For #134, check to ensure properties are defined when destinations
         * are set using properties. 
         */
        if (entry.contains(CoreConstants.UNDEFINED_PROPERTY_SUFFIX)) {
            throw new IllegalArgumentException(
                    "Invalid destination '" + entry + "': unparseable value (expected format 'host[:port]').");
        }

        Matcher matcher = DESTINATION_PATTERN.matcher(entry);
        if (!matcher.matches()) {
            throw new IllegalArgumentException(
                    "Invalid destination '" + entry + "': unparseable value (expected format 'host[:port]').");
        }
        String host = matcher.group(HOSTNAME_GROUP);
        String portString = matcher.group(PORT_GROUP);

        int port;
        try {
            port = (portString != null) ? Integer.parseInt(portString) : defaultPort;

        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(
                    "Invalid destination '" + entry + "': unparseable port (was '" + portString + "').");
        }

        destinationList.add(InetSocketAddress.createUnresolved(host, port));
    }

    return destinationList;
}

From source file:net.sf.zekr.engine.network.NetworkController.java

public Proxy getProxy(String uri) throws URISyntaxException {
    Proxy proxy;//from  w w w .  java2  s  .c o m
    if (SYSTEM_PROXY.equalsIgnoreCase(defaultProxy)) {
        List<Proxy> proxyList = proxySelector.select(new URI(uri));
        proxy = (Proxy) proxyList.get(0);
        if (proxy.address() == null) {
            proxy = Proxy.NO_PROXY;
        }
    } else if (MANUAL_PROXY.equalsIgnoreCase(defaultProxy)) {
        SocketAddress sa = InetSocketAddress.createUnresolved(proxyServer, proxyPort);
        Proxy.Type type = Proxy.Type.HTTP.name().equalsIgnoreCase(proxyType) ? Proxy.Type.HTTP
                : Proxy.Type.SOCKS.name().equalsIgnoreCase(proxyType) ? Proxy.Type.SOCKS : Proxy.Type.DIRECT;
        proxy = new Proxy(type, sa);
    } else {
        proxy = Proxy.NO_PROXY;
    }
    return proxy;
}