gervais.b
gervais.b

Reputation: 2347

Akka, dropping earlier messages

I would like to drop earlier messages from an actor. The base idea is to have a timestamp on each message, store it for the last processed message message and drop messages earlier than this timestamp.

I am thinking to create mailbox for that, however I don't know:

  1. If it is a good idea to keep a state in a mailbox.
  2. How I can share the state of the actor (that has the timestamp) with the mailbox.

Maybe I am trying to something wrong and there is a better alternative for that ?

Thanks

Upvotes: 2

Views: 85

Answers (1)

senjin.hajrulahovic
senjin.hajrulahovic

Reputation: 3181

Writing a custom mailbox for that is overkill. You can solve it like this:

class MyActor extends Actor {

  val timestampLimit: LocalDateTime = ???

  def receive = {
    case m: Message if (m.getTimeStamp.isBefore(timestampLimit)) => // drop
    case m: Message                                              => // process
  } 
}

Upvotes: 1

Related Questions