001 package com.hammurapi.eventbus.tests;
002
003 import java.util.concurrent.atomic.AtomicInteger;
004
005 import com.hammurapi.eventbus.Handler;
006 import com.hammurapi.eventbus.local.LocalEventDispatchContext;
007
008 public class PriorityHandler {
009
010 private AtomicInteger hpCounter = new AtomicInteger();
011 private AtomicInteger ahpCounter = new AtomicInteger();
012 private AtomicInteger lpCounter = new AtomicInteger();
013
014 @Handler(priority=10)
015 public void highPriority(LocalEventDispatchContext<Object, Integer, Object> ctx, String event) throws InterruptedException {
016 hpCounter.incrementAndGet();
017 Thread.sleep(500);
018 if ("Hello".equals(event)) {
019 ctx.consume(event);
020 }
021 }
022
023 @Handler(priority=11)
024 public void anotherHighPriority(String event) {
025 ahpCounter.incrementAndGet();
026 }
027
028 @Handler
029 public void lowPriority(String event) {
030 lpCounter.incrementAndGet();
031 }
032
033 public int getHpCounter() {
034 return hpCounter.get();
035 }
036
037 public int getAhpCounter() {
038 return ahpCounter.get();
039 }
040
041 public int getLpCounter() {
042 return lpCounter.get();
043 }
044 }