Draft: Event system refactoring proposal [15h]
NOTE this is not a final proposal - it is an entry point for discussion
Some tasks that can be done without any significant problems:
-
move admin.execute command to Zmq/Notifd -
wrap response from admin result into some structure -
replace stateless bool with method -
initialize consumers when app starts -
merge heartbeat and regular events -
replace ifs with methods aka pipe, interface change etc
Below is a short description of the proposal for event system refactoring. Detailed discussion will be at the next Tango Kernel meeting (Q'3 2018).
Roughly speaking this refactoring aims to restructure existing classes [1] and code [2,3] preserving existing features:
- heartbeat
- reconnect
- compatibility
[1]
New classes structure [4]:
Below is an example of a new API usage (it is in Java but may give a feeling of how this should look like in c++ as well):
@Test
public void test_subscribe() throws Exception {
EventSubscriber subscriber = proxy.getEventSubscriber("zmq");//proxy comes from somewhere
EventSubscription subscription = subscriber.createOrGetSubscription("float_scalar","change");
try {
subscriber.getTransport().connect(subscription.getEndpoint());
subscription.setEventConsumer(EventConsumers.createSimpleCallbackConsumer(new EventCallback() {
@Override
public void onEvent(EventData data) {
System.out.println("onEvent");
}
@Override
public void onError(EventData data) {
System.out.println("onError");
}
}));
} catch (/*EventTransportConnectionFailed*/ IOException ex){
throw ex;
}
}
@Test
public void test_unsubscribe() throws Exception {
EventSubscriber subscriber = proxy.getEventSubscriber("zmq");
EventSubscription subscription = subscriber.createOrGetSubscription("float_scalar","change");
subscription.cancel();
}
@Test
public void test_transport_loop() throws Exception {
while (!Thread.currentThread().isInterrupted()) {
EventData event = transport.nextEvent();//transport is initialized somewhere i.e. heartbeat subscription
EventSubscription<?> subscription = EventSubscriptions.getFor(event);
subscription.getEventConsumer().consume(event);
}
}
@Test
public void test_heartbeat() throws Exception {
EventSubscriber subscriber = proxy.getEventSubscriber("zmq");
EventSubscription subscription = subscriber.createHeartbeatSubscription();
subscription.getTransport().connect(subscription.getEndpoint());
subscriber.startTransport();
}
P.S. do we need to support multicast?
Edited by Thomas Braun