YTread Logo
YTread Logo

Intro to the Akka Actor system, Behaviors factory, Types, FSM, and State

Mar 30, 2024
Let's look at the code, so let's see now it's these three things, so what is the active

system

? What is a behavior f

actor

y? F

actor

y and previous

types

. So let's take a look at it and see what he was trying to talk about. This is about these basics here so hello world so again we're going to go back and put this back in so what is the actual

system

the

behaviors

are clarifying the

types

the actual system we see here this part is a little bit short gray and what it represents is the part of the

akka

system that we simply do not know or do not know, do not need and do not want to know, this is how the whole system works behind the scenes, behind the scenes, but the actor The system for us is the guardian user, which will be the first actor that we create and from that actor we will start generating actors everywhere and we will be in a father and son relationship, so that will be what we will see now. in the behavior

factory

, so how can we build real actors with these factories?
intro to the akka actor system behaviors factory types fsm and state
And of course, if we're talking about archetypes, you know a little bit about other types, so the reactor system, the active system that you can see here, is just part of the basics of the account. and what you need to do to create that first asset that depends on all of them is call that constructor and pass another constructor of an actor in this case, what we have here is an actor that is defined simply by this application method, which is very sparse, it is a call to the very function of this object. What we can already see is that this actor system has this string uh here, which means that that is the type that the actor has, which is the same thing that we have here, which means that that type is the type of messages that this actor expects that the only messages that we can send, why we send them later, after creating this gatekeeper that we're creating, we're passing or sending a couple of messages to the software and this is just a little bit of, you know, a good practice in a way of saying "well, when you're done, your system has just finished, so you allow the system to close everything that is open to some services and some actors so some kind of coordinated change closure and we do this here just pressing keywords, this is not important, but what I'm trying to explain here so that we have the system active now and we see the types and um what What we see now are these

behaviors

here and these are the factories that allow us to create openings, yes, maybe we can start and yes, let's start from the beginning from the top, you can already see that this behavior contains this behavior which in turn contains this behavior, so the behaviors are created as Russian objectives and you put one inside and that's how you compose them in a very functional way and at the beginning what we have is this first behavior that says "well, me." I'm going to set up this actor just once and it runs right when you create the actor, that's the time we're going to create.
intro to the akka actor system behaviors factory types fsm and state

More Interesting Facts About,

intro to the akka actor system behaviors factory types fsm and state...

In this case, we are simply logging into something and what it expects is the input of this context, which is the context of the actor that the system will be responsible for passing it on with that context that in this case, for example, we are registering or you could do other things like enter the cells to maybe find out what the precise path name vector name of the actor is and through that you can also search for the children or generate more actors with this context, so this will run once, but where we actually have the part that actually deals with messages is this

factory

here. the factory suspects that the message is suspecting a message or string of type that we are configuring here and with that type of message and what we can do is again use the context which you can see now that the contest uses the context from the configuration. so it's composable and reusable and just log in again, that doesn't matter, maybe the most important part of all these behaviors is the one that might cause the most confusion at first, it's this part here where you can configure what is the next behavior for the next message?
intro to the akka actor system behaviors factory types fsm and state
So when you pass this first message, this will be received by this behavior here and what we are saying here is that it is okay for the next message the behavior that you are going to have. use is actually the same meaning, you have to go back and use the same behavior again, that's what we saw at the beginning, that we were saying that one of the three actions of the actor is the third, is that you need to designate the behavior. for the next message and here we are doing that and with this I guess we have a little bit of the case of what is an actor system, what are the messages and how well the build connector works, of course, there is not much to show here.
intro to the akka actor system behaviors factory types fsm and state
Yeah, maybe I'll load the svt and then I'll show it to you later and maybe some more meaningful examples in this case. Well, maybe what I can show here is, for example, first this compiles composites, sorry, compiled, so yeah, yeah, we should take this again. so that should work and well anyway I didn't want to run this so what I wanted to do is just let me see this is the basics run the basic right like hello world yeah let's look at one that's not very good , Yeah. so there we are, we are not working, we get the two messages there or we press yes, then we press o with the line and then it will end the system.
This is what we see here, the cognitive shutdown and I guess what I do. I wanted to show the simplicity of this beautiful thing here, let me see, yes, maybe it's quite simple, but the fact that this will not compile is actually very powerful, you can see where you see that you can see that in this message it was founded on the visual project flow three, yeah, we've done it wrong, so those are the guys and now just to expand, it's about the string at the beginning in this first example that we were talking about, okay, this actor is just you, you can send the strings to this actor and that's good, but in general the way you do things you send them proper messages, which means you create like a protocol, that protocol is the messages that you can send, it's even a little bit more complex than this, usually these messages extend from a trend or from an interface such that you can define that or put that interface here we will see how it works, but you can see that using the message as the type of directory that defines now use that same message is another factory that We have here, of course, this example is quite similar, it's a little bit different in the sense that we don't have a configuration, we have more context and therefore there is another factor that, instead of receiving a message that respects only one message as we see, we have seen before. just the message it's like there's a lot of factories and this is the one I want to use often which waits for the actual context and the message and that's where you match the message and then you can use the context for whatever you want to do but I guess the point I thought was most important is this: how can you configure behaviors so that they stop meaning, like the next message you try to send to this actor, it won't even work because you decided that this actor will stop, we talked about the steps of the system behavior factor and now the finite

state

machines and we find the stigma scenes.
We can see this example here again, very simple where you have the same network, Hello world, that before and now we have the received instead of the received message, so the factory that we saw that the finite

state

machine is here, you can see how It is happening that this is a way of creating the whole world. Apply will be the first input and method of the first message, so you can define here how you are going to handle it, this is how we handle it, you can just plug something in and then we are setting up what is the next behavior that will receive the next message, so now is not there, this will be for this second message will run it in this behavior and this behavior is the same, well, so that message is needed here, did you say message?
Sorry, I have to go so this behavior gives us a different output. message and at the end the next behavior that we are setting up here is stopped behavior, which means that as we saw before, this loop will stop and this third message that we are trying to send to the sector will never reach um when this happens. and then the system behind us that we saw here the entire system that we have behind us is taking care of those messages and it will do so and that message that it cannot be sent to the sector because this now appears stopped is no longer sent to a actor called the letters, so when I look at that one in this, I exactly duplicate the topic or something like that, so we can see that they get the message Hello world and the djca I'm sorry and there are no more messages than that.
So we lost that and we were able to through the settings and add the message there to see that the last messages were to the letter q broadcast in this case, so on the financial machines now the status is another uh which is one of the things The most important things we get to, one of the most surprising things is when you see that concurrency works when you have a state, which is usually the case, I mean a state that you can think about. about stateless functions, but that's the crux of the matter usually it's in the state and that's how you handle the stadium, it's extremely simple, so again the watchdog in this case has an actor in the sector in the method application. in your constructor you have um right now, but two parameters there is a counter which has a count like what is the current count that the message is at and a maximum number of increments it can or the maximum count it can have, so plus a little bit more about that and how that kind of this works, so we create this counter, we say okay, the initial count is going to be zero and the maximum count that we're going to allow for this is two, what we're doing now is just having three. and knowing that as we said the maximum is still, you will never reach three, it will reach its maximum, so now what we are saying is the increasing command and here we see what I mentioned before about the extension of a trait. we have the protocol, this is the protocol here and actually this is the protocol and now we extend from a command that is the type that you are the type of target that you have in this case it is a somewhat usual command also these notations for the semantics and we already saw that they received, so when you receive the message, you match the message in the cases where they increase, which is so far the only one we have, it will only increase the count and here is actually the important thing.
If the current is less than or equal to the maximum then they are still good and we don't get over the bumps, then here is the hard part to read at first, so what you are designating here will be the following behavior, which is the same, it is say, if they apply the supply again, but now it's passing two parameters, the current one, which is the incremented count and the maximum itself, so it still calls this method here to target that behavior. next message for the next message and for that behavior you will get this current and these flags as inputs and that is the way the state is maintained so every time the current increases it increases here and for the next behavior the next message, the behavior will maintain the state then and that's all this is this kind of is once you understand it it's very intuitive and it allows you to stop thinking about concurrency and locks and things like that, you just have your state inside the director and you handle it the way you think is what you need, in this case it's just a count, you take your variable there, you move it, you mix it and then you pass it to the next behavior, you don't need to worry about the rest of the world, this is the ending we were talking about at the beginning, so in the end you don't care what's happening in the colony, the end knows its job, that's just the only thing it needs to know and no coordination is needed, yeah, in that case.
This is this abstraction is extremely powerful as that is the key pointer with all the clustering and resilience, but this is the thing about state and locality, this is avoiding monetary problems, which is very, very difficult and then, in case it gets there you were already back and counting and you try to increase more, which is the case of your message now we simply stop here and what we already see a couple of times, I suppose you can also see this and continue to be number six and increase to one, increase to one and then we will receive the second message of yes, another only three or more keep coming or again not much to say today, but that is the state in which

If you have any copyright issue, please Contact