|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectecologylab.generic.Debug
ecologylab.services.distributed.impl.NIOCore
public abstract class NIOCore
Provides core functionality for NIO-based servers or clients. This class is Runnable and StartAndStoppable; it's run method automatically handles interest-switching on a selector's keys, as well as calling appropriate abstract methods whenever interest ops are selected. Subclasses are required to configure their own selector.
| Field Summary | |
|---|---|
protected int |
portNumber
|
protected java.nio.channels.Selector |
selector
|
| Fields inherited from interface ecologylab.services.distributed.common.NetworkingConstants |
|---|
CHARACTER_ENCODING, CONTENT_LENGTH_STRING, CONTENT_LENGTH_STRING_LENGTH, DECODER, ENCODER, HTTP_HEADER_LINE_DELIMITER, HTTP_HEADER_TERMINATOR, MAX_HTTP_HEADER_LENGTH, MAX_PACKET_SIZE_BYTES, MAX_PACKET_SIZE_CHARACTERS, UNIQUE_IDENTIFIER_STRING |
| Constructor Summary | |
|---|---|
protected |
NIOCore(java.lang.String networkingIdentifier,
int portNumber)
Instantiates a new NIOCore object. |
| Method Summary | |
|---|---|
abstract void |
acceptFinished(java.nio.channels.SelectionKey key)
Queues a request to change key's interest operations back to READ. |
protected abstract void |
acceptReady(java.nio.channels.SelectionKey key)
|
protected abstract void |
checkAndDropIdleKeys()
Check for timeout on all allocated keys; deallocate those that are hanging around, but no longer in use. |
protected void |
close()
|
void |
connectFinished(java.nio.channels.SelectionKey key)
Queues a request to change key's interest operations back to READ. |
protected abstract void |
connectReady(java.nio.channels.SelectionKey key)
|
int |
getPortNumber()
|
protected abstract void |
invalidateKey(java.nio.channels.SelectionKey key,
boolean permanent)
|
protected void |
invalidateKey(java.nio.channels.SocketChannel chan)
Shut down the connection associated with this SelectionKey. |
protected void |
queueForAccept(java.nio.channels.SelectionKey key)
|
protected void |
queueForConnect(java.nio.channels.SelectionKey key)
|
protected void |
queueForRead(java.nio.channels.SelectionKey key)
|
protected void |
queueForWrite(java.nio.channels.SelectionKey key)
|
protected abstract void |
readFinished(java.nio.channels.SelectionKey key)
|
protected abstract void |
readReady(java.nio.channels.SelectionKey key)
|
protected abstract void |
removeBadConnections(java.nio.channels.SelectionKey key)
|
void |
run()
THIS METHOD SHOULD NOT BE CALLED DIRECTLY! Proper use of this method is through the start / stop methods. |
void |
setPendingInvalidate(java.nio.channels.SelectionKey key,
boolean permanent)
Sets up a pending invalidate command for the given input. |
void |
start()
|
void |
stop()
|
protected void |
writeFinished(java.nio.channels.SelectionKey key)
Queues a request to change key's interest operations back to READ. |
protected abstract void |
writeReady(java.nio.channels.SelectionKey key)
|
| Methods inherited from class ecologylab.generic.Debug |
|---|
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected java.nio.channels.Selector selector
protected int portNumber
| Constructor Detail |
|---|
protected NIOCore(java.lang.String networkingIdentifier,
int portNumber)
throws java.io.IOException
networkingIdentifier - the name to identify this object when its thread is created.portNumber - the port number that this object will use for network communications.
java.io.IOException - if an I/O error occurs while trying to open a Selector from the system.| Method Detail |
|---|
public final void run()
run in interface java.lang.RunnableRunnable.run()protected abstract void acceptReady(java.nio.channels.SelectionKey key)
key - protected abstract void connectReady(java.nio.channels.SelectionKey key)
key - protected abstract void readFinished(java.nio.channels.SelectionKey key)
key -
protected abstract void readReady(java.nio.channels.SelectionKey key)
throws ClientOfflineException,
BadClientException
key -
ClientOfflineException
BadClientExceptionpublic abstract void acceptFinished(java.nio.channels.SelectionKey key)
key - public void connectFinished(java.nio.channels.SelectionKey key)
key - protected void writeFinished(java.nio.channels.SelectionKey key)
key - -
the SelectionKey that is finished writing.protected abstract void removeBadConnections(java.nio.channels.SelectionKey key)
public void setPendingInvalidate(java.nio.channels.SelectionKey key,
boolean permanent)
chan - -
the SocketChannel to invalidate.protected void invalidateKey(java.nio.channels.SocketChannel chan)
chan - The SocketChannel that needs to be shut down.
protected abstract void invalidateKey(java.nio.channels.SelectionKey key,
boolean permanent)
ecologylab.services.distributed.impl.NIONetworking#invalidateKey(java.nio.channels.SocketChannel, boolean)public void start()
start in interface StartAndStoppablepublic void stop()
stop in interface StartAndStoppableprotected void close()
protected abstract void checkAndDropIdleKeys()
protected abstract void writeReady(java.nio.channels.SelectionKey key)
throws java.io.IOException
key -
java.io.IOExceptionprotected void queueForAccept(java.nio.channels.SelectionKey key)
protected void queueForConnect(java.nio.channels.SelectionKey key)
protected void queueForRead(java.nio.channels.SelectionKey key)
protected void queueForWrite(java.nio.channels.SelectionKey key)
public int getPortNumber()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||