opennars / Narjure

A Clojure implementation of the Non-Axiomatic Reasoning System proposed by Pei Wang.
GNU General Public License v2.0
43 stars 11 forks source link

Usage of register!/unregister! for actors #23

Closed marotili closed 8 years ago

marotili commented 8 years ago

IMO registering of actors should be moved outside of the actors. The server actors should be agnostic to the names of themselves and their dependencies to allow better mocking and dynamic behavior (e.g. replacing dependencies at run-time)

Developing and testing using the repl is harder if we use global state. If an actor crashes it will not be unregistered and it has to be manually unregistered.

Blocking calls inside the server behaviors lead to warnings (Uninstrumented methods or call-sites), so calling (whereis actor-name) inside the servers is error prone (Sometimes narjure/core.clj fails to initialize the actors)

A monitor or supervisor actor can be used to register the actors at a later stage. The server actors can be extended to handle a message

[:actor-msg actor-name actor] The handler can then set the internal reference to the actor, if the server actor is interested in it. The supervisor could broadcast that message whenever a server restarts.

For initialization, the actors initialization function can take additional parameters with their dependencies. If circular dependencies exist, the actors can be lazily initialized using the actor-msg.

TonyLo1 commented 8 years ago

Yes, I think you may be right on this. This was how it was done initially but then I changed it to have actors self register. I don't have a problem with this in principle, the only thing that is fiddly is managing the actor dependencies (between each other). This is another reason why it makes sense to use the 'from' pattern where possible to avoid the circular reference issues between actors.

patham9 commented 8 years ago

altough this handling would probably be better from software design perspective, it is not an issue.