Package com.icegreen.greenmail.server
Class AbstractServer
java.lang.Object
java.lang.Thread
com.icegreen.greenmail.server.AbstractServer
- Direct Known Subclasses:
ImapServer,Pop3Server,SmtpServer
- 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
FieldsModifier and TypeFieldDescriptionprotected final InetAddressprotected static final intprotected final org.slf4j.Loggerprotected final Managersprotected ServerSocketprotected ServerSetupFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCloses the server socket.protected abstract ProtocolHandlercreateProtocolHandler(Socket clientSocket) Create a new, specific protocol handler such as for IMAP.jakarta.mail.SessionCreates 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.StoreCreates a new JavaMail store.intgetPort()protected voidhandleClientSocket(Socket clientSocket) protected voidbooleanChecks if service is up and running.protected final booleankeepOn()protected ServerSocketprotected voidquit()Quits server by closing server socket and closing client socket handlers.voidrun()voidsetClientSocketTimeout(int clientSocketTimeout) protected voidsetRunning(boolean r) voidStarts the service in the background as a new thread.final voidStops the service (without timeout).final voidstopService(long millis) Stops the service.toString()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 Details
-
log
protected final org.slf4j.Logger log -
bindTo
-
serverSocket
-
CLIENT_SOCKET_SO_TIMEOUT
protected static final int CLIENT_SOCKET_SO_TIMEOUT- See Also:
-
managers
-
setup
-
-
Constructor Details
-
AbstractServer
-
-
Method Details
-
createProtocolHandler
Create a new, specific protocol handler such as for IMAP.- Parameters:
clientSocket- the client socket to use.- Returns:
- the new protocol handler.
-
openServerSocket
- Throws:
IOException
-
run
public void run() -
initServerSocket
protected void initServerSocket() -
closeServerSocket
protected void closeServerSocket()Closes the server socket. -
setClientSocketTimeout
public void setClientSocketTimeout(int clientSocketTimeout) -
handleClientSocket
- Throws:
SocketException
-
quit
protected void quit()Quits server by closing server socket and closing client socket handlers. -
getBindTo
-
getPort
public int getPort() -
getProtocol
-
getServerSetup
-
toString
-
waitTillRunning
Description 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 use
Service.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
Creates a session configured for given server (IMAP, SMTP, ...).- Parameters:
properties- optional session properties, can be null.- Returns:
- the session.
-
createSession
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
-