Package marauroa.server.net
Class NetworkServerManager
java.lang.Object
marauroa.server.net.NetworkServerManager
- All Implemented Interfaces:
INetworkServerManager
,IServerManager
public final class NetworkServerManager
extends Object
implements IServerManager, INetworkServerManager
This is the implementation of a worker that sends messages, receives them, ...
This class also handles validation of connection and disconnection events
- Author:
- miguel
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addServer(ConnectionManager server)
Associate this object with a server.void
disconnectClient(Channel channel)
This method disconnect a socket.void
finish()
This method notifies the thread to finish the executiongetChannel(Object internalChannel)
gets the channel associated with an internalChannelThis method blocks until a message is availableReturns a instance of the connection validatorConnectionValidator
so that other layers can manipulate it for banning IP.onConnect(ConnectionManager connectionManager, InetSocketAddress address, Object internalChannel)
handles a connection from a clientvoid
onDisconnect(ConnectionManager server, Object internalChannel)
Removes stored parts of message for this channel at the decoder.void
onMessage(ConnectionManager server, Object internalChannel, Message msg)
This method is called when data is received from a socket channelvoid
Register a listener for disconnection events.void
sendMessage(Message msg)
This method add a message to be delivered to the client the message is pointed to.void
start()
This method inits the active object
-
Constructor Details
-
NetworkServerManager
Constructor- Throws:
IOException
- if there any exception when starting the socket server.
-
-
Method Details
-
start
public void start()Description copied from interface:INetworkServerManager
This method inits the active object- Specified by:
start
in interfaceINetworkServerManager
-
addServer
Associate this object with a server. This model a master-slave approach for managing network messages.- Specified by:
addServer
in interfaceIServerManager
- Parameters:
server
- the master server.
-
finish
public void finish()This method notifies the thread to finish the execution- Specified by:
finish
in interfaceINetworkServerManager
-
getMessage
This method blocks until a message is available- Specified by:
getMessage
in interfaceINetworkServerManager
- Returns:
- a Message
-
sendMessage
This method add a message to be delivered to the client the message is pointed to.- Specified by:
sendMessage
in interfaceINetworkServerManager
- Parameters:
msg
- the message to be delivered.
-
disconnectClient
This method disconnect a socket.- Specified by:
disconnectClient
in interfaceINetworkServerManager
- Parameters:
channel
- the socket channel to close
-
getValidator
Returns a instance of the connection validatorConnectionValidator
so that other layers can manipulate it for banning IP.- Specified by:
getValidator
in interfaceINetworkServerManager
- Returns:
- the Connection validator instance
-
registerDisconnectedListener
Register a listener for disconnection events.- Specified by:
registerDisconnectedListener
in interfaceINetworkServerManager
- Specified by:
registerDisconnectedListener
in interfaceIServerManager
- Parameters:
listener
- a listener for disconnection events.
-
getChannel
gets the channel associated with an internalChannel- Specified by:
getChannel
in interfaceINetworkServerManager
- Parameters:
internalChannel
- internel channel- Returns:
- Channel
-
onConnect
public Channel onConnect(ConnectionManager connectionManager, InetSocketAddress address, Object internalChannel)handles a connection from a client- Specified by:
onConnect
in interfaceIServerManager
- Parameters:
connectionManager
- IServeraddress
- of the clientinternalChannel
- internal channel object- Returns:
- the channel, if the connection was accepted;
null
otherwise
-
onDisconnect
Removes stored parts of message for this channel at the decoder.- Specified by:
onDisconnect
in interfaceIServerManager
- Parameters:
internalChannel
- the channel to clearserver
- ConnectionManager
-
onMessage
This method is called when data is received from a socket channel- Specified by:
onMessage
in interfaceIServerManager
- Parameters:
server
- NioServerinternalChannel
- internal channel objectmsg
- a Message
-