001 package com.hammurapi.eventbus.tests;
002
003 import java.util.concurrent.atomic.AtomicReference;
004
005 import com.hammurapi.common.Condition;
006 import com.hammurapi.eventbus.Handler;
007 import com.hammurapi.eventbus.EventHandlerBase.Mode;
008 import com.hammurapi.eventbus.local.LocalEventDispatchJoinContext;
009
010 public class HelperHandler2 {
011
012 private int worldCounter;
013 private boolean worldOk;
014
015 private int emCounter;
016 private boolean emOk;
017
018 public int getWorldCounter() {
019 return worldCounter;
020 }
021
022 public boolean isWorldOk() {
023 return worldOk;
024 }
025
026 public int getEmCounter() {
027 return emCounter;
028 }
029
030 public boolean isEmOk() {
031 return emOk;
032 }
033
034 @Handler("java(str)://str.get().equals(\"World\")")
035 public void handleWorld(AtomicReference<String> strRef) {
036 ++worldCounter;
037 worldOk = "World".equals(strRef.get());
038 }
039
040 @Handler //("\"!\".equals(args[0])")
041 public void handleEm(@Condition("\"!\".equals(strRef.get())") AtomicReference<String> strRef) {
042 ++emCounter;
043 emOk = "!".equals(strRef.get());
044 }
045
046 private int joinCounter;
047 private boolean joinOk;
048
049 public boolean isJoinOk() {
050 return joinOk;
051 }
052
053 public int getJoinCounter() {
054 return joinCounter;
055 }
056
057 /**
058 * Updates world to ! when Hello is posted.
059 * @param context
060 * @param hello
061 * @param worldRef
062 * @param i
063 */
064 @Handler("worldRef.get().equals(\"World\")")
065 public void join(
066 LocalEventDispatchJoinContext<Object, Integer, Object> context,
067 @Condition("\"Hello\".equals(hello)") String hello,
068 AtomicReference<String> worldRef) {
069 ++joinCounter;
070 joinOk = "Hello".equals(hello) && "World".equals(worldRef.get());
071
072 worldRef.set("!");
073 context.update(worldRef);
074 }
075 }