- Joined
- Nov 21, 2011
- Messages
- 67
- Reaction score
- 12
Hello,
It's about saying which you think is best and why.
1.- The "classic". When we get a message we just call the requests class, exactly to the map and we have it execute, without opening another thread, in the same as the user-connection. An example of this is Icarus from Quackster.
2.- This method I have seen and I have programmed it and it is not difficult at all. It consists of creating a Queue list of an object(QueueItem)that contains the session and the clientmessage. When a request arrives we create a queue object that we store in the QueueMessages list. On the other hand there is a pool of threads picking up these messages and executing them (Sync problem detected). An example:
I get the package with header 4000.
RequestMessage.QueueList.add (new QueueItem (session, clientmessage))
On the other hand, the pool of threads would be in a continuous loop, such as:
While (alive) {
NextQueue = RequestMessages.QueueList.Dequeue ()
Message = nextQueue.message
Session = nextQueue.session
RequestMessages.MessageList.get (message.header) .execute (session, message)
wait(DELAY_TIME)
}
I do not know if I have explained myself completely, I hope you can understand what I mean.
It's about saying which you think is best and why.
1.- The "classic". When we get a message we just call the requests class, exactly to the map and we have it execute, without opening another thread, in the same as the user-connection. An example of this is Icarus from Quackster.
Code:
// OnMessage:
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
try {
Player player = (Player) ctx.getChannel().getAttachment();
NettyRequest request = (NettyRequest) e.getMessage();
if (request == null) {
return;
}
if (Util.getConfiguration().get("Logging", "log.packets", Boolean.class)) {
Log.println("Received: " + request.getMessageId() + " / " + request.getMessageBody());
}
if (player != null){
Icarus.getServer().getMessageHandler().handleRequest(player, request);
}
} catch (Exception ex) {
Log.exception(ex);
}
}
public void handleRequest(Player player, ClientMessage message) {
if (messages.containsKey(message.getMessageId())) {
messages.get(message.getMessageId()).handle(player, message);
}
}
2.- This method I have seen and I have programmed it and it is not difficult at all. It consists of creating a Queue list of an object(QueueItem)that contains the session and the clientmessage. When a request arrives we create a queue object that we store in the QueueMessages list. On the other hand there is a pool of threads picking up these messages and executing them (Sync problem detected). An example:
I get the package with header 4000.
RequestMessage.QueueList.add (new QueueItem (session, clientmessage))
On the other hand, the pool of threads would be in a continuous loop, such as:
While (alive) {
NextQueue = RequestMessages.QueueList.Dequeue ()
Message = nextQueue.message
Session = nextQueue.session
RequestMessages.MessageList.get (message.header) .execute (session, message)
wait(DELAY_TIME)
}
I do not know if I have explained myself completely, I hope you can understand what I mean.