Details
-
New Feature
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Currently GossipCore is a case statement. It would be better if we registered handlers. This would allows users to extend the protocol.
- We need a hashmap of Class -> Handler
- When GossipCore.receive(Base message) gets a message it gets the class of the message and looks it up in the hashmap
- Builder class allows users to specify other handlers
- Common handlers are enabled by default
Something like this:
if (base instanceof ShutdownMessage){ ShutdownMessage s = (ShutdownMessage) base; GossipDataMessage m = new GossipDataMessage(); m.setKey(ShutdownMessage.PER_NODE_KEY); m.setNodeId(s.getNodeId()); m.setPayload(base); m.setTimestamp(System.currentTimeMillis()); m.setExpireAt(System.currentTimeMillis() + 30L * 1000L); addPerNodeData(m); } if (base instanceof GossipDataMessage) { UdpGossipDataMessage message = (UdpGossipDataMessage) base; addPerNodeData(message); }
Replace with:
Map<Class,Handler> handlers... { handlers.put(ShutdownMessage.class, new ShutdownHandler(GossipCore); } Handler h = handlers.get(base.class) h.invoke(base)
Attachments
Issue Links
- links to