Home How to store state in an Actor
Reply: 0

How to store state in an Actor

user45627 Published in September 19, 2018, 11:44 am

I am using the AKKA framework for concurrency with Java and have the following use case

The actors operate on a graph data structure and work on each node in the graph in a specific order and do not proceed to the next until a node is processed

Here is the relevant code

if (msg instanceof processGraph) {

      // For each level in the graph create a child at each level, for nodes on the same level create child actors simultaneously

      BreadthFirstIterator bfs = new BreadthFirstIterator<>(graph);
        while (bfs.hasNext()) {
          ActorRef NodeProcesor = getContext().actorOf(NodeProcesor.props());
             NodeProcesor.tell(send the node),



Now the question is, while the nodes of one graph are getting processed a new graph may be handed over to the GraphProcessor, this will confuse the actor from tracking the state of the graph? How do I correctly maintain this informtaion?

share|improve this question
  • Possible duplicate of Correct pattern for accumulating state in an Akka actor – Raman Mishra Apr 17 at 3:43
  • Yes, an example in Java is what I was looking for, – user_mda Apr 17 at 14:58
  • I think it should not be hard to convert Scala code into java – Raman Mishra Apr 17 at 14:59
  • I dont understand Scala and it is difficult to understand a problem when I am unsure of what the solution is. The link also seems to solve a different problem than what I am looking for, again I might be wronly interpreting a language I do no completely understand – user_mda Apr 17 at 15:06
  • See you want to store the state of an actor, so the basics says you must have done it in the Prestop phase of an actor now it doesn’t matter in what language you are going to implement it. – Raman Mishra Apr 17 at 15:11

active oldest votes

Your Answer

StackExchange.ifUsing("editor", function () { StackExchange.using("externalEditor", function () { StackExchange.using("snippets", function () { StackExchange.snippets.init(); }); }); }, "code-snippets"); StackExchange.ready(function() { var channelOptions = { tags: "".split(" "), id: "1" }; initTagRenderer("".split(" "), "".split(" "), channelOptions); StackExchange.using("externalEditor", function() { // Have to fire editor after snippets, if snippets enabled if (StackExchange.settings.snippets.snippetsEnabled) { StackExchange.using("snippets", function() { createEditor(); }); } else { createEditor(); } }); function createEditor() { StackExchange.prepareEditor({ heartbeatType: 'answer', convertImagesToLinks: true, noModals: false, showLowRepImageUploadWarning: true, reputationToPostImages: 10, bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".discard-answer" ,immediatelyShowMarkdownHelp:true }); } });
StackExchange.ready( function () { StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49864861%2fhow-to-store-state-in-an-actor%23new-answer', 'question_page'); } );

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged asynchronous graph akka state or ask your own question.

StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); }) (function(i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); StackExchange.ready(function () { StackExchange.ga.init({ sendTitles: true, tracker: window.ga, trackingCodes: [ 'UA-108242619-1' ] }); StackExchange.ga.setDimension('dimension2', '|asynchronous|graph|akka|state|'); StackExchange.ga.setDimension('dimension3', 'Questions/Show'); StackExchange.ga.trackPageView(); }); /**/ var _qevents = _qevents || [], _comscore = _comscore || []; (function() { var ssl = 'https:' == document.location.protocol, s = document.getElementsByTagName('script')[0], qc = document.createElement('script'); qc.async = true; qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve.com/quant.js'; s.parentNode.insertBefore(qc, s); _qevents.push({ qacct: "p-c1rF4kxgLUzNc" }); /**/ var sc = document.createElement('script'); sc.async = true; sc.src = (ssl ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js'; s.parentNode.insertBefore(sc, s); _comscore.push({ c1: "2", c2: "17440561" }); })();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.29747 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO