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

**URL:** <https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343>\
**Category:** Persistence / Event Sourcing\
**Tags:** akka-typed\
**Created:** [March 19, 2018, 10:31am UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343 "2018-03-19T10:31:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pawelkaczor](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pawelkaczor](https://discuss.akka.io/u/pawelkaczor)\
**Post date:** [March 19, 2018, 10:31am UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/1 "2018-03-19T10:31:07Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![patriknw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/patriknw/32/89_2.png) [@patriknw](https://discuss.akka.io/u/patriknw)\
**Post date:** [March 19, 2018, 10:54am UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/2 "2018-03-19T10:54:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pawelkaczor](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pawelkaczor](https://discuss.akka.io/u/pawelkaczor)\
**Post date:** [March 19, 2018, 11:07am UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/3 "2018-03-19T11:07:38Z")

</div>

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

```auto
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](https://github.com/akka/akka/blob/master/akka-actor-typed/src/main/scala/akka/actor/typed/Behavior.scala#L335)

---

<div class="post-metadata">

**Author:** ![patriknw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/patriknw/32/89_2.png) [@patriknw](https://discuss.akka.io/u/patriknw)\
**Post date:** [March 19, 2018, 12:18pm UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/4 "2018-03-19T12:18:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pawelkaczor](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pawelkaczor](https://discuss.akka.io/u/pawelkaczor)\
**Post date:** [April 16, 2018, 8:15am UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/5 "2018-04-16T08:15:21Z")

</div>

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

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![patriknw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/patriknw/32/89_2.png) [@patriknw](https://discuss.akka.io/u/patriknw)\
**Post date:** [April 16, 2018, 1:30pm UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/6 "2018-04-16T13:30:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pawelkaczor](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pawelkaczor](https://discuss.akka.io/u/pawelkaczor)\
**Post date:** [April 16, 2018, 2:22pm UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/7 "2018-04-16T14:22:00Z")

</div>

Perhaps this helps:

```java
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()
		);
	}
}

```

---

<div class="post-metadata">

**Author:** ![patriknw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/patriknw/32/89_2.png) [@patriknw](https://discuss.akka.io/u/patriknw)\
**Post date:** [April 16, 2018, 9:55pm UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/8 "2018-04-16T21:55:36Z")

</div>

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](https://github.com/akka/akka/issues)

---

<div class="post-metadata">

**Author:** ![pawelkaczor](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pawelkaczor](https://discuss.akka.io/u/pawelkaczor)\
**Post date:** [April 17, 2018, 7:26am UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/9 "2018-04-17T07:26:31Z")

</div>

Isseue created: [https://github.com/akka/akka/issues/24915](https://github.com/akka/akka/issues/24915)

---

<div class="post-metadata">

**Author:** ![ktoso](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/ktoso/32/19_2.png) [@ktoso](https://discuss.akka.io/u/ktoso)\
**Post date:** [April 24, 2018, 12:18am UTC](https://discuss.akka.io/t/cannot-wrap-persistent-behavior-in-behaviors-setup-behaviors-supervise-or-similar/343/10 "2018-04-24T00:18:25Z")

</div>

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