Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Private Best way to catch Messages.

Newbie Spellweaver
Joined
Nov 21, 2011
Messages
66
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.
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.
 
Newbie Spellweaver
Joined
Aug 7, 2007
Messages
61
Reaction score
7
If you don't want active waits and/or sync issues, you should probably be using monitors. Multithreading isn't really simple, but it is easy once you get the hang of it. This way, you'd put the thread to sleep, and once it recieves something you notify it to get going. No need to actively wait for anything, nor to waste processing cycles.

Here's the documentation on , which give you even more flexibility on Java monitors.
 
Newbie Spellweaver
Joined
Nov 21, 2011
Messages
66
Reaction score
12
If you don't want active waits and/or sync issues, you should probably be using monitors. Multithreading isn't really simple, but it is easy once you get the hang of it. This way, you'd put the thread to sleep, and once it recieves something you notify it to get going. No need to actively wait for anything, nor to waste processing cycles.

Here's the documentation on , which give you even more flexibility on Java monitors.

I dont know that, i never see condition wow, its really amazing. I will study that :$



Is this a question or something?

There are multiple ways you can handle messages, queue them to a thread pool, handle them straight away or do whatever you want.

Its a "debate" wich you should say what form u prefer to execute messages, and u think what is the best way for you
 
topkek amirite??
Joined
May 16, 2009
Messages
751
Reaction score
696
In the example you showed regarding Icarus, it uses Netty. Under the hood, Netty processes events in a queue. You can define whether you want to use multiple queues for user events, IO events etc (aka loop groups) so it would be pretty damn pointless pushing those events to another queue (Comet supports handling messages in the current thread, handling them in another pool etc, feel free to take a look.. I don't recommend using any other method of handling messages other than the default method in production though; after much testing, I figured letting the Netty event loop handle it was the best way).

In other cases, if the message is initially read in the IO threads, you want to be pushing those messages to another queue to take the load away from the IO threads.

So yeah.. It honestly depends on so many other things. You might want to do some research into how your networking stack works if you want to squeeze every ounce of performance out of your code.
 
Last edited:
Newbie Spellweaver
Joined
Nov 21, 2011
Messages
66
Reaction score
12
In the example you showed regarding Icarus, it uses Netty. Under the hood, Netty processes events in a queue. You can define whether you want to use multiple queues for user events, IO events etc (aka loop groups) so it would be pretty damn pointless pushing those events to another queue (Comet supports handling messages in the current thread, handling them in another pool etc, feel free to take a look.. I don't recommend using any other method of handling messages other than the default method in production though; after much testing, I figured letting the Netty event loop handle it was the best way).

In other cases, if the message is initially read in the IO threads, you want to be pushing those messages to another queue to take the load away from the IO threads.

So yeah.. It honestly depends on so many other things. You might want to do some research into how your networking stack works if you want to squeeze every ounce of performance out of your code.


Male lion neither more nor less than I like this doubt seeing how he executed comet the messages. PS: Execelt job with that;)
 
Back
Top