Package com.icegreen.greenmail.server
Class AbstractServer
- java.lang.Object
-
- java.lang.Thread
-
- com.icegreen.greenmail.server.AbstractServer
-
- Direct Known Subclasses:
ImapServer,Pop3Server,SmtpServer
public abstract class AbstractServer extends Thread implements Service
- Since:
- Feb 2, 2006
- Version:
- $Id: $
- Author:
- Wael Chatila
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected InetAddressbindToprotected static intCLIENT_SOCKET_SO_TIMEOUTprotected org.slf4j.Loggerlogprotected Managersmanagersprotected ServerSocketserverSocketprotected ServerSetupsetup-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractServer(ServerSetup setup, Managers managers)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcloseServerSocket()Closes the server socket.protected abstract ProtocolHandlercreateProtocolHandler(Socket clientSocket)Create a new, specific protocol handler such as for IMAP.jakarta.mail.SessioncreateSession()Creates a session configured for given server (IMAP, SMTP, ...).jakarta.mail.SessioncreateSession(Properties properties)Creates a session configured for given server (IMAP, SMTP, ...).jakarta.mail.SessioncreateSession(Properties properties, boolean debug)Creates a session configured for given server (IMAP, SMTP, ...).jakarta.mail.StorecreateStore()Creates a new JavaMail store.StringgetBindTo()intgetPort()StringgetProtocol()ServerSetupgetServerSetup()protected voidhandleClientSocket(Socket clientSocket)protected voidinitServerSocket()booleanisRunning()Checks if service is up and running.protected booleankeepOn()protected ServerSocketopenServerSocket()protected voidquit()Quits server by closing server socket and closing client socket handlers.voidrun()voidsetClientSocketTimeout(int clientSocketTimeout)protected voidsetRunning(boolean r)voidstartService()Starts the service in the background as a new thread.voidstopService()Stops the service (without timeout).voidstopService(long millis)Stops the service.StringtoString()booleanwaitTillRunning(long timeoutInMs)Waits till service is up or timeout was reached.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, yield
-
-
-
-
Field Detail
-
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:
- Constant Field Values
-
managers
protected final Managers managers
-
setup
protected ServerSetup setup
-
-
Constructor Detail
-
AbstractServer
protected AbstractServer(ServerSetup setup, Managers managers)
-
-
Method Detail
-
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
-
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()
-
waitTillRunning
public boolean waitTillRunning(long timeoutInMs) throws InterruptedExceptionDescription copied from interface:ServiceWaits till service is up or timeout was reached.- Specified by:
waitTillRunningin interfaceService- 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:ServiceChecks if service is up and running.
-
setRunning
protected void setRunning(boolean r)
-
keepOn
protected final boolean keepOn()
-
startService
public void startService()
Description copied from interface:ServiceStarts the service in the background as a new thread. You can useService.isRunning()andService.waitTillRunning(long)to check if service is up.- Specified by:
startServicein interfaceService
-
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:
stopServicein interfaceService- Parameters:
millis- value in ms
-
stopService
public final void stopService()
Stops the service (without timeout).- Specified by:
stopServicein interfaceService
-
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.NoSuchProviderExceptionCreates a new JavaMail store.- Returns:
- a new store.
- Throws:
jakarta.mail.NoSuchProviderException
-
-