Skip to content
laforge49 edited this page Sep 14, 2011 · 6 revisions

RandomIO is a service for accessing a disk file. It uses two properties:

  • dbPathname - Provides the pathname of the file. (Required)
  • dbAccessMode - Specifies how the file is to be opened. (Defaults to "rw".)

The RandomIO service supports two types of messages:

case class ReadBytes(offset: Long, length: Int)
case class WriteBytes(offset: Long, bytes: Array[Byte])

RandomIO opens/closes its file when the actor it is aggregated with is opened/closed.

We will start by looking at a driver actor to exercise RandomIO.

case class DoIt()

class Driver extends Actor {
  bind(classOf[DoIt], doIt)

  def doIt(msg: AnyRef, rf: Any => Unit) {
    systemServices(WriteBytes(0, new Array[Byte](5000))) {
      rsp1 => {
        systemServices(ReadBytes(0, 5000)) {
          rsp2 => {
            rf(rsp2)
          }
        }
      }
    }
  }
}

RandomIOTest

tutorial

Clone this wiki locally