Cannot wrap persistent behavior in Behaviors.setup, Behaviors.supervise or similar

Hi,

I’m prototyping a system using the brand new akka-typed Java API with Persistence, Cluster and Sharding.

Currently I’m hit by the following exception:

java.lang.IllegalArgumentException: cannot wrap behavior [XXX@7fc28be1] in Behaviors.setup, Behaviors.supervise or similar
	at akka.actor.typed.Behavior$.interpret(Behavior.scala:309)

when trying to tap (akka.actor.typed.javadsl.Behaviors#tap) a persistent behavior.

I’m using akka 2.5.11 but I tried also latest timestamped snapshot.

Please advise.

This will be solved in next version. Pull request is already merged. I think there is an issue with the timestamped snapshots at the moment. I’ll look into that. It should be included in 2.5-SNAPSHOT if you are eager to try it.

I just tested against 2.5-SNAPSHOT. The same error:

java.lang.IllegalArgumentException: cannot wrap behavior [XXX@47d9baa0] in Behaviors.setup, Behaviors.supervise or similar
	at akka.actor.typed.Behavior$.interpret(Behavior.scala:336)

See: https://github.com/akka/akka/blob/master/akka-actor-typed/src/main/scala/akka/actor/typed/Behavior.scala#L335

Thanks for testing and reporting. That is an oversight and I created issue https://github.com/akka/akka/issues/24753

After upgrading to Akka 2.5.12 I tested again. Now I get the following error:

java.lang.ClassCastException: akka.persistence.RecoveryPermitter$RecoveryPermitGranted$ cannot be cast to mypackage.JobScheduleCommand
	at akka.actor.typed.javadsl.Behaviors$.$anonfun$tap$1(Behaviors.scala:179)
	at akka.actor.typed.javadsl.Behaviors$.$anonfun$tap$1$adapted(Behaviors.scala:179)
	at akka.actor.typed.internal.BehaviorImpl$.$anonfun$tap$1(BehaviorImpl.scala:94)
	at akka.actor.typed.internal.BehaviorImpl$Intercept.receive(BehaviorImpl.scala:163)
	at akka.actor.typed.Behavior$.interpret(Behavior.scala:341)
	at akka.actor.typed.Behavior$.interpretMessage(Behavior.scala:318)
	at akka.actor.typed.internal.adapter.ActorAdapter.akka$actor$typed$internal$adapter$ActorAdapter$$handleMessage(ActorAdapter.scala:64)
	at akka.actor.typed.internal.adapter.ActorAdapter$$anonfun$running$1.applyOrElse(ActorAdapter.scala:60)

That is interesting. Can you show how you define this PersistenceBehavior or how we can reproduce this issue? I’m specifically curious about where that tap/intercept comes from. I think I understand what could be causing that but it would be good to confirm that guess.

Perhaps this helps:

public class SingletonScheduler {

	public static ActorRef<JobScheduleCommand> scheduler(ActorSystem as) {
		return ClusterSingleton.get(as).spawn( 
				jobScheduling(), 
				"GlobalJobScheduler",
				Props.empty(), 
				ClusterSingletonSettings.create(as),
				new Stop()
		);
	}

	private static Behavior<JobScheduleCommand> jobScheduling() {
		return tap(
				(ctx, cmd) -> { 
					ctx.getLog().info("Job Scheduler received command: {}", cmd);
				},
				(ctx, signal) -> {
					ctx.getLog().debug("Job Scheduler received signal: {}", signal);
				},
				new JobScheduling()
		);
	}
}

Ok, thanks. It’s the combination of tap and PersistentBehavior that is not working. Please create an issue at https://github.com/akka/akka/issues

Isseue created: https://github.com/akka/akka/issues/24915

Thanks for reporting; this has now been resolved: https://github.com/akka/akka/pull/24961