package org.nryotaro.amanatsu.actor;

import akka.actor.AbstractActor;
import akka.actor.UntypedActor;
import org.nryotaro.amanatsu.service.CountingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


/**
 * An actor that can count using an injected CountingService.
 *
 * @note The scope here is prototype since we want to create a new actor
 * instance for use of this bean.
 */
@Component("CountingActor")
@Scope("prototype")
public class CountingActor extends AbstractActor {

  @Override
  public Receive createReceive() {
      
    return null;
  }

  public static class Count {}
  public static class Get {}

  // the service that will be automatically injected
  final CountingService countingService;

  @Autowired
  public CountingActor(CountingService countingService) {
    this.countingService = countingService;
  }

  private int count = 0;

  @Override
  public void onReceive(Object message) throws Exception {
    if (message instanceof Count) {
      count = countingService.increment(count);
    } else if (message instanceof Get) {
      getSender().tell(count, getSelf());
    } else {
      unhandled(message);
    }
  }
}

@@ -92,24 +92,95 @@
 typedActor;%0A
+import akka.japi.pf.ReceiveBuilder;%0Aimport akka.japi.pf.UnitPFBuilder;%0A
 import org.n
@@ -386,16 +386,63 @@
 ponent;%0A
+import org.springframework.stereotype.Service;%0A
 %0A%0A/**%0A *
@@ -715,16 +715,145 @@
 ctor %7B%0A%0A
+  private int count = 0;%0A%0A  // the service that will be automatically injected%0A  @Autowired%0A  CountingService countingService;%0A%0A%0A
   @Overr
@@ -899,33 +899,249 @@
     
- 
- %0A    return null
+return receiveBuilder()%0A            .match(Count.class, s -%3E count = countingService.increment(count))%0A            .match(Get.class, g -%3E getSender().tell(count, getSelf()))%0A            .matchAny(this::unhandled)%0A            .build()
 ;%0A  %7D%0A%0A
+%0A
   pu
@@ -1201,102 +1201,13 @@
 %7B%7D%0A%0A
+%0A
   /
-/ the service that will be automatically injected%0A  final CountingService countingService;%0A
+*
 %0A  @
@@ -1327,33 +1327,8 @@
  %7D%0A%0A
-  private int count = 0;%0A
 %0A  @
@@ -1611,10 +1611,15 @@
   %7D%0A  %7D%0A
+  */%0A
 %7D%0A

apply 2.5 style