posthumecaver
posthumecaver

Reputation: 1853

Akka Typed and having base class for MessageAdapters

I am trying something with Akka Typed and Scala, actually something very simple as concept but I could not make it work so may be you can help me.

All my Actors will have one common Signal, so I try to place it to a base class and let my all Actors share it but it the compiler refuse it in the MessageAdapter....

So my code looks like following....

object ContractActor {
  sealed trait ContractEvent extends BaseEvent
  final case class onApprove(payload: Payload) extends ContractEvent
}

class ContractActor(ctx: ActorContext[ContractEvent]) extends BaseActor {
  val listingAdapter = : ActorRef[Receptionist.Listing] = ctx.
    messageAdapter(
      listing => onAddRelatedEvent(listing)
}

and base actor

object BaseActor {
  trait BaseEvent;
  final case class onAddRelatedEvent(listing: Receptionist.Listing) extends BaseEvent
}

The compiler complains about onAddRelatedEvent is not known on ContractEvent which surprise me because ContractEvent extends BaseEvent....

What am I missing here....

Upvotes: 0

Views: 90

Answers (1)

Leo C
Leo C

Reputation: 22449

Class ContractActor extending BaseActor does not automatically bring BaseActor's companion object into scope. To bring it into scope, just import it inside class ContractActor:

import BaseActor._

Alternatively, you could move the inner trait/case class into BaseActor's companion class.

Upvotes: 1

Related Questions