Javatpoint Logo
Javatpoint Logo

Actor

An actor is an entity which communicates to other actor by message passing. Actor has it's own state and behavior. As in object-oriented programming everything is an object same like everything is an actor in actor-based system.

In other words, we can say that an actor is an object that encapsulates state and behavior.

How to create an Actor?

You can create actor by extending Actor trait and implementing it's receive method. This method is called each time a message is received by the actor. The receive method does pattern matching on the received message and decide what to do.

Here, we have created a simple "Hello Akka" program.

Hello Akka Example

Output:

Hello Akka
Unknown message

In the above example, we have created an actor "HelloAkka" by extending Actor trait and overriding receive method. You must provide match cases for all received messages. In case, if there is unknown message, you need to provide a default case as we did in above example.

Next TopicAkka ActorSystem





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA