Search code examples
javasimgrid

SimGrid. Receive only specified type of task


This is method for receiving сertain type of task by Host:

task = Task.receive(String mailbox);
    if (task instanceof SomeTask):
        SomeTask sometesk = (SomeTask) task;
        // Do something

But is there any way to receive directly sometask like sometask = Sometask.receive(String mailbox)?


Solution

  • Filtering the tasks that you want to receive is not as developed in Java than in the C version of MSG (yet).

    Use anther mailbox to not mix the tasks, it will avoid the difficulty of sorting them out afterward.

    There is no trivial example in SimGrid examples, but several applications use this feature. For example the bittorrent example (that is clearly not trivial) use one mailbox for the regular communications intended to the current host, and another mailbox to receive messages from the tracker. That way, you cannot get a message from a random peer when you expect a message from the tracker.