public static Props mkProps(ActorSystem system, ActorRef commandDispatcher, SagaRepository repository, ActorRef eventstore, String packageScanPath, String dispatcher) { Props singletonProps = Props.create(SagaManager.class, commandDispatcher, repository, eventstore, packageScanPath); if(dispatcher != null){ singletonProps = singletonProps.withDispatcher(dispatcher); } try { final ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create(system); system.actorOf(ClusterSingletonManager.props( singletonProps, "shutdown", settings), "sagamanagersingelton"); ClusterSingletonProxySettings proxySettings = ClusterSingletonProxySettings.create(system); proxySettings.withBufferSize(10000); return ClusterSingletonProxy.props("/user/eventstoresingelton", proxySettings); } catch (ConfigurationException e) { log.info("not cluster system"); return singletonProps; } }
@Override public void preStart() { try { Cluster cluster = Cluster.get(getContext().system()); cluster.subscribe(self(), ClusterEvent.MemberRemoved.class); log.info("{} subscribes to cluster events", self()); } catch (ConfigurationException e) { } final ActorSystem system = context().system(); try { Cluster cluster = Cluster.get(system); final ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create(system); system.actorOf(ClusterSingletonManager.props( EventstoreSingelton.mkProps(storage), "shutdown", settings), "eventstoresingelton"); ClusterSingletonProxySettings proxySettings = ClusterSingletonProxySettings.create(system); proxySettings.withBufferSize(10000); eventstoresingeltonProxy = system.actorOf(ClusterSingletonProxy.props("/user/eventstoresingelton", proxySettings), "eventstoresingeltonProxy"); } catch (ConfigurationException e) { log.info("not cluster system"); eventstoresingeltonProxy = system.actorOf(EventstoreSingelton.mkProps(storage)); } log.debug("Eventstore started with adress {}", getSelf().path()); }