|
3 | 3 | import in.erail.common.FramworkConstants; |
4 | 4 | import io.vertx.core.Handler; |
5 | 5 | import io.vertx.core.json.JsonObject; |
| 6 | +import java.util.List; |
6 | 7 |
|
7 | 8 | /** |
8 | 9 | * |
9 | 10 | * @author vinay |
10 | 11 | */ |
11 | | -public class DefaultBridgeEventHandler implements Handler<BridgeEvent> { |
| 12 | +public class BridgeEventHandler implements Handler<BridgeEvent> { |
| 13 | + |
| 14 | + private List<String> mAddressAllowedToRegister; |
| 15 | + private List<String> mAddressAllowedToRegisterRegex; |
12 | 16 |
|
13 | 17 | @Override |
14 | 18 | public void handle(BridgeEvent pEvent) { |
@@ -52,15 +56,52 @@ public void handle(BridgeEvent pEvent) { |
52 | 56 |
|
53 | 57 | } |
54 | 58 |
|
55 | | - public void handlePublish(String pAddress, BridgeEvent pEvent) { |
56 | | - pEvent.complete(true); |
| 59 | + public void handleRegister(String pAddress, BridgeEvent pEvent) { |
| 60 | + if (mAddressAllowedToRegister.isEmpty() && mAddressAllowedToRegisterRegex.isEmpty()) { |
| 61 | + pEvent.complete(true); |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + if (!(matchAddress(pAddress) || matchAddressRegex(pAddress))) { |
| 66 | + pEvent.fail("Can't subscribe to topic : " + pAddress); |
| 67 | + } else { |
| 68 | + pEvent.complete(true); |
| 69 | + } |
57 | 70 | } |
58 | 71 |
|
59 | | - public void handleRecieve(String pAddress, BridgeEvent pEvent) { |
| 72 | + private boolean matchAddress(String pAddress) { |
| 73 | + return mAddressAllowedToRegister |
| 74 | + .stream() |
| 75 | + .anyMatch((allowedAddress) -> (pAddress.equals(allowedAddress))); |
| 76 | + } |
| 77 | + |
| 78 | + private boolean matchAddressRegex(String pAddress) { |
| 79 | + return mAddressAllowedToRegisterRegex |
| 80 | + .stream() |
| 81 | + .anyMatch((allowedAddress) -> (pAddress.matches(allowedAddress))); |
| 82 | + } |
| 83 | + |
| 84 | + public List<String> getAddressAllowedToRegister() { |
| 85 | + return mAddressAllowedToRegister; |
| 86 | + } |
| 87 | + |
| 88 | + public void setAddressAllowedToRegister(List<String> pAddressAllowedToRegister) { |
| 89 | + this.mAddressAllowedToRegister = pAddressAllowedToRegister; |
| 90 | + } |
| 91 | + |
| 92 | + public List<String> getAddressAllowedToRegisterRegex() { |
| 93 | + return mAddressAllowedToRegisterRegex; |
| 94 | + } |
| 95 | + |
| 96 | + public void setAddressAllowedToRegisterRegex(List<String> pAddressAllowedToRegisterRegex) { |
| 97 | + this.mAddressAllowedToRegisterRegex = pAddressAllowedToRegisterRegex; |
| 98 | + } |
| 99 | + |
| 100 | + public void handlePublish(String pAddress, BridgeEvent pEvent) { |
60 | 101 | pEvent.complete(true); |
61 | 102 | } |
62 | 103 |
|
63 | | - public void handleRegister(String pAddress, BridgeEvent pEvent) { |
| 104 | + public void handleRecieve(String pAddress, BridgeEvent pEvent) { |
64 | 105 | pEvent.complete(true); |
65 | 106 | } |
66 | 107 |
|
|
0 commit comments