DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Java
  4. Supervision and Monitoring in Akka

Supervision and Monitoring in Akka

It's important to know your Akka actor hierarchy so you know how to react to failures. This guide covers the actor system and how you can supervise parents and children.

Prabhat Kashyap user avatar by
Prabhat Kashyap
·
May. 03, 17 · Tutorial
Like (8)
Save
Tweet
Share
8.97K Views

Join the DZone community and get the full member experience.

Join For Free

Supervision describes a dependency relationship between actors: the parent and child relationship. A parent is unique because it created the child actor, so the parent is responsible for reacting when failures happen in the child.

And the parent decides which choice needs to be selected. When a parent receives the failure signal from its child, depending on the nature of the failure, the parent decides from following options:

  • Resume: Parent starts the child actor, keeping its internal state.

  • Restart: Parent starts the child actor by clearing its internal state.

  • Stop: Stop the child permanently.

  • Escalate: Escalate the failure by failing itself and propagating the failure to its parent.

akka-life-cycle

Akka Actor Lifecycle

It is always important to view all parts of the supervision hierarchy, which explains the escalate option. Each supervisor should cover all possible failure cases.

Actor System

Actor System

/user: The User Guardian Actor

An actor created using system.actorOf() are children of the user guardian actor. Whenever a user guardian terminates, all user-created actors will be terminated, too. Top-level user-created actors are determined by the user guardian actor as to how they will be supervised. Root Guardian is the supervisor of the user guardian.

/root: The Root Guardian

The root guardian actor is the father of the actor system. It supervises the user guardian actor and system guardian actor.

Supervision Strategies

There are two types of supervision strategies that we follow to supervise any actor:

  1. One-For-One

  2. One-For-All

case object ResumeException extends Exception
case object StopException extends Exception

case object RestartException extends Exception

override val supervisorStrategy =

    OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 second){

    case ResumeException => Resume

    case RestartException => Restart

    case StopException => Stop

    case _: Exception => Escalate 

}



Example of One-For-One Strategy

What is Monitoring?

Lifecycle Monitoring in Akka is usually referred to as DeathWatch

Monitoring is thus used to tie one actor to another so that it may react to the other actor’s termination, in contrast to supervision which reacts to failure.

Monitoring

Monitoring is particularly useful if a supervisor cannot simply restart its children and has to terminate them, such as in the case of errors during actor initialization. In that case, it should monitor those children and re-create them or schedule itself to retry this at a later time.

Code Repository: Supervision and Monitoring

Akka (toolkit)

Published at DZone with permission of Prabhat Kashyap, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Three SQL Keywords in QuestDB for Finding Missing Data
  • Cloud-Native Application Networking
  • Data Mesh vs. Data Fabric: A Tale of Two New Data Paradigms
  • GPT-3 Playground: The AI That Can Write for You

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: