PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/musicscan/src/main/scala/local/choonweb/musicscan/MongoUnchangedFilter.scala

http://github.com/etaoins/choonweb
Scala | 36 lines | 26 code | 7 blank | 3 comment | 1 complexity | bf90d07f6875d4eb709bf3ea7a9c612e MD5 | raw file
  1. package local.choonweb.musicscan
  2. import scala.actors._
  3. import com.mongodb.casbah.Imports._
  4. import java.util.Date
  5. class MongoUnchangedFilter(trackColl : MongoCollection, downstream : Actor) extends Actor {
  6. def act() {
  7. loop {
  8. react {
  9. case FileFound(relativePath, file) =>
  10. // Is there a file with the same path, size and last modified?
  11. val queryBulder = MongoDBObject.newBuilder
  12. queryBulder += "path" -> relativePath
  13. queryBulder += "file.lastModified" -> new Date(file.lastModified)
  14. queryBulder += "file.size" -> file.length
  15. // We don't actually want any fields but we get _id anyway
  16. val existingTrack = trackColl.findOne(queryBulder.result, MongoDBObject("_id" -> 1))
  17. if (existingTrack.isEmpty) {
  18. downstream ! FileFound(relativePath, file)
  19. }
  20. case ScanDone() =>
  21. downstream ! ScanDone()
  22. exit()
  23. case other : AnyRef =>
  24. downstream ! other
  25. }
  26. }
  27. }
  28. }
  29. // vim: set ts=4 sw=4 et: