Java – naming convention for akka messages and actors

I am currently making a very large Java application based on akka. I have encountered several problems and I am not finished

My current package layout looks like this:

My mobile course serves as the director of the actors in the actor pack

Since I don't want to create a new set of actors for each httpclient and account, I pass the message object in the message object to the endpoint actorref that receives the final result together with the endpoint actorref stored in the message package However, this creates a very chaotic message package, and each actor has a different message For example Mobileforactor1, actor1 for mobile, mobileforactor2, etc Now my question is whether there is a convention to deal with this kind of thing, which is my structure (Mobile - > actor1 - > Mobile - > actor2 - > etc.) How akka wants to do this, or I have to just arrange messages (Mobile - > actor1 - > actor2 - > etc.)

Now I send a connectmessage to my mobile actor, and then it sends it to actor1. Actor1 processes it and sends a new message back to mobile. Mobile sends the response and then to actor2. The loop continues to create an old message based on the old message For example New message2 (message1.foo, message1.bar, message1.baz, newcomputedresult, newcomputedresult2, etc.);

Is this a good practice, or should we include old instances (which may contain information that is no longer useful) and include new things? For example New message2 (message1, newcomputedresult2, etc.);

Or should we do something completely different?

I want to use typedactors, but those who need to use waterfall mode, I don't know how to pass the actorref of the listener who wants to receive the final result

I hope I can understand it, because English is not my girl language, and this problem is clear to everyone

I am a developer who started akka and like the idea, but because the documentation is not perfect, I think this is the best place Thank you for reading!

Solution

Because I dealt with the same problem on akka's learning curve, I will make a few comments I think you are asking for some rules of thumb, so mine is included here

First of all, creating actors is very cheap; They are very light So why not create one for each httpclient and account and give them the appropriate name derived from their identity? This also avoids having to pass them as much as possible, possibly abandoning your code

Second, keep your message short, focused, and start with a verb Every message should tell the actor to do something so that you can reflect the name by using verbs

Third, the news goes with the actors I usually declare them in the companion object of the actor class, so I use them like actorclass Messagename, unless it is in actorclass and only messagename

Fourth, add the name of an actor I often just combine a counter (using atomicinteger) with a type name (car-1, CAR-2, etc.)

If hierarchy is important to you, I recommend appending only the parent actor to the name Car-7 contains the meaning of "phone-1-in-car-7", that is, phone-1 You can then combine hierarchies programmatically and manually by following parent links

I think the "message" in connectmessage is redundant Just make the message name "connect", or better "connecttothing" (anyway, if relevant)

I won't compound your message names too much, just like you prompt with message2 Using the minimum amount of information is useful for who reads these names I think the lack of response to this may be due to part of your question I found it confusing because there were no details

I hope this will help

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>