add statemachine implementation, port collector to statemachine
refactor publisher to use state machine
fix bug in state machine
add subscriber protocol and test