public class MockSocketServer extends Thread
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
static byte[] |
EMPTY_BYTES
An empty Array of bytes.
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
MockSocketServer()
Creates a new MockMongoDBServer.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the requests received and replies to send.
|
void |
close()
Closes the server socket.
|
protected void |
close(Socket socket)
Closes the
Socket and logs any error. |
boolean |
disconnectClient()
Disconnects any active client..
|
InetSocketAddress |
getInetSocketAddress()
Returns the address for the server.
|
List<byte[]> |
getReplies()
Returns the replies that will be returned after each message is received.
|
List<byte[]> |
getRequests()
Returns the requests that have been received.
|
String |
getServerName()
Returns the address for the server.
|
protected void |
handleClient()
Handles a single client connection.
|
boolean |
isRunning()
Returns if the server is running.
|
void |
run()
Runs the server loop waiting for connections and servicing a single
client until it exits.
|
void |
setReplies(List<byte[]> replies)
Sets the replies to return after each message is received.
|
void |
setRunning(boolean running)
Controls if the server is running.
|
protected void |
sleep() |
boolean |
waitForClient(long timeout)
Waits for a client to connect.
|
boolean |
waitForDisconnect(long timeout)
Waits for a client to disconnect.
|
boolean |
waitForRequest(int count,
long timeout)
Waits for a client request.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public MockSocketServer() throws IOException
IOException
- On a failure creating the server socket.public void clear()
public void close() throws IOException
IOException
- On a failure closing the server socket.public boolean disconnectClient()
public InetSocketAddress getInetSocketAddress()
public List<byte[]> getReplies()
public List<byte[]> getRequests()
public String getServerName()
public boolean isRunning()
public void run()
public void setReplies(List<byte[]> replies)
replies
- the replies to sendpublic void setRunning(boolean running)
running
- the running to setpublic boolean waitForClient(long timeout)
timeout
- Time to wait (in milliseconds) for the disconnect.public boolean waitForDisconnect(long timeout)
timeout
- Time to wait (in milliseconds) for the disconnect.public boolean waitForRequest(int count, long timeout)
count
- The number of request to wait for.timeout
- Time to wait (in milliseconds) for the disconnect.protected void close(Socket socket)
socket
- The connection to close. Sockets do not implement
Closeable
in Java 6protected void handleClient() throws IOException
IOException
- On a connection error.protected void sleep()
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.