PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/scala/org/log4jfugue/MongoDataGetter.scala

http://github.com/btarbox/Log4ScalaFugue
Scala | 44 lines | 20 code | 2 blank | 22 comment | 3 complexity | 462405094a9c49a793a32dff0f7e4ba2 MD5 | raw file
  1. package org.log4jfugue
  2. /*
  3. * Log4JFugue - Application Sonification
  4. * Copyright (C) 2011-2012 Brian Tarbox
  5. *
  6. * http://www.log4jfugue.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. import com.mongodb.casbah.Imports._
  24. import org.scala_tools.subcut.inject.BindingModule
  25. class MongoDataGetter() (override implicit val bindingModule: BindingModule) extends FileDataGetter {
  26. lazy val timeColumn = injectOptional[String]('timeColumn).getOrElse("time")
  27. lazy val msgColumn = injectOptional[String]('msgColumn).getOrElse("msg")
  28. lazy val databaseName = injectOptional[String]('databaseName).getOrElse("logs")
  29. lazy val collectionName = injectOptional[String]('collectionName).getOrElse("thisLog")
  30. lazy val conn = MongoConnection() (databaseName)(collectionName)
  31. override def run() {
  32. try {
  33. for { x <- conn.find().sort(MongoDBObject("timeColumn" -> "1")); thisTime = x.get(timeColumn); if(thisTime != null)} {
  34. val line = x.get(timeColumn).toString
  35. messageProcessor ! x.get(msgColumn)
  36. delayProcessing(line)
  37. }
  38. }finally {
  39. //conn.underlying.close()
  40. }
  41. }
  42. }