title: Scala actors and shared state
body: <p>I am trying to implement a dispatcher actor that either process the request or delegates the processing to another actor in case of failure (actually it is the exponential backoff algorithm). The dispatcher actor has a boolean variable that is used to decide how to route the processing.</p>
  
  <p>Is it correct to mantain some state in the actor? What problems could happen? Should I use a transactor (akka) or STM to avoid problems? (I am using akka actors)</p>
  
  <pre><code>class DispatcherActor extends Actor {
  
     var backoff = false
  
     def receive = {
      case SendMessage(registrationId, message) =&gt; {
        if (backoff) {
          //put on the queue
          backoffManagerActor ! AddMessageToQueue(message)
        } else {
          httpClient.sendNotificationToClient(message, this)
        }
      }
      case BackoffCompleted =&gt; //set backoff to false
        backoff = false
      }
  
     def otherMethod = {
        backoff=true
     } 
  }
  </code></pre>