List of usage examples for java.net ServerSocket close
public void close() throws IOException
From source file:org.apache.hadoop.hbase.TestIPv6NIOServerSocketChannel.java
/** * Creates and binds a regular ServerSocket. *///from w w w.j a v a 2 s .c o m private void bindServerSocket(InetAddress inetAddr) throws IOException { while (true) { int port = HBaseTestingUtility.randomFreePort(); InetSocketAddress addr = new InetSocketAddress(inetAddr, port); ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(); serverSocket.bind(addr); break; } catch (BindException ex) { //continue } finally { if (serverSocket != null) { serverSocket.close(); } } } }
From source file:com.kixeye.janus.client.http.rest.DefaultRestHttpClientTest.java
@Before public void setUp() throws Exception { ConfigurationManager.getConfigInstance().setProperty("janus.errorThresholdPerSec", 3); ConfigurationManager.getConfigInstance().setProperty("janus.shortCircuitDuration", 1000); ConfigurationManager.getConfigInstance().setProperty("janus.refreshIntervalInMillis", 500); Server server = new ContainerServer(forwardingServerContainer); server1Connection = new SocketConnection(server); ServerSocket socketServer = new ServerSocket(0); server1Port = socketServer.getLocalPort(); socketServer.close(); server1Connection.connect(new InetSocketAddress(server1Port)); server = new ContainerServer(forwardingServerContainer); server2Connection = new SocketConnection(server); socketServer = new ServerSocket(0); server2Port = socketServer.getLocalPort(); socketServer.close();/* w w w. j a v a 2 s.c om*/ server2Connection.connect(new InetSocketAddress(server2Port)); }
From source file:org.apache.hadoop.ipc.TestServer.java
@Test public void testEmptyConfig() throws Exception { Configuration conf = new Configuration(); conf.set("TestRange", ""); ServerSocket socket = new ServerSocket(); InetSocketAddress address = new InetSocketAddress("0.0.0.0", 0); try {/*w w w. j a v a2 s .c om*/ Server.bind(socket, address, 10, conf, "TestRange"); assertTrue(socket.isBound()); } finally { socket.close(); } }
From source file:org.apache.servicemix.jbi.cluster.engine.AbstractClusterEndpointTest.java
protected int findFreePort() { int port = 61616; try {// w w w .j a v a2 s.c om ServerSocket ss = new ServerSocket(0); port = ss.getLocalPort(); ss.close(); } catch (Exception e) { } return port; }
From source file:com.barchart.netty.server.http.TestHttpServer.java
@Before public void setUp() throws Exception { basic = new TestRequestHandler("basic", false, 0, 0, false, false); async = new TestRequestHandler("async", true, 0, 0, false, false); asyncDelayed = new TestRequestHandler("async-delayed", true, 50, 0, false, false); clientDisconnect = new TestRequestHandler("", true, 500, 500, false, false); error = new TestRequestHandler("error", false, 0, 0, true, false); channelError = new TestRequestHandler("channel-error", false, 0, 0, false, true); infoHandler = new TestRequestHandler("info", false, 0, 0, false, false); serviceHandler = new TestRequestHandler("service", false, 0, 0, false, false); chunkedHandler = new ChunkedRequestHandler("chunked"); final ServerSocket s = new ServerSocket(0); port = s.getLocalPort();/*from w ww .j a v a 2s . c o m*/ s.close(); Thread.sleep(100); server = Servers.createHttpServer().requestHandler("/basic", basic).group(new NioEventLoopGroup(1)) .requestHandler("/async", async).requestHandler("/async-delayed", asyncDelayed) .requestHandler("/client-disconnect", clientDisconnect) .requestHandler("/channel-error", channelError).requestHandler("/error", error) .requestHandler("/service/info", infoHandler).requestHandler("/service", serviceHandler) .requestHandler("/chunked", chunkedHandler).maxConnections(1); server.listen(port, "localhost").sync(); connMgr = new PoolingClientConnectionManager(); client = new DefaultHttpClient(connMgr); }
From source file:com.nokia.dempsy.messagetransport.tcp.TcpReceiver.java
private void closeQuietly(ServerSocket socket) { if (socket != null) { try {//from w w w.j a v a 2s. c o m socket.close(); } catch (IOException ioe) { if (logger.isDebugEnabled()) logger.debug("close socket failed for " + destination, ioe); } } }
From source file:org.asynchttpclient.async.AbstractBasicTest.java
protected synchronized int findFreePort() throws IOException { ServerSocket socket = null; try {//from w w w. j a va2 s. co m socket = new ServerSocket(0); return socket.getLocalPort(); } finally { if (socket != null) { socket.close(); } } }
From source file:org.sonatype.nexus.proxy.NonProxyHostsTest.java
private int getAFreePort() { int port = 0; ServerSocket serverSocket = null; try {//w ww. jav a 2 s . c om serverSocket = new ServerSocket(0); port = serverSocket.getLocalPort(); } catch (IOException e) { Assert.fail("Failed to find free port." + e.getMessage()); } finally { try { serverSocket.close(); } catch (IOException e) { Assert.fail("Failed to close port." + e.getMessage()); } } return port; }
From source file:org.mule.transport.http.functional.MockHttpServer.java
public void run() { try {/* w w w.j av a 2s . c o m*/ ServerSocket serverSocket = new ServerSocket(listenPort); startupLatch.countDown(); Socket clientSocket = serverSocket.accept(); InputStream in = clientSocket.getInputStream(); OutputStream out = clientSocket.getOutputStream(); processRequests(in, out); in.close(); out.close(); clientSocket.close(); serverSocket.close(); shutdownLatch.countDown(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.fabrician.enabler.KarafContainer.java
private boolean serverPortInUse(int port) { if (port == UNDEFINED_PORT) { return false; }//from w ww .j a v a 2 s . co m ServerSocket srv = null; boolean inUse = false; try { srv = new ServerSocket(port); srv.close(); } catch (Exception e) { getEngineLogger().finest("serverPortInUse: debug exception: " + e); inUse = true; } return inUse; }