Check the port availability

@param port
the port to check
@param msg
the text to append to the end of the error message displayed when the port is not available.
@throws IllegalArgumentException
when the port is not available.
762471
void checkPort(int port, String msg) {
        StringBuilder message = new StringBuilder().append(" ").append(msg);
        String portInUseError = String.format("Port %d is already in use. Please shutdown the service "
                + "listening on this port or configure a different port%s.", port, message);
        boolean free = false;
        try {
            free = PortProber.pollPort(port);
        } catch (RuntimeException e) {
            throw new IllegalArgumentException(portInUseError, e);
        } finally {
            if (!free) {
                throw new IllegalArgumentException(portInUseError);
            }
        }
    }
168919
public void error( String msg, Throwable t )
    {
        if( m_delegate.isErrorEnabled() )
        {
            m_delegate.error( msg, t );
        }
    }
129276
public void appendMsg(final String msg) {
        if (!EventQueue.isDispatchThread()) {
            try {
                EventQueue.invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        appendMsg(msg);
                    }
                });
            } catch (InvocationTargetException e) {
                LOGGER.error("Failed to append message: ", e);
            } catch (InterruptedException ignore) {
            }
            return;
        }

        displayRandomTip();
        getLogPanel().append(msg);
        JScrollBar vertical = getLogJScrollPane().getVerticalScrollBar();
        vertical.setValue(vertical.getMaximum());
    }
1090796
@Override
  public synchronized void release(Integer port) {
    if(port != null){
      portsInUse.remove(port);
      if (port >= minPort && port <= maxPort && isEvenNumber(port)) {
        availablePorts.add(port);
      }
    }
  }
953164
static void checkState(boolean check, String msg, Object... args) {
    if (!check) {
      throw new IllegalStateException(String.format(msg, args));
    }
  }
457085
public static boolean isPortAvailable(String host, int port) {
        try {
            Socket socket = new Socket(host, port);
            socket.close();
            return false;
        } catch (IOException e) {
            return true;
        }
    }
457081
boolean isFree( int port )
    {
        try
        {
            ServerSocket sock = new ServerSocket( port );
            sock.close();
            // is free:
            return true;
            // We rely on an exception thrown to determine availability or not availability.
        } catch( Exception e )
        {
            // not free.
            return false;
        }
    }
710211
public static Buffer ensureNotEmpty(final Buffer reference, final String msg) throws IllegalArgumentException {
        if (reference == null || reference.isEmpty()) {
            throw new IllegalArgumentException(msg);
        }
        return reference;
    }
156052
public static RuntimeException codeBug(String msg)
        throws RuntimeException
    {
        msg = "FAILED ASSERTION: " + msg;
        RuntimeException ex = new IllegalStateException(msg);
        // Print stack trace ASAP
        ex.printStackTrace(System.err);
        throw ex;
    }
94375
static void checkArgument(boolean check, String msg, Object... args) {
    if (!check) {
      throw new IllegalArgumentException(String.format(msg, args));
    }
  }
1239308
public static void invalidArgIf(boolean tester, String msg, Object... args) {
        if (tester) {
            throw invalidArg(msg, args);
        }
    }
1343036
public static void debug(String msg, Throwable t) {
        if (debugEnabled && !quietMode) {
            System.out.println(PREFIX + msg);
            if (t != null)
                t.printStackTrace(System.out);
        }
    }
686640
public static void error(String msg, Throwable t) {
        if (quietMode)
            return;

        System.err.println(ERR_PREFIX + msg);
        if (t != null) {
            t.printStackTrace();
        }
    }
346128
public void setPorts(java.util.Collection<InstancePortInfo> ports) {
        if (ports == null) {
            this.ports = null;
            return;
        }

        this.ports = new java.util.ArrayList<InstancePortInfo>(ports);
    }
251259
private boolean portAvailable(final int port) {
    ServerSocket socket = null;
    try {
      socket = new ServerSocket(port);
      return true;
    } catch (IOException ignored) {
      return false;
    } finally {
      if (socket != null) {
        try {
          socket.close();
        } catch (IOException e) {
          log.error("Couldn't close socket on port {} when checking availability: {}", port, e);
        }
      }
    }
  }
1372213
static boolean isPortAvailable(int port) {
        ServerSocket ss = null;
        try {
            ss = new ServerSocket(port);
            ss.setReuseAddress(true);
            return true;
        } catch (IOException ioe) { // NOSONAR
            return false;
        } finally {
            closeQuietly(ss);
        }
    }
740394
protected void error(String msg)
          throws javax.xml.transform.TransformerException
  {
    error(msg, null);
  }