import akka.actor.ActorRef;
import akka.actor.PoisonPill;
-import akka.persistence.UntypedPersistentActor;
+import akka.persistence.AbstractPersistentActor;
import com.google.common.annotations.Beta;
import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
import org.slf4j.Logger;
* @author Robert Varga
*/
@Beta
-public abstract class AbstractClientActor extends UntypedPersistentActor {
+public abstract class AbstractClientActor extends AbstractPersistentActor {
private static final Logger LOG = LoggerFactory.getLogger(AbstractClientActor.class);
private AbstractClientActorBehavior<?> currentBehavior;
return currentBehavior.persistenceId();
}
+ @Override
+ public void postStop() {
+ if (currentBehavior != null) {
+ currentBehavior.close();
+ }
+
+ super.postStop();
+ }
+
private void switchBehavior(final AbstractClientActorBehavior<?> nextBehavior) {
if (!currentBehavior.equals(nextBehavior)) {
if (nextBehavior == null) {
LOG.debug("{}: switched from {} to {}", persistenceId(), currentBehavior, nextBehavior);
}
+ currentBehavior.close();
currentBehavior = nextBehavior;
}
}
@Override
- public final void onReceiveCommand(final Object command) {
+ public Receive createReceive() {
+ return receiveBuilder().matchAny(this::onReceiveCommand).build();
+ }
+
+ @Override
+ public Receive createReceiveRecover() {
+ return receiveBuilder().matchAny(this::onReceiveRecover).build();
+ }
+
+ private void onReceiveCommand(final Object command) {
if (command == null) {
LOG.debug("{}: ignoring null command", persistenceId());
return;
}
}
- @Override
- public final void onReceiveRecover(final Object recover) {
+ private void onReceiveRecover(final Object recover) {
switchBehavior(currentBehavior.onReceiveRecover(recover));
}
protected abstract ClientActorBehavior<?> initialBehavior(ClientActorContext context);
+
+ protected abstract ClientActorConfig getClientActorConfig();
}