public void connect(String ip, int port, IMessageArrivalListener listener) throws IOException { registerListener(listener); int timeout = DEFAULT_TIMEOUT; // Bind to a local ephemeral port sock.bind(null); sock.connect(new InetSocketAddress(ip, port), timeout); // attach reader to receive async msgs SocketReader reader = new SocketReader(); reader.start(); }
void checkHealth() { // Check that the sending operation is still active if (writeStarted > -1 && System.currentTimeMillis() - writeStarted > JiveGlobals.getIntProperty("xmpp.session.sending-limit", 60000)) { // Close the socket if (Log.isDebugEnabled()) { Log.debug( "Closing connection: " + this + " that started sending data at: " + new Date(writeStarted)); } forceClose(); } else { // Check if the connection has been idle. A connection is considered idle if the client // has not been receiving data for a period. Sending data to the client is not // considered as activity. if (idleTimeout > -1 && socketReader != null && System.currentTimeMillis() - socketReader.getLastActive() > idleTimeout) { // Close the socket if (Log.isDebugEnabled()) { Log.debug("Closing connection that has been idle: " + this); } forceClose(); } } }
/** * About as simple as it gets. The thread spins around an accept call getting sockets and creating * new reading threads for each new connection. */ @Override public void run() { while (notTerminated) { try { Socket sock = serverSocket.accept(); if (sock != null) { Log.debug("Connect " + sock.toString()); SocketReader reader = connManager.createSocketReader(sock, false, serverPort, true); Thread thread = new Thread(reader, reader.getName()); thread.setDaemon(true); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); } } catch (IOException ie) { if (notTerminated) { Log.error(LocaleUtils.getLocalizedString("admin.error.accept"), ie); } } catch (Throwable e) { Log.error(LocaleUtils.getLocalizedString("admin.error.accept"), e); } } }
protected void shutdown() { super.shutdown(); // Shutdown the pool of threads that are processing packets sent by // the remote server threadPool.shutdown(); }