Pergunta

I have an actor system that hosts a round robin router actor that has as routees a variable number of actors that upload very large files to a storage server ( each actor uploads one file ). The upload operation takes about 10 minutes per file. The actor system is local / not distributed.

How can I know how many files are under upload at any given time ?

My solution right now is to have an UploadOpsActor :

case object UploadEndOp
case object UploadStartOp
case object QueryOp

object UploadOpsMonitorActor {
  def apply(): Props = Props(new UploadOpsMonitorActor())
}



class UploadOpsMonitorActor extends Actor {

  var numUploadsInProgress: Int = 0
  // number of uploads in progress , initially equal to zero

  def receive = {

    case UploadStartOp => {
      numUploadsInProgress = numUploadsInProgress + 1
    }
    case UploadEndOp => {
      numUploadsInProgress = numUploadsInProgress - 1
    }
    case QueryOp => {
      sender ! numUploadsInProgress
    }

  }

Whenever an upload worker actor starts an upload it sends a "UploadStartOp" to this UploadOpsMonitorActor and when it finishes (or fails) the upload , it sens a UploadEndOp message. The other components of the application can send a QueryOp message to get the total number of uploads in progress...

Is there a better solution that this ? The weakness of this is that messages are not guaranteed to arrive in order - theoretically an UploadEndOp message may arrive before an UploadStartOp message this may result in this UploadOpsMonitorActor returning a negative number :-(

Cheers !

Foi útil?

Solução

Per this link: http://doc.akka.io/docs/akka/2.2.3/general/message-delivery-guarantees.html

Message ordering can be guaranteed per sender-receiver pair. So no need to worry about it.

Outras dicas

Messaging between actors happen though a queue i.e. order is maintained

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top