List of usage examples for java.net InetSocketAddress InetSocketAddress
private InetSocketAddress(int port, String hostname)
From source file:io.pravega.segmentstore.storage.impl.bookkeeper.ZooKeeperServiceRunner.java
/** * Starts the ZooKeeper Service in process. * * @throws Exception If an exception occurred. */// www . java 2 s. c o m public void start() throws Exception { this.tmpDir = IOUtils.createTempDir("zookeeper", "inproc"); this.tmpDir.deleteOnExit(); val s = new ZooKeeperServer(this.tmpDir, this.tmpDir, ZooKeeperServer.DEFAULT_TICK_TIME); this.server.set(s); val serverFactory = new NIOServerCnxnFactory(); val address = LOOPBACK_ADDRESS.getHostAddress() + ":" + this.zkPort; log.info("Starting Zookeeper server at " + address + " ..."); serverFactory.configure(new InetSocketAddress(LOOPBACK_ADDRESS, this.zkPort), 1000); serverFactory.startup(s); boolean b = LocalBookKeeper.waitForServerUp(address, LocalBookKeeper.CONNECTION_TIMEOUT); log.info("ZooKeeper server {}.", b ? "up" : "not up"); }
From source file:com.sun.faban.driver.transport.hc3.ProtocolTimedSocketFactory.java
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort, HttpConnectionParams params) throws IOException { if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); }/*from w ww .j a va 2 s . c o m*/ int timeout = params.getConnectionTimeout(); if (timeout == 0) { return createSocket(host, port, localAddress, localPort); } else { TimedSocket socket = new TimedSocket(); socket.bind(new InetSocketAddress(localAddress, localPort)); socket.connect(new InetSocketAddress(host, port), timeout); return socket; } }
From source file:com.smartwork.client.gsocket.CommonSocketFactory.java
public Object makeObject(Object key) throws Exception { ServerAddress address = (ServerAddress) key; Socket conn = new Socket(); conn.setSoTimeout(networkConfig.getReadTimeout() * 1000); conn.setTcpNoDelay(networkConfig.isTcpNoDelay()); conn.setReuseAddress(networkConfig.isReuseAddress()); conn.setSoLinger(networkConfig.getSoLinger() > 0, networkConfig.getSoLinger()); conn.setSendBufferSize(networkConfig.getSendBufferSize()); conn.setReceiveBufferSize(networkConfig.getReceiveBufferSize()); conn.connect(new InetSocketAddress(address.getHost(), address.getPort()), networkConfig.getConnectTimeout() * 1000); return conn;//from w ww. j a v a 2 s. c om }
From source file:com.hellblazer.jackal.configuration.basic.LocalGossipConfiguration.java
@Bean(name = "connectionSetEndpoint") public InetSocketAddress connectionSetEndpoint() { return new InetSocketAddress("127.0.0.1", 0); }
From source file:com.barchart.http.handlers.TestCancellableRequestHandler.java
@Before public void setUp() throws Exception { server = new HttpServer(); basic = new TestRequestHandler("basic", false, 0, 0, false); async = new TestRequestHandler("async", true, 0, 0, false); asyncDelayed = new TestRequestHandler("async-delayed", true, 50, 0, false); clientDisconnect = new TestRequestHandler("client-disconnect", true, 500, 500, false); error = new TestRequestHandler("error", false, 0, 0, true); final HttpServerConfig config = new HttpServerConfig().requestHandler("/basic", basic) .address(new InetSocketAddress("localhost", 8888)).parentGroup(new NioEventLoopGroup(1)) .childGroup(new NioEventLoopGroup(1)).requestHandler("/async", async) .requestHandler("/async-delayed", asyncDelayed) .requestHandler("/client-disconnect", clientDisconnect).requestHandler("/error", error) .maxConnections(1);//w w w . ja va 2 s. c om server.configure(config).listen().sync(); client = new DefaultHttpClient(new PoolingClientConnectionManager()); }
From source file:com.pinterest.pinlater.client.PinLaterClient.java
public PinLaterClient(String host, int port, int concurrency) { this.service = ClientBuilder.safeBuild(ClientBuilder.get().hosts(new InetSocketAddress(host, port)) .codec(ThriftClientFramedCodec.apply(Option.apply(new ClientId("pinlaterclient")))) .hostConnectionLimit(concurrency).tcpConnectTimeout(Duration.apply(2, TimeUnit.SECONDS)) .requestTimeout(Duration.apply(10, TimeUnit.SECONDS)).retries(1)); this.iface = new PinLater.ServiceToClient(service, new TBinaryProtocol.Factory()); }
From source file:nl.phanos.liteliveresultsclient.LoginHandler.java
public static boolean isReachable() { // Any Open port on other machine // openPort = 22 - ssh, 80 or 443 - webserver, 25 - mailserver etc. try {//from w w w .j a v a 2 s .c o m try (Socket soc = new Socket()) { soc.connect(new InetSocketAddress("www.atletiek.nu", 80), 2000); } return true; } catch (IOException ex) { return false; } }
From source file:com.flipkart.phantom.thrift.impl.proxy.SocketObjectFactory.java
/** * Interface method implementation. Creates and returns a new {@link java.net.Socket} * @see org.apache.commons.pool.PoolableObjectFactory#makeObject() *///from w ww . j a v a2 s .c om public Socket makeObject() throws Exception { Socket socket = new Socket(); socket.setSoTimeout(this.getThriftProxy().getThriftTimeoutMillis()); socket.connect(new InetSocketAddress(this.getThriftProxy().getThriftServer(), this.getThriftProxy().getThriftPort())); LOGGER.info("Creating a new socket for server : {} at port : {}", this.getThriftProxy().getThriftServer(), this.getThriftProxy().getThriftPort()); return socket; }
From source file:org.ttrssreader.net.deprecated.FakeSocketFactory.java
@Override public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException { int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); InetSocketAddress remoteAddress = new InetSocketAddress(host, port); 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 w w . j a v a 2s .c o m*/ InetSocketAddress isa = new InetSocketAddress(localAddress, localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress, connTimeout); sslsock.setSoTimeout(soTimeout); return sslsock; }
From source file:cf.client.model.ApplicationInstance.java
@JsonCreator public ApplicationInstance(@JsonProperty("state") String state, @JsonProperty("since") double since, @JsonProperty("debug_ip") String debugIp, @JsonProperty("debug_port") Integer debugPort, @JsonProperty("console_ip") String consoleIp, @JsonProperty("console_port") Integer consolePort) { State stateValue = null;//from w w w . j a v a2 s .c o m try { stateValue = State.valueOf(state.toUpperCase()); } catch (IllegalArgumentException e) { stateValue = State.UNKNOWN; } this.state = stateValue; this.since = new Date((long) Math.floor(since * 1000)); this.debugAddress = (debugIp == null || debugPort == null) ? null : new InetSocketAddress(debugIp, debugPort); this.consoleAddress = (consoleIp == null || consolePort == null) ? null : new InetSocketAddress(consoleIp, consolePort); }