com.mindbright.nio
public class Switchboard extends java.lang.Object implements java.lang.Runnable
| Modifier and Type | Method and Description |
|---|---|
void |
checkForDeadlock()
Check if the current thread is a thread which is allowed to
wait.
|
protected void |
close(java.nio.channels.spi.AbstractSelectableChannel channel) |
NetworkConnection |
connect(java.net.InetAddress addr,
int port,
boolean block)
Establish a new network connection.
|
boolean |
debug2(java.lang.String cls,
java.lang.String meth,
java.lang.String msg) |
static Switchboard |
getSwitchboard()
Get the global switchboard instance.
|
void |
notifyWhenConnected(NetworkConnection conn,
long timeout,
NIOCallback callback)
Wait for a network connection to become connected.
|
protected void |
read(java.nio.channels.spi.AbstractSelectableChannel channel,
java.nio.ByteBuffer buf,
NIOCallback callback,
NonBlockingInput lock,
boolean shortDataOk) |
java.lang.Object |
registerTimer(long interval,
TimerCallback callback)
Register a callback which is called regularly
|
void |
run()
This is the main loop which never exits.
|
void |
setLog(Log log)
Set the log to use
|
static void |
stop()
Stop the switchboard instance
|
void |
unregisterTimer(java.lang.Object key)
Unregister a previously registered timer callback
|
protected void |
write(java.nio.channels.spi.AbstractSelectableChannel channel,
java.nio.ByteBuffer buf,
NonBlockingOutput lock) |
public static Switchboard getSwitchboard()
public static void stop()
public void setLog(Log log)
log - log to usepublic java.lang.Object registerTimer(long interval,
TimerCallback callback)
interval - minimum number of milliseconds between callscallback - class to call backpublic void unregisterTimer(java.lang.Object key)
key - the handler returned from registerTimerpublic NetworkConnection connect(java.net.InetAddress addr, int port, boolean block) throws java.io.IOException
addr - address of server to connect toport - port to connect toblock - true if the call should block until the connection
is establishedjava.io.IOExceptionpublic void notifyWhenConnected(NetworkConnection conn, long timeout, NIOCallback callback)
conn - the network connection to wait ontimeout - max time, in milliseconds, the connect may takecallback - function to call back once connection is done
or has timed out.public final boolean debug2(java.lang.String cls,
java.lang.String meth,
java.lang.String msg)
protected void read(java.nio.channels.spi.AbstractSelectableChannel channel,
java.nio.ByteBuffer buf,
NIOCallback callback,
NonBlockingInput lock,
boolean shortDataOk)
throws java.io.IOException
java.io.IOExceptionpublic void checkForDeadlock()
throws java.lang.Exception
java.lang.Exception - if the current thread is the event handling threadprotected void write(java.nio.channels.spi.AbstractSelectableChannel channel,
java.nio.ByteBuffer buf,
NonBlockingOutput lock)
throws java.io.IOException
java.io.IOExceptionprotected void close(java.nio.channels.spi.AbstractSelectableChannel channel)
throws java.io.IOException
java.io.IOExceptionpublic void run()
run in interface java.lang.Runnable