| 1 | package com.hammurapi.eventbus.tests; |
| 2 | |
| 3 | import com.hammurapi.common.Condition; |
| 4 | import com.hammurapi.eventbus.Handler; |
| 5 | import com.hammurapi.eventbus.local.LocalEventDispatchJoinContext; |
| 6 | |
| 7 | public class JoinHandlerWithCost { |
| 8 | |
| 9 | private int joinCounter; |
| 10 | private boolean joinOk; |
| 11 | |
| 12 | public boolean isJoinOk() { |
| 13 | return joinOk; |
| 14 | } |
| 15 | |
| 16 | public int getJoinCounter() { |
| 17 | return joinCounter; |
| 18 | } |
| 19 | |
| 20 | @Handler({ |
| 21 | "java(,world,)://world.equals(\"World\")", |
| 22 | "java(hello,world,i)://AND(i+((int) 'A')> (int) hello.charAt(0),i+((int) 'A')< (int) world.charAt(0))" |
| 23 | }) |
| 24 | public void join( |
| 25 | LocalEventDispatchJoinContext<Object, Integer, Object> context, |
| 26 | @Condition("COST(2*20,\"Hello\".equals(hello))") String hello, |
| 27 | String world, |
| 28 | int i) { |
| 29 | ++joinCounter; |
| 30 | joinOk = "Hello".equals(hello) && "World".equals(world) && i>'H'-'A' && i<'W'-'A'; |
| 31 | |
| 32 | context.post(hello+" "+world+" "+i); |
| 33 | } |
| 34 | } |