/** * Shut things down gracefully. */ public synchronized void stop() { log.info("SMTP server {} stopping...", getDisplayableLocalSocketAddress()); if (this.serverThread == null) return; this.serverThread.shutdown(); this.serverThread = null; log.info("SMTP server {} stopped", getDisplayableLocalSocketAddress()); }
/** * Shut things down gracefully. */ public synchronized void stop() { log.info("SMTP server {} stopping...", getDisplayableLocalSocketAddress()); if (this.serverThread == null) return; this.serverThread.shutdown(); this.serverThread = null; log.info("SMTP server {} stopped", getDisplayableLocalSocketAddress()); }
/** * Shut things down gracefully. */ public synchronized void stop() { if (log.isInfoEnabled()) log.info("SMTP server {} stopping", getDisplayableLocalSocketAddress()); if (this.serverThread == null) return; this.serverThread.shutdown(); this.serverThread = null; }
public ServerThread(SMTPServer server, ServerSocket serverSocket) { super(ServerThread.class.getName() + " " + server.getDisplayableLocalSocketAddress()); this.server = server; this.serverSocket = serverSocket; // reserve a few places for graceful disconnects with informative // messages int countOfConnectionPermits = server.getMaxConnections() + 10; this.connectionPermits = new Semaphore(countOfConnectionPermits); this.sessionThreads = new HashSet<Session>(countOfConnectionPermits * 4 / 3 + 1); }
public ServerThread(SMTPServer server, ServerSocket serverSocket) { super(ServerThread.class.getName() + " " + server.getDisplayableLocalSocketAddress()); this.server = server; this.serverSocket = serverSocket; // reserve a few places for graceful disconnects with informative // messages int countOfConnectionPermits = server.getMaxConnections() + 10; this.connectionPermits = new Semaphore(countOfConnectionPermits); this.sessionThreads = new HashSet<Session>(countOfConnectionPermits * 4 / 3 + 1); }
public ServerThread(SMTPServer server, ServerSocket serverSocket) { super(ServerThread.class.getName() + " " + server.getDisplayableLocalSocketAddress()); this.server = server; this.serverSocket = serverSocket; // reserve a few places for graceful disconnects with informative // messages int countOfConnectionPermits = server.getMaxConnections() + 10; this.connectionPermits = new Semaphore(countOfConnectionPermits); this.sessionThreads = new HashSet<Session>(countOfConnectionPermits * 4 / 3 + 1); }
/** * This method is called by this thread when it starts up. To safely cause * this to exit, call {@link #shutdown()}. */ @Override public void run() { MDC.put("smtpServerLocalSocketAddress", server.getDisplayableLocalSocketAddress()); log.info("SMTP server {} started", server.getDisplayableLocalSocketAddress()); try { runAcceptLoop(); log.info("SMTP server {} stopped", server.getDisplayableLocalSocketAddress()); } catch (RuntimeException e) { log.error("Unexpected exception in server socket thread, server is stopped", e); throw e; } catch (Error e) { log.error("Unexpected error in server socket thread, server is stopped", e); throw e; } finally { MDC.remove("smtpServerLocalSocketAddress"); } }
/** * This method is called by this thread when it starts up. To safely cause * this to exit, call {@link #shutdown()}. */ @Override public void run() { MDC.put("smtpServerLocalSocketAddress", server.getDisplayableLocalSocketAddress()); log.info("SMTP server {} started", server.getDisplayableLocalSocketAddress()); try { runAcceptLoop(); log.info("SMTP server {} stopped accepting connections", server.getDisplayableLocalSocketAddress()); } catch (RuntimeException e) { log.error("Unexpected exception in server socket thread, server is stopped", e); throw e; } catch (Error e) { log.error("Unexpected error in server socket thread, server is stopped", e); throw e; } finally { MDC.remove("smtpServerLocalSocketAddress"); } }
/** * This method is called by this thread when it starts up. To safely cause * this to exit, call {@link #shutdown()}. */ @Override public void run() { MDC.put("smtpServerLocalSocketAddress", server.getDisplayableLocalSocketAddress()); log.info("SMTP server {} started", server.getDisplayableLocalSocketAddress()); try { runAcceptLoop(); log.info("SMTP server {} stopped accepting connections", server.getDisplayableLocalSocketAddress()); } catch (RuntimeException e) { log.error("Unexpected exception in server socket thread, server is stopped", e); throw e; } catch (Error e) { log.error("Unexpected error in server socket thread, server is stopped", e); throw e; } finally { MDC.remove("smtpServerLocalSocketAddress"); } }
/** * Call this method to get things rolling after instantiating the * SMTPServer. * <p> * An SMTPServer which has been shut down, must not be reused. */ public synchronized void start() { if (log.isInfoEnabled()) log.info("SMTP server {} starting", getDisplayableLocalSocketAddress()); if (this.started) throw new IllegalStateException( "SMTPServer can only be started once. " + "Restarting is not allowed even after a proper shutdown."); // Create our server socket here. ServerSocket serverSocket; try { serverSocket = this.createServerSocket(); } catch (Exception e) { throw new RuntimeException(e); } this.serverThread = new ServerThread(this, serverSocket); this.serverThread.start(); this.started = true; }
/** * Call this method to get things rolling after instantiating the * SMTPServer. */ public synchronized void start() { if (log.isInfoEnabled()) log.info("SMTP server {} starting", getDisplayableLocalSocketAddress()); if (this.started) throw new IllegalStateException( "SMTPServer can only be started once"); // Create our server socket here. ServerSocket serverSocket; try { serverSocket = this.createServerSocket(); } catch (Exception e) { throw new RuntimeException(e); } this.serverThread = new ServerThread(this, serverSocket); this.serverThread.start(); this.started = true; }
/** * Starts the server listening for connections. When this method returns the * server socket will have been established and will accept connections though * the thread that processes accepted connections (queued) may not have started * yet (it runs asynchronously). * <p> * An SMTPServer which has been shut down, must not be reused. */ public synchronized void start() { log.info("SMTP server {} starting", getDisplayableLocalSocketAddress()); if (this.started) throw new IllegalStateException("SMTPServer can only be started once. " + "Restarting is not allowed even after a proper shutdown."); // Create our server socket here. ServerSocket serverSocket; try { serverSocket = this.createServerSocket(); } catch (Exception e) { throw new RuntimeException(e); } this.serverThread = new ServerThread(this, serverSocket); this.serverThread.start(); this.started = true; }