Example usage for java.net BindException getMessage

List of usage examples for java.net BindException getMessage

Introduction

In this page you can find the example usage for java.net BindException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.stanford.epad.epadws.PluginMain.java

public static void main(String[] args) {
    ShutdownSignal shutdownSignal = ShutdownSignal.getInstance();
    Server server = null;/*from  ww w. j  a v  a2  s  .  c  o  m*/

    try {
        checkPluginsFile();
        int pluginPort = new Integer(EPADConfig.getParamValue("PluginPort", "8085"));
        log.info("#######################################################");
        log.info("############# Starting ePAD Plugin Webapp #############");
        log.info("#######################################################");
        initializePlugins();
        server = new Server(pluginPort);
        configureJettyServer(server);
        addHandlers(server);
        Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());
        log.info("Starting Jetty for ePAD Plugins on port " + pluginPort);
        server.start();
        server.join();
    } catch (BindException be) {
        log.severe("Bind exception", be);
        Throwable t = be.getCause();
        log.warning("Bind exception cause: " + be.getMessage(), t);
    } catch (SocketException se) {
        log.severe("Cannot bind to all sockets", se);
    } catch (Exception e) {
        log.severe("Fatal Exception. Shutting down ePAD Web Service", e);
    } catch (Error err) {
        log.severe("Fatal Error. Shutting down ePAD Web Service", err);
    } finally {
        log.info("#####################################################");
        log.info("############# Shutting down ePAD  ###################");
        log.info("#####################################################");

        shutdownSignal.shutdownNow();
        stopServer(server);
        try { // Wait just long enough for some messages to be printed out.
            TimeUnit.MILLISECONDS.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    log.info("#####################################################");
    log.info("################## Exit ePAD Web Service ###########");
    log.info("#####################################################");
}

From source file:edu.stanford.epad.epadws.Main.java

public static void main(String[] args) {
    ShutdownSignal shutdownSignal = ShutdownSignal.getInstance();
    Server server = null;//from  ww w  .ja  va 2 s.com

    try {
        checkPropertiesFile();
        checkResourcesFolders();
        checkPluginsFile();
        RemotePACService.checkPropertiesFile();
        int epadPort = EPADConfig.epadPort;
        Dcm4CheeOperations.checkScriptFiles();
        separateWebServicesApp = "true".equalsIgnoreCase(EPADConfig.getParamValue("SeparateWebServicesApp"));
        if (!separateWebServicesApp) {
            log.info("#####################################################");
            log.info("############# Starting ePAD Web Service #############");
            log.info("#####################################################");
            initializePlugins();
            startSupportThreads();
        } else {
            log.info("#####################################################");
            log.info("############# Starting ePAD GWT FrontEnd ############");
            log.info("#####################################################");
        }
        server = new Server(epadPort);
        configureJettyServer(server);
        addHandlers(server);
        Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());
        log.info("Starting Jetty on port " + epadPort);
        server.start();
        setupTestFiles();
        server.join();
    } catch (BindException be) {
        log.severe("Bind exception", be);
        Throwable t = be.getCause();
        log.warning("Bind exception cause: " + be.getMessage(), t);
    } catch (SocketException se) {
        log.severe("Cannot bind to all sockets", se);
    } catch (Exception e) {
        log.severe("Fatal Exception. Shutting down ePAD Web Service", e);
    } catch (Error err) {
        log.severe("Fatal Error. Shutting down ePAD Web Service", err);
    } finally {
        log.info("#####################################################");
        log.info("############# Shutting down ePAD  ###################");
        log.info("#####################################################");

        shutdownSignal.shutdownNow();
        stopServer(server);
        if (!separateWebServicesApp) {
            EpadDatabase.getInstance().shutdown();
            QueueAndWatcherManager.getInstance().shutdown();
        }
        try { // Wait just long enough for some messages to be printed out.
            TimeUnit.MILLISECONDS.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    log.info("#####################################################");
    log.info("################## Exit ePAD Web Service ###########");
    log.info("#####################################################");
}

From source file:com.clustercontrol.port.protocol.ReachAddressTCP.java

/**
 * ????????????/*from   w  w w.  ja  v a 2  s. c om*/
 * 
 * @param addressText
 * @return PORT
 */
@Override
protected boolean isRunning(String addressText) {

    m_message = "";
    m_messageOrg = "";
    m_response = -1;

    boolean isReachable = false;

    try {
        long start = 0; // 
        long end = 0; // 

        StringBuffer bufferOrg = new StringBuffer(); // 
        String result = "";

        // Reachability ?? ICMP ??
        boolean retry = true;

        InetAddress address = InetAddress.getByName(addressText);

        bufferOrg.append("Monitoring the port of " + address.getHostName() + "[" + address.getHostAddress()
                + "]:" + m_portNo + ".\n\n");

        // 
        Socket socket = null;

        for (int i = 0; i < m_sentCount && retry; i++) {
            try {
                // ?
                socket = new Socket();
                InetSocketAddress isa = new InetSocketAddress(address, m_portNo);

                bufferOrg.append(HinemosTime.getDateString() + " Tried to Connect: ");
                start = HinemosTime.currentTimeMillis();
                socket.connect(isa, m_timeout);
                end = HinemosTime.currentTimeMillis();

                m_response = end - start;
                if (m_response > 0) {
                    if (m_response < m_timeout) {
                        result = ("Response Time = " + m_response + "ms");
                    } else {
                        m_response = m_timeout;
                        result = ("Response Time = " + m_response + "ms");
                    }
                } else {
                    result = ("Response Time < 1ms");
                }
                retry = false;
                isReachable = true;
            } catch (BindException e) {
                result = (e.getMessage() + "[BindException]");
                retry = true;
                isReachable = false;
            } catch (ConnectException e) {
                result = (e.getMessage() + "[ConnectException]");
                retry = false;
                isReachable = false;
            } catch (NoRouteToHostException e) {
                result = (e.getMessage() + "[NoRouteToHostException]");
                retry = true;
                isReachable = false;
            } catch (PortUnreachableException e) {
                result = (e.getMessage() + "[PortUnreachableException]");
                retry = true;
                isReachable = false;
            } catch (IOException e) {
                result = (e.getMessage() + "[IOException]");
                retry = true;
                isReachable = false;
            } finally {
                bufferOrg.append(result + "\n");
                if (socket != null) {
                    try {
                        socket.close();
                    } catch (IOException e) {
                        m_log.warn("isRunning(): " + "socket close failed: " + e.getMessage(), e);
                    }
                }
            }

            if (i < m_sentCount - 1 && retry) {
                try {
                    Thread.sleep(m_sentInterval);
                } catch (InterruptedException e) {
                    break;
                }
            }
        }

        m_message = result + "(TCP/" + m_portNo + ")";
        m_messageOrg = bufferOrg.toString();
        return isReachable;
    } catch (UnknownHostException e) {
        m_log.debug("isRunning(): " + MessageConstant.MESSAGE_FAIL_TO_EXECUTE_TO_CONNECT.getMessage()
                + e.getMessage());

        m_message = MessageConstant.MESSAGE_FAIL_TO_EXECUTE_TO_CONNECT.getMessage() + " (" + e.getMessage()
                + ")";

        return false;
    }
}

From source file:com.taobao.adfs.distributed.rpc.Server.java

/**
 * A convenience method to bind to a given address and report better exceptions if the address is not a valid host.
 * /*  w w  w.  j a  v a2  s  . c  o  m*/
 * @param socket
 *          the socket to bind
 * @param address
 *          the address to bind to
 * @param backlog
 *          the number of connections allowed in the queue
 * @throws BindException
 *           if the address can't be bound
 * @throws UnknownHostException
 *           if the address isn't a valid host name
 * @throws IOException
 *           other random errors from bind
 */
public static void bind(ServerSocket socket, InetSocketAddress address, int backlog) throws IOException {
    try {
        socket.bind(address, backlog);
    } catch (BindException e) {
        BindException bindException = new BindException(
                "Problem binding to " + address + " : " + e.getMessage());
        bindException.initCause(e);
        throw bindException;
    } catch (SocketException e) {
        // If they try to bind to a different host's address, give a better
        // error message.
        if ("Unresolved address".equals(e.getMessage())) {
            throw new UnknownHostException("Invalid hostname for server: " + address.getHostName());
        } else {
            throw e;
        }
    }
}

From source file:jhttpp2.Jhttpp2Server.java

public void init() {
    writeLog("server startup...");
    if (serverproperties == null) {
        log.warn("Server properties should be set prior to init");
    }//from w w w  .j a  va 2  s.  c  o m
    if (dic == null) {
        log.warn("Server dic should be set prior to calling init");
    }
    if (urlactions == null) {
        log.warn("url actions should be set prior to init");
    }
    try {
        listen = new ServerSocket(port);
    } catch (BindException e_bind_socket) {
        setErrorMsg("Socket " + port + " is already in use (Another jHTTPp2 proxy running?) "
                + e_bind_socket.getMessage());
    } catch (IOException e_io_socket) {
        setErrorMsg(
                "IO Exception while creating server socket on port " + port + ". " + e_io_socket.getMessage());
    }

    if (error) {
        writeLog(error_msg);
        return;
    }
}

From source file:com.hortonworks.hbase.replication.bridge.HBaseServer.java

/**
 * A convenience method to bind to a given address and report
 * better exceptions if the address is not a valid host.
 * @param socket the socket to bind/*from  w  w w  .j  a va  2 s .c  om*/
 * @param address the address to bind to
 * @param backlog the number of connections allowed in the queue
 * @throws BindException if the address can't be bound
 * @throws UnknownHostException if the address isn't a valid host name
 * @throws IOException other random errors from bind
 */
public static void bind(ServerSocket socket, InetSocketAddress address, int backlog) throws IOException {
    try {
        socket.bind(address, backlog);
    } catch (BindException e) {
        BindException bindException = new BindException(
                "Problem binding to " + address + " : " + e.getMessage());
        bindException.initCause(e);
        throw bindException;
    } catch (SocketException e) {
        // If they try to bind to a different host's address, give a better
        // error message.
        if ("Unresolved address".equals(e.getMessage())) {
            throw new UnknownHostException("Invalid hostname for server: " + address.getHostName());
        }
        throw e;
    }
}

From source file:net.pms.PMS.java

/**
 * Initialisation procedure for PMS.//from   ww  w .ja v  a  2 s  .c o  m
 * @return true if the server has been initialized correctly. false if the server could
 * not be set to listen on the UPnP port.
 * @throws Exception
 */
private boolean init() throws Exception {
    // The public VERSION field is deprecated.
    // This is a temporary fix for backwards compatibility
    VERSION = getVersion();

    // call this as early as possible
    displayBanner();

    AutoUpdater autoUpdater = null;
    if (Build.isUpdatable()) {
        String serverURL = Build.getUpdateServerURL();
        autoUpdater = new AutoUpdater(serverURL, getVersion());
    }

    registry = createSystemUtils();

    if (!isHeadless()) {
        frame = new LooksFrame(autoUpdater, configuration);
    } else {
        logger.info("GUI environment not available");
        logger.info("Switching to console mode");
        frame = new DummyFrame();
    }

    /*
     * we're here:
     *
     *     main() -> createInstance() -> init()
     *
     * which means we haven't created the instance returned by get()
     * yet, so the frame appender can't access the frame in the
     * standard way i.e. PMS.get().getFrame(). we solve it by
     * inverting control ("don't call us; we'll call you") i.e.
     * we notify the appender when the frame is ready rather than
     * e.g. making getFrame() static and requiring the frame
     * appender to poll it.
     *
     * XXX an event bus (e.g. MBassador or Guava EventBus
     * (if they fix the memory-leak issue)) notification
     * would be cleaner and could support other lifecycle
     * notifications (see above).
     */
    FrameAppender.setFrame(frame);

    configuration.addConfigurationListener(new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if ((!event.isBeforeUpdate())
                    && PmsConfiguration.NEED_RELOAD_FLAGS.contains(event.getPropertyName())) {
                frame.setReloadable(true);
            }
        }
    });

    frame.setStatusCode(0, Messages.getString("PMS.130"), "connect_no-220.png");
    RendererConfiguration.loadRendererConfigurations(configuration);
    logger.info("Checking MPlayer font cache. It can take a minute or so.");
    checkProcessExistence("MPlayer", true, null, configuration.getMplayerPath(), "dummy");

    if (Platform.isWindows()) {
        checkProcessExistence("MPlayer", true, configuration.getTempFolder(), configuration.getMplayerPath(),
                "dummy");
    }

    logger.info("Done!");

    // check the existence of Vsfilter.dll
    if (registry.isAvis() && registry.getAvsPluginsDir() != null) {
        logger.info("Found AviSynth plugins dir: " + registry.getAvsPluginsDir().getAbsolutePath());
        File vsFilterdll = new File(registry.getAvsPluginsDir(), "VSFilter.dll");
        if (!vsFilterdll.exists()) {
            logger.info(
                    "VSFilter.dll is not in the AviSynth plugins directory. This can cause problems when trying to play subtitled videos with AviSynth");
        }
    }

    // Check if VLC is found
    String vlcVersion = registry.getVlcVersion();
    String vlcPath = registry.getVlcPath();

    if (vlcVersion != null && vlcPath != null) {
        logger.info("Found VLC version " + vlcVersion + " at: " + vlcPath);

        Version vlc = new Version(vlcVersion);
        Version requiredVersion = new Version("2.0.2");

        if (vlc.compareTo(requiredVersion) <= 0) {
            logger.error("Only VLC versions 2.0.2 and above are supported");
        }
    }

    // check if Kerio is installed
    if (registry.isKerioFirewall()) {
        logger.info("Detected Kerio firewall");
    }

    // force use of specific dvr ms muxer when it's installed in the right place
    File dvrsMsffmpegmuxer = new File("win32/dvrms/ffmpeg_MPGMUX.exe");
    if (dvrsMsffmpegmuxer.exists()) {
        configuration.setFfmpegAlternativePath(dvrsMsffmpegmuxer.getAbsolutePath());
    }

    // disable jaudiotagger logging
    LogManager.getLogManager()
            .readConfiguration(new ByteArrayInputStream("org.jaudiotagger.level=OFF".getBytes()));

    // wrap System.err
    System.setErr(new PrintStream(new SystemErrWrapper(), true));

    server = new HTTPServer(configuration.getServerPort());

    /*
     * XXX: keep this here (i.e. after registerExtensions and before registerPlayers) so that plugins
     * can register custom players correctly (e.g. in the GUI) and/or add/replace custom formats
     *
     * XXX: if a plugin requires initialization/notification even earlier than
     * this, then a new external listener implementing a new callback should be added
     * e.g. StartupListener.registeredExtensions()
     */
    try {
        ExternalFactory.lookup();
    } catch (Exception e) {
        logger.error("Error loading plugins", e);
    }

    // a static block in Player doesn't work (i.e. is called too late).
    // this must always be called *after* the plugins have loaded.
    // here's as good a place as any
    Player.initializeFinalizeTranscoderArgsListeners();

    // Initialize a player factory to register all players
    PlayerFactory.initialize(configuration);

    // Instantiate listeners that require registered players.
    ExternalFactory.instantiateLateListeners();

    // Any plugin-defined players are now registered, create the GUI view.
    frame.addEngines();

    boolean binding = false;

    try {
        binding = server.start();
    } catch (BindException b) {
        logger.info("FATAL ERROR: Unable to bind on port: " + configuration.getServerPort() + ", because: "
                + b.getMessage());
        logger.info("Maybe another process is running or the hostname is wrong.");
    }

    new Thread("Connection Checker") {
        @Override
        public void run() {
            try {
                Thread.sleep(7000);
            } catch (InterruptedException e) {
            }

            if (foundRenderers.isEmpty()) {
                frame.setStatusCode(0, Messages.getString("PMS.0"), "messagebox_critical-220.png");
            } else {
                frame.setStatusCode(0, Messages.getString("PMS.18"), "apply-220.png");
            }
        }
    }.start();

    if (!binding) {
        return false;
    }

    // initialize the cache
    if (configuration.getUseCache()) {
        initializeDatabase(); // XXX: this must be done *before* new MediaLibrary -> new MediaLibraryFolder
        mediaLibrary = new MediaLibrary();
        logger.info("A tiny cache admin interface is available at: http://" + server.getHost() + ":"
                + server.getPort() + "/console/home");
    }

    // XXX: this must be called:
    //     a) *after* loading plugins i.e. plugins register root folders then RootFolder.discoverChildren adds them
    //     b) *after* mediaLibrary is initialized, if enabled (above)
    getRootFolder(RendererConfiguration.getDefaultConf());

    frame.serverReady();

    // UPNPHelper.sendByeBye();
    Runtime.getRuntime().addShutdownHook(new Thread("PMS Listeners Stopper") {
        @Override
        public void run() {
            try {
                for (ExternalListener l : ExternalFactory.getExternalListeners()) {
                    l.shutdown();
                }
                UPNPHelper.shutDownListener();
                UPNPHelper.sendByeBye();
                logger.debug("Forcing shutdown of all active processes");
                for (Process p : currentProcesses) {
                    try {
                        p.exitValue();
                    } catch (IllegalThreadStateException ise) {
                        logger.trace("Forcing shutdown of process: " + p);
                        ProcessUtil.destroy(p);
                    }
                }
                get().getServer().stop();
                Thread.sleep(500);
            } catch (InterruptedException e) {
                logger.debug("Caught exception", e);
            }
        }
    });

    UPNPHelper.sendAlive();
    logger.trace("Waiting 250 milliseconds...");
    Thread.sleep(250);
    UPNPHelper.listen();

    return true;
}

From source file:org.apache.tomcat.util.net.PoolTcpEndpoint.java

public void initEndpoint() throws IOException, InstantiationException {
    try {/*w  w w  .j  a v  a 2  s  . c  o m*/
        if (factory == null)
            factory = ServerSocketFactory.getDefault();
        if (serverSocket == null) {
            try {
                if (inet == null) {
                    serverSocket = factory.createSocket(port, backlog);
                } else {
                    serverSocket = factory.createSocket(port, backlog, inet);
                }
            } catch (BindException be) {
                throw new BindException(be.getMessage() + ":" + port);
            }
        }
        if (serverTimeout >= 0)
            serverSocket.setSoTimeout(serverTimeout);
    } catch (IOException ex) {
        //       log("couldn't start endpoint", ex, Logger.DEBUG);
        throw ex;
    } catch (InstantiationException ex1) {
        //       log("couldn't start endpoint", ex1, Logger.DEBUG);
        throw ex1;
    }
    initialized = true;
}

From source file:org.cloudata.core.common.ipc.CServer.java

/**
 * A convience method to bind to a given address and report 
 * better exceptions if the address is not a valid host.
 * @param socket the socket to bind/*from  ww  w  . j a v  a  2 s.  co m*/
 * @param address the address to bind to
 * @param backlog the number of connections allowed in the queue
 * @throws BindException if the address can't be bound
 * @throws UnknownHostException if the address isn't a valid host name
 * @throws IOException other random errors from bind
 */
static void bind(ServerSocket socket, InetSocketAddress address, int backlog) throws IOException {
    try {
        socket.bind(address, backlog);
    } catch (BindException e) {
        throw new BindException("Problem binding to " + address + "," + e.getMessage());
    } catch (SocketException e) {
        // If they try to bind to a different host's address, give a better
        // error message.
        if ("Unresolved address".equals(e.getMessage())) {
            throw new UnknownHostException("Invalid hostname for server: " + address.getHostName());
        } else {
            throw e;
        }
    }
}

From source file:org.mule.transport.tcp.issues.ReuseExperimentMule2067TestCase.java

protected int repeatOpenCloseClientServer(int numberOfRepeats, int numberOfConnections, int port, long pause,
        boolean reuse, boolean noFail) throws IOException {
    String message = "Repeating openCloseClientServer with pauses of " + pause + " ms "
            + (reuse ? "with" : "without") + " reuse";
    if (noFail) {
        logger.debug(message);/*from   w w w . j av a 2  s .c  om*/
    } else {
        logger.info(message);
    }
    for (int i = 0; i < numberOfRepeats; i++) {
        if (0 != i) {
            pause(pause);
        }
        try {
            openCloseClientServer(numberOfConnections, port, reuse);
        } catch (BindException e) {
            if (noFail && e.getMessage().indexOf("Address already in use") > -1) {
                return i;
            }
            throw e;
        }
    }
    return numberOfRepeats;
}