1 | package com.hammurapi.eventbus.tests; |
2 | |
3 | import com.hammurapi.common.Condition; |
4 | import com.hammurapi.eventbus.Handler; |
5 | import com.hammurapi.eventbus.EventHandlerBase.Mode; |
6 | import com.hammurapi.eventbus.local.LocalEventDispatchJoinContext; |
7 | |
8 | public class JoinHandler { |
9 | |
10 | private int helloCounter; |
11 | private boolean helloOk; |
12 | |
13 | public int getHelloCounter() { |
14 | return helloCounter; |
15 | } |
16 | |
17 | public boolean isHelloOk() { |
18 | return helloOk; |
19 | } |
20 | |
21 | private int joinCounter; |
22 | private boolean joinOk; |
23 | |
24 | public boolean isJoinOk() { |
25 | return joinOk; |
26 | } |
27 | |
28 | public int getJoinCounter() { |
29 | return joinCounter; |
30 | } |
31 | |
32 | @Handler("java(str)://str.equals(\"Hello\")") |
33 | public String handleHello(String str) { |
34 | ++helloCounter; |
35 | helloOk = "Hello".equals(str); |
36 | return "World"; |
37 | } |
38 | |
39 | @Handler({ |
40 | "java(,world,)://world.equals(\"World\")", |
41 | "java(hello,world,i)://AND(i+((int) 'A')> (int) hello.charAt(0),i+((int) 'A')< (int) world.charAt(0))" |
42 | }) |
43 | public void join( |
44 | LocalEventDispatchJoinContext<Object, Integer, Object> context, |
45 | @Condition("\"Hello\".equals(hello)") String hello, |
46 | String world, |
47 | int i) { |
48 | ++joinCounter; |
49 | joinOk = "Hello".equals(hello) && "World".equals(world) && i>'H'-'A' && i<'W'-'A' && Mode.POST.equals(context.getMode()); |
50 | |
51 | context.post(hello+" "+world+" "+i); |
52 | } |
53 | } |