-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageController.py
34 lines (29 loc) · 1.22 KB
/
MessageController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from typing import NoReturn
import Message
from Component import Component
from handlers.MessageClientHandler import MessageClientHandler
from handlers.MessageDecisionHandler import MessageDecisionHandler
from handlers.MessageLeaderElectionHandler import MessageLeaderElectionHandler
from handlers.MessageLearnerCatchUpHandler import MessageLearnerCatchUpHandler
from handlers.MessageOneAHandler import MessageOneAHandler
from handlers.MessageOneBHandler import MessageOneBHandler
from handlers.MessageTwoAHandler import MessageTwoAHandler
from handlers.MessageTwoBHandler import MessageTwoBHandler
class MessageController:
def __init__(self, type: Component):
self.node = type
self.handlers = [
MessageOneAHandler,
MessageOneBHandler,
MessageTwoAHandler,
MessageTwoBHandler,
MessageClientHandler,
MessageDecisionHandler,
MessageLeaderElectionHandler,
MessageLearnerCatchUpHandler
]
def handle(self, message: Message) -> NoReturn:
for handler in self.handlers:
if handler.is_valid_handler_for(self.node.whoiam, message):
handler.handle(self.node, message)
break