The idea here is that aggregate instances (actors) are singletons. For a given aggregate id, only one actor can be running concurrently. So, I need to have a single actor that serializes access to aggregates, that's the AggregateManager.
Last active
August 29, 2015 14:03
-
-
Save Papipo/151d0acd4f69e81454ba to your computer and use it in GitHub Desktop.
Hahahacking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EventSourcing | |
class AggregateManager | |
include Celluloid | |
def instance_of(klass, id) | |
# So, in order to remove it when terminated, now I use supervise_as(), | |
# But I have to remove the exlusive mode because it can't be used with | |
# the blocks that supervise_as() uses under the hood. | |
# But now I don't think access to this method is serialized as it was | |
# with __exclusive__ | |
klass.supervise_as(id) unless Celluloid::Actor[id] && Celluloid::Actor[id].alive? | |
Celluloid::Actor[id] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EventSourcing | |
class AggregateManager | |
include Celluloid | |
exclusive | |
#On this first version I do that with the __exclusive mode__. | |
#The problem with this approach is that when I terminate an aggregate, | |
#due to inactivity timeout for example, it isn't removed from the registry. | |
def instance_of(klass, id) | |
Celluloid::Actor[id] = klass.send(:new) unless Celluloid::Actor[id] && Celluloid::Actor[id].alive? | |
Celluloid::Actor[id] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment