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 InetAddress
bindTo
protected static int
CLIENT_SOCKET_SO_TIMEOUT
protected org.slf4j.Logger
log
protected Managers
managers
protected ServerSocket
serverSocket
protected ServerSetup
setup
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractServer(ServerSetup setup, Managers managers)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
closeServerSocket()
Closes the server socket.protected abstract ProtocolHandler
createProtocolHandler(Socket clientSocket)
Create a new, specific protocol handler such as for IMAP.jakarta.mail.Session
createSession()
Creates a session configured for given server (IMAP, SMTP, ...).jakarta.mail.Session
createSession(Properties properties)
Creates a session configured for given server (IMAP, SMTP, ...).jakarta.mail.Session
createSession(Properties properties, boolean debug)
Creates a session configured for given server (IMAP, SMTP, ...).jakarta.mail.Store
createStore()
Creates a new JavaMail store.String
getBindTo()
int
getPort()
String
getProtocol()
ServerSetup
getServerSetup()
protected void
handleClientSocket(Socket clientSocket)
protected void
initServerSocket()
boolean
isRunning()
Checks if service is up and running.protected boolean
keepOn()
protected ServerSocket
openServerSocket()
protected void
quit()
Quits server by closing server socket and closing client socket handlers.void
run()
void
setClientSocketTimeout(int clientSocketTimeout)
protected void
setRunning(boolean r)
void
startService()
Starts the service in the background as a new thread.void
stopService()
Stops the service (without timeout).void
stopService(long millis)
Stops the service.String
toString()
boolean
waitTillRunning(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 InterruptedException
Description copied from interface:Service
Waits till service is up or timeout was reached.- Specified by:
waitTillRunning
in 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:Service
Checks 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:Service
Starts the service in the background as a new thread. You can useService.isRunning()
andService.waitTillRunning(long)
to check if service is up.- Specified by:
startService
in 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:
stopService
in interfaceService
- Parameters:
millis
- value in ms
-
stopService
public final void stopService()
Stops the service (without timeout).- Specified by:
stopService
in 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.NoSuchProviderException
Creates a new JavaMail store.- Returns:
- a new store.
- Throws:
jakarta.mail.NoSuchProviderException
-
-