List of usage examples for java.net ServerSocket close
public void close() throws IOException
From source file:org.jboss.aerogear.unifiedpush.migrator.EmbeddedMysqlDatabase.java
private int getFreePort() { ServerSocket socket = null; try {/* w w w. jav a2 s . c om*/ socket = new ServerSocket(0); return socket.getLocalPort(); } catch (IOException e) { } finally { if (socket != null) { try { socket.close(); } catch (IOException e) { } } } return -1; }
From source file:org.apache.vysper.xmpp.extension.xep0124.inttests.IntegrationTestTemplate.java
private int findFreePort() throws IOException { ServerSocket ss = null; try {/*from w w w.j a v a 2 s. co m*/ ss = new ServerSocket(0); ss.setReuseAddress(true); return ss.getLocalPort(); } finally { if (ss != null) { ss.close(); } } }
From source file:VASSAL.tools.io.IOUtilsTest.java
@Test public void testCloseQuietlyServerSocketClosed() throws IOException { final ServerSocket s = new ServerSocket(0); s.close(); assertTrue(s.isClosed());// ww w . ja va 2 s .c o m IOUtils.closeQuietly(s); assertTrue(s.isClosed()); }
From source file:org.pentaho.platform.web.hsqldb.HsqlDatabaseStarterBean.java
protected boolean checkPort() { if ((port < 0) || (port > 65535)) { if (allowFailoverToDefaultPort) { logger.error(Messages.getErrorString("HsqlDatabaseStarterBean.ERROR_0004_INVALID_PORT", //$NON-NLS-1$ "" + failoverPort)); port = failoverPort;/*w ww . j a v a2 s .c o m*/ } else { return logFailure("HsqlDatabaseStarterBean.ERROR_0004_INVALID_PORT", "" + failoverPort); //$NON-NLS-1$ } } try { ServerSocket sock = new ServerSocket(port); sock.close(); } catch (IOException ex1) { if (port == failoverPort) { return logFailure("HsqlDatabaseStarterBean.ERROR_0006_DEFAULT_PORT_IN_USE"); //$NON-NLS-1$ } else { if (allowFailoverToDefaultPort) { logger.error(Messages.getErrorString("HsqlDatabaseStarterBean.ERROR_0005_SPECIFIED_PORT_IN_USE", //$NON-NLS-1$ Integer.toString(port), "" + failoverPort)); port = failoverPort; try { ServerSocket sock = new ServerSocket(port); sock.close(); } catch (IOException ex2) { return logFailure("HsqlDatabaseStarterBean.ERROR_0006_DEFAULT_PORT_IN_USE"); //$NON-NLS-1$ } } else { return logFailure("HsqlDatabaseStarterBean.ERROR_0008_SPECIFIED_PORT_IN_USE_NO_FAILOVER", //$NON-NLS-1$ Integer.toString(port)); } } } return true; }
From source file:com.deicos.lince.Initializer.java
private boolean isPortFree(int port) { boolean isPortTaken = false; ServerSocket socket = null; try {/* w w w . j ava 2 s . c o m*/ socket = new ServerSocket(port); } catch (IOException e) { isPortTaken = true; } finally { if (socket != null) try { socket.close(); } catch (IOException e) { /* e.printStackTrace(); */ } } return isPortTaken; }
From source file:com.ning.metrics.goodwill.access.CachingGoodwillAccessorTest.java
private int findFreePort() throws IOException { ServerSocket socket = null; try {/*from w ww. ja va 2 s. c om*/ socket = new ServerSocket(0); return socket.getLocalPort(); } finally { if (socket != null) { socket.close(); } } }
From source file:com.hortonworks.registries.auth.client.AuthenticatorTestCase.java
protected int getLocalPort() throws Exception { ServerSocket ss = new ServerSocket(0); int ret = ss.getLocalPort(); ss.close(); return ret;/*w ww.ja v a 2 s. c om*/ }
From source file:ch.vorburger.mariadb4j.DBConfigurationBuilder.java
protected int detectFreePort() { try {//from ww w .ja va 2 s. co m ServerSocket ss = new ServerSocket(0); port = ss.getLocalPort(); ss.setReuseAddress(true); ss.close(); return port; } catch (IOException e) { // This should never happen throw new RuntimeException(e); } }
From source file:se.inera.certificate.proxy.mappings.remote.RemoteDispatcherTest.java
@Before public void before() throws Exception { ServerSocket ss = new ServerSocket(0); int serverPort = ss.getLocalPort(); ss.close(); TestServer server = new TestServer(); server.start(serverPort);// w ww.j a v a 2s . c o m moduleHostUri = "http://localhost:" + serverPort; }
From source file:com.twosigma.beaker.core.rest.PluginServiceLocatorRest.java
private static boolean isPortAvailable(int port) { ServerSocket ss = null; try {//from www.j a va2s.c o m InetAddress address = InetAddress.getByName("127.0.0.1"); ss = new ServerSocket(port, 1, address); // ss = new ServerSocket(port); ss.setReuseAddress(true); return true; } catch (IOException e) { } finally { if (ss != null) { try { ss.close(); } catch (IOException e) { /* should not be thrown */ } } } return false; }