package com.example;

import akka.actor.ActorSystem;
import akka.actor.ActorRef;
import akka.pattern.CircuitBreaker;
import akka.pattern.Patterns;
import akka.util.Timeout;
import scala.concurrent.Future;
import scala.concurrent.duration.FiniteDuration;
import static scala.compat.java8.FutureConverters.*;

/**
 * Modified version of the new project from typesafe demonstrating mailbox config
 * and circuitbreaker
 */

public class ApplicationMain {

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("MyActorSystem");
        ActorRef pingActorWithMailbox = system.actorOf(PingActor.props().withMailbox("akka.actor.boundedmailbox"), "pingActor");

        pingActorWithMailbox.tell(new PingActor.Initialize(), null);

        ActorRef pongActor = system.actorOf(PingActor.props().withMailbox("akka.actor.boundedmailbox"), "pingActor2");

        CircuitBreaker breaker =
                new CircuitBreaker(system.scheduler(),
                        1,
                        FiniteDuration.create(1, "second"),
                        FiniteDuration.create(1, "second"),
                        system.dispatcher()).
                        onOpen(() -> {
                            System.out.println("circuit breaker opened!");
                        }).
                        onClose(() -> {
                            System.out.println("circuit breaker opened!");
                        }).
                        onHalfOpen(() -> {
                            System.out.println("circuit breaker opened!");
                        });

        Timeout timeout = Timeout.longToTimeout(2000L);

        Future future1 = breaker.callWithCircuitBreaker(()
                -> Patterns.ask(pongActor, new PingActor.PingMessage("ping"), timeout));

        Future future2 = breaker.callWithCircuitBreaker(()
                -> Patterns.ask(pongActor, new PingActor.PingMessage("ping"), timeout));


        toJava(future1).handle((x,t) -> {
            if(t != null){
                System.out.println("got it: " + x);
            }else{
                System.out.println("error: " + t.toString());
            }
            return null;
        });

        toJava(future2).handle((x,t) -> {
            if(t != null){
                System.out.println("got it: " + x);
            }else{
                System.out.println("error: " + t.toString());
            }
            return null;
        });

        //play around with sending futures and see how the breaker responds

        system.awaitTermination();
    }

}
@@ -1396,36 +1396,36 @@
 circuit breaker 
-open
+clos
 ed!%22);%0A         
@@ -1542,32 +1542,37 @@
 circuit breaker 
+half 
 opened!%22);%0A     
@@ -2579,8 +2579,9 @@
     %7D%0A%0A%7D
+%0A

Update ApplicationMain.java