This is an initial PR for the refactoring of the code base. Despite massive changes, the intention is try our best to have it at least as stable as dev. Below are the key initial design changes focused on radical decoupling of the classes and SOA (Service-oriented architecture)
ServiceManager class is introduced as a static inner class in Pendulum. It keeps Class-based references to the service classes which are singletons. The service manager is itself a singleton and is intended to be used as follows. Whenever you need access to a service, say ValidationManagerService, simply obtain a reference as follows:
This will lead to a much cleaner code as you don't need to pass multiple references to the constructors and method arguments. In fact, you can even use the idiom about in various init() methods which would simply Pendulum.injectDependencies() (which however can be left as is now without any side effects)
Events. Instead of tightly coupling services, the even driven model allows to subscribe to "events" and give classes more restrictive dependencies. An arbitrary data can be passed using EventContext, and event type should be added to the EventType enum. An example of this refactoring in action is the handling of new bytes received from a peer. UDPReciever fires a corresponding event on the data retrieval, thus moving the data processing away from the networking logic. (Before UDPReciever had to keep a reference to the Node class and keep an irrelevent processor executor to further handle the recieved bytes).
Further down the road, we should completely remove this reference and decouple the low-level networking threads, higher-level processing of the packets (e.g. validation), and managing the peers, as these are completely independent matters.
This is an initial PR for the refactoring of the code base. Despite massive changes, the intention is try our best to have it at least as stable as
dev
. Below are the key initial design changes focused on radical decoupling of the classes and SOA (Service-oriented architecture)ServiceManager
class is introduced as a static inner class inPendulum
. It keepsClass
-based references to the service classes which are singletons. The service manager is itself a singleton and is intended to be used as follows. Whenever you need access to a service, sayValidationManagerService
, simply obtain a reference as follows:This will lead to a much cleaner code as you don't need to pass multiple references to the constructors and method arguments. In fact, you can even use the idiom about in various
init()
methods which would simplyPendulum.injectDependencies()
(which however can be left as is now without any side effects)Events. Instead of tightly coupling services, the even driven model allows to subscribe to "events" and give classes more restrictive dependencies. An arbitrary data can be passed using EventContext, and event type should be added to the EventType enum. An example of this refactoring in action is the handling of new bytes received from a peer.
UDPReciever
fires a corresponding event on the data retrieval, thus moving the data processing away from the networking logic. (BeforeUDPReciever
had to keep a reference to theNode
class and keep an irreleventprocessor
executor to further handle the recieved bytes).Further down the road, we should completely remove this reference and decouple the low-level networking threads, higher-level processing of the packets (e.g. validation), and managing the peers, as these are completely independent matters.