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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddServer(ConnectionManager server)Associate this object with a server.voiddisconnectClient(Channel channel)This method disconnect a socket.voidfinish()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 validatorConnectionValidatorso that other layers can manipulate it for banning IP.onConnect(ConnectionManager connectionManager, InetSocketAddress address, Object internalChannel)handles a connection from a clientvoidonDisconnect(ConnectionManager server, Object internalChannel)Removes stored parts of message for this channel at the decoder.voidonMessage(ConnectionManager server, Object internalChannel, Message msg)This method is called when data is received from a socket channelvoidRegister a listener for disconnection events.voidsendMessage(Message msg)This method add a message to be delivered to the client the message is pointed to.voidstart()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:INetworkServerManagerThis method inits the active object- Specified by:
startin interfaceINetworkServerManager
-
addServer
Associate this object with a server. This model a master-slave approach for managing network messages.- Specified by:
addServerin interfaceIServerManager- Parameters:
server- the master server.
-
finish
public void finish()This method notifies the thread to finish the execution- Specified by:
finishin interfaceINetworkServerManager
-
getMessage
This method blocks until a message is available- Specified by:
getMessagein interfaceINetworkServerManager- Returns:
- a Message
-
sendMessage
This method add a message to be delivered to the client the message is pointed to.- Specified by:
sendMessagein interfaceINetworkServerManager- Parameters:
msg- the message to be delivered.
-
disconnectClient
This method disconnect a socket.- Specified by:
disconnectClientin interfaceINetworkServerManager- Parameters:
channel- the socket channel to close
-
getValidator
Returns a instance of the connection validatorConnectionValidatorso that other layers can manipulate it for banning IP.- Specified by:
getValidatorin interfaceINetworkServerManager- Returns:
- the Connection validator instance
-
registerDisconnectedListener
Register a listener for disconnection events.- Specified by:
registerDisconnectedListenerin interfaceINetworkServerManager- Specified by:
registerDisconnectedListenerin interfaceIServerManager- Parameters:
listener- a listener for disconnection events.
-
getChannel
gets the channel associated with an internalChannel- Specified by:
getChannelin 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:
onConnectin interfaceIServerManager- Parameters:
connectionManager- IServeraddress- of the clientinternalChannel- internal channel object- Returns:
- the channel, if the connection was accepted;
nullotherwise
-
onDisconnect
Removes stored parts of message for this channel at the decoder.- Specified by:
onDisconnectin interfaceIServerManager- Parameters:
internalChannel- the channel to clearserver- ConnectionManager
-
onMessage
This method is called when data is received from a socket channel- Specified by:
onMessagein interfaceIServerManager- Parameters:
server- NioServerinternalChannel- internal channel objectmsg- a Message
-