| 1 | package com.hammurapi.eventbus.tests; |
| 2 | |
| 3 | import java.util.concurrent.atomic.AtomicReference; |
| 4 | |
| 5 | import com.hammurapi.common.Condition; |
| 6 | import com.hammurapi.eventbus.Handler; |
| 7 | import com.hammurapi.eventbus.EventHandlerBase.Mode; |
| 8 | import com.hammurapi.eventbus.local.LocalEventDispatchJoinContext; |
| 9 | |
| 10 | public class HelperHandler2 { |
| 11 | |
| 12 | private int worldCounter; |
| 13 | private boolean worldOk; |
| 14 | |
| 15 | private int emCounter; |
| 16 | private boolean emOk; |
| 17 | |
| 18 | public int getWorldCounter() { |
| 19 | return worldCounter; |
| 20 | } |
| 21 | |
| 22 | public boolean isWorldOk() { |
| 23 | return worldOk; |
| 24 | } |
| 25 | |
| 26 | public int getEmCounter() { |
| 27 | return emCounter; |
| 28 | } |
| 29 | |
| 30 | public boolean isEmOk() { |
| 31 | return emOk; |
| 32 | } |
| 33 | |
| 34 | @Handler("java(str)://str.get().equals(\"World\")") |
| 35 | public void handleWorld(AtomicReference<String> strRef) { |
| 36 | ++worldCounter; |
| 37 | worldOk = "World".equals(strRef.get()); |
| 38 | } |
| 39 | |
| 40 | @Handler //("\"!\".equals(args[0])") |
| 41 | public void handleEm(@Condition("\"!\".equals(strRef.get())") AtomicReference<String> strRef) { |
| 42 | ++emCounter; |
| 43 | emOk = "!".equals(strRef.get()); |
| 44 | } |
| 45 | |
| 46 | private int joinCounter; |
| 47 | private boolean joinOk; |
| 48 | |
| 49 | public boolean isJoinOk() { |
| 50 | return joinOk; |
| 51 | } |
| 52 | |
| 53 | public int getJoinCounter() { |
| 54 | return joinCounter; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Updates world to ! when Hello is posted. |
| 59 | * @param context |
| 60 | * @param hello |
| 61 | * @param worldRef |
| 62 | * @param i |
| 63 | */ |
| 64 | @Handler("worldRef.get().equals(\"World\")") |
| 65 | public void join( |
| 66 | LocalEventDispatchJoinContext<Object, Integer, Object> context, |
| 67 | @Condition("\"Hello\".equals(hello)") String hello, |
| 68 | AtomicReference<String> worldRef) { |
| 69 | ++joinCounter; |
| 70 | joinOk = "Hello".equals(hello) && "World".equals(worldRef.get()); |
| 71 | |
| 72 | worldRef.set("!"); |
| 73 | context.update(worldRef); |
| 74 | } |
| 75 | } |