title: Akka Actors - Lock single resource request
body: <p>I'm using several akka actors to monitor my system, each responsible for a different component.</p>
  
  <p>Some of the actors operations should not be performed in parallel.
  So I created an actor which holding a lock (LockActor).
  Once actor wants to perform such operation, he need to ask for approval from the LockActor and he cannot perform the operation till he get the approval.</p>
  
  <p>If I want to make the code simple, in the requested actor I need to do somthing like:</p>
  
  <pre><code>while (LockActor.isLockHold()) {
      // perform the operation
  }
  </code></pre>
  
  <p>This is of course breaks the whole design of actors system...</p>
  
  <p>So I need to use messages which make the code a little bit complicated:</p>
  
  <ol>
  <li>Actor B need to send LockRequestMessage to the LockActor</li>
  <li>LockActor is holding queue which hold lock requests</li>
  <li>If the lock is possible, the LockActor send LockApprovalMessage to the first actor in the queue</li>
  <li>When actor B recieve LockApprovalMessage (not necessarily immediately) he need to perform the specific operation that was needed when he sent the LockRequestMessage (each actor can have several operations that need the lock)</li>
  </ol>
  
  <p>So my question is - what is the best way implement such thing without breaking the actor system design but still keeping the code as simple as possible?</p>