Class AbstractServer

java.lang.Object
java.lang.Thread
com.icegreen.greenmail.server.AbstractServer
All Implemented Interfaces:
Service, Runnable
Direct Known Subclasses:
ImapServer, Pop3Server, SmtpServer

public abstract class AbstractServer extends Thread implements Service
Since:
Feb 2, 2006
Version:
$Id: $
Author:
Wael Chatila
  • Field Details

    • log

      protected final org.slf4j.Logger log
    • bindTo

      protected final InetAddress bindTo
    • serverSocket

      protected ServerSocket serverSocket
    • CLIENT_SOCKET_SO_TIMEOUT

      protected static final int CLIENT_SOCKET_SO_TIMEOUT
      See Also:
    • managers

      protected final Managers managers
    • setup

      protected ServerSetup setup
  • Constructor Details

  • Method Details

    • createProtocolHandler

      protected abstract ProtocolHandler createProtocolHandler(Socket clientSocket)
      Create a new, specific protocol handler such as for IMAP.
      Parameters:
      clientSocket - the client socket to use.
      Returns:
      the new protocol handler.
    • openServerSocket

      protected ServerSocket openServerSocket() throws IOException
      Throws:
      IOException
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • initServerSocket

      protected void initServerSocket()
    • closeServerSocket

      protected void closeServerSocket()
      Closes the server socket.
    • setClientSocketTimeout

      public void setClientSocketTimeout(int clientSocketTimeout)
    • handleClientSocket

      protected void handleClientSocket(Socket clientSocket) throws SocketException
      Throws:
      SocketException
    • quit

      protected void quit()
      Quits server by closing server socket and closing client socket handlers.
    • getBindTo

      public String getBindTo()
    • getPort

      public int getPort()
    • getProtocol

      public String getProtocol()
    • getServerSetup

      public ServerSetup getServerSetup()
    • toString

      public String toString()
      Overrides:
      toString in class Thread
    • waitTillRunning

      public boolean waitTillRunning(long timeoutInMs) throws InterruptedException
      Description copied from interface: Service
      Waits till service is up or timeout was reached.
      Specified by:
      waitTillRunning in interface Service
      Parameters:
      timeoutInMs - the timeout in milliseconds
      Returns:
      true, if running otherwise false if timeout was reached.
      Throws:
      InterruptedException - if interrupted while waiting.
    • isRunning

      public boolean isRunning()
      Description copied from interface: Service
      Checks if service is up and running.
      Specified by:
      isRunning in interface Service
      Returns:
      true, if running.
    • setRunning

      protected void setRunning(boolean r)
    • keepOn

      protected final boolean keepOn()
    • startService

      public void startService()
      Description copied from interface: Service
      Starts the service in the background as a new thread.

      You can use Service.isRunning() and Service.waitTillRunning(long) to check if service is up.

      Specified by:
      startService in interface Service
    • stopService

      public final void stopService(long millis)
      Stops the service. If a timeout is given and the service has still not gracefully been stopped after timeout ms the service is stopped by force.
      Specified by:
      stopService in interface Service
      Parameters:
      millis - value in ms
    • stopService

      public final void stopService()
      Stops the service (without timeout).
      Specified by:
      stopService in interface Service
    • createSession

      public jakarta.mail.Session createSession(Properties properties)
      Creates a session configured for given server (IMAP, SMTP, ...).
      Parameters:
      properties - optional session properties, can be null.
      Returns:
      the session.
    • createSession

      public jakarta.mail.Session createSession(Properties properties, boolean debug)
      Creates a session configured for given server (IMAP, SMTP, ...).
      Parameters:
      properties - optional session properties, can be null.
      debug - if true enables JavaMail debug settings
      Returns:
      the session.
    • createSession

      public jakarta.mail.Session createSession()
      Creates a session configured for given server (IMAP, SMTP, ...).
      Returns:
      the session.
    • createStore

      public jakarta.mail.Store createStore() throws jakarta.mail.NoSuchProviderException
      Creates a new JavaMail store.
      Returns:
      a new store.
      Throws:
      jakarta.mail.NoSuchProviderException