Package marauroa.server.net.nio
Class NIONetworkConnectionManager
java.lang.Object
java.lang.Thread
marauroa.server.net.nio.NIONetworkConnectionManager
- All Implemented Interfaces:
Runnable
,ConnectionManager
,IWorker
This is the implementation of a worker that sends messages, receives them, ...
This class also handles validation of connection and disconnection events
- Author:
- miguel
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
This method disconnect a socket.void
finish()
This method notifies the thread to finish the executionboolean
was the server shutdown?void
onConnect(SocketChannel internalChannel)
We check that this socket is not banned.void
onData(marauroa.server.net.nio.NioServer server, SocketChannel channel, byte[] data, int count)
This method is called when new data is received on server from channel.void
onDisconnect(SocketChannel channel)
Removes stored parts of message for this channel at the decoder.void
run()
void
This method add a message to be delivered to the client the message is pointed to.void
setServer(marauroa.server.net.nio.NioServer server)
Associate this object with a server.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, toString, yield
-
Constructor Details
-
NIONetworkConnectionManager
Constructor- Throws:
IOException
- if there any exception when starting the socket server.
-
-
Method Details
-
setServer
public void setServer(marauroa.server.net.nio.NioServer server)Associate this object with a server. This model a master-slave approach for managing network messages. -
finish
public void finish()This method notifies the thread to finish the execution- Specified by:
finish
in interfaceConnectionManager
-
isFinished
public boolean isFinished()Description copied from interface:ConnectionManager
was the server shutdown?- Specified by:
isFinished
in interfaceConnectionManager
- Returns:
- true, if the server was shut down; false otherwise
-
onConnect
We check that this socket is not banned. We do it just on connect so we save lots of queries. -
onData
public void onData(marauroa.server.net.nio.NioServer server, SocketChannel channel, byte[] data, int count)This method is called when new data is received on server from channel. -
send
This method add a message to be delivered to the client the message is pointed to.- Specified by:
send
in interfaceConnectionManager
- Parameters:
internalChannel
- the channel to the clientmsg
- the message to be delivered.isPerceptionRequired
- true indicates that the message may not be skipped
-
close
This method disconnect a socket.- Specified by:
close
in interfaceConnectionManager
- Parameters:
channel
- the socket channel to close
-
run
public void run() -
onDisconnect
Removes stored parts of message for this channel at the decoder.- Specified by:
onDisconnect
in interfaceIWorker
- Parameters:
channel
- the channel to clear
-