Last minute awesomization of the priority based mailbox API docs

This commit is contained in:
Viktor Klang 2012-02-21 18:24:38 +01:00
parent 2b4c8b2508
commit 98b74a974c
2 changed files with 21 additions and 31 deletions

View file

@ -123,30 +123,21 @@ public class DispatcherDocTestBase {
}
//#prio-mailbox
public static class PrioMailbox implements MailboxType {
static final PriorityGenerator generator = new PriorityGenerator() { // Create a new PriorityGenerator, lower prio means more important
@Override
public int gen(Object message) {
if (message.equals("highpriority"))
return 0; // 'highpriority messages should be treated first if possible
else if (message.equals("lowpriority"))
return 100; // 'lowpriority messages should be treated last if possible
else if (message.equals(Actors.poisonPill()))
return 1000; // PoisonPill when no other left
else
return 50; // We default to 50
}
};
private UnboundedPriorityMailbox priorityMailbox;
public static class PrioMailbox extends UnboundedPriorityMailbox {
public PrioMailbox(Config config) { // needed for reflective instantiation
priorityMailbox = new UnboundedPriorityMailbox(generator);
}
public MessageQueue create(Option<ActorContext> owner) {
return priorityMailbox.create(owner);
super(new PriorityGenerator() { // Create a new PriorityGenerator, lower prio means more important
@Override
public int gen(Object message) {
if (message.equals("highpriority"))
return 0; // 'highpriority messages should be treated first if possible
else if (message.equals("lowpriority"))
return 100; // 'lowpriority messages should be treated last if possible
else if (message.equals(Actors.poisonPill()))
return 1000; // PoisonPill when no other left
else
return 50; // We default to 50
}
});
}
}
//#prio-mailbox