Commit 3a76ce65 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

cleaning up

parent 695ebf8c
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -7,11 +7,11 @@

package com.fnordmetric.enterprise

case class BucketKey(key: String, mode: String, flush_timeout: String)
case class BucketKey(key: String, mode: String, flush_interval: Long)

trait AbstractBucket {

  val flush_timeout : Long
  val key : BucketKey
  var next_flush : Long = 0

  def sample(value: Double) : Unit
@@ -24,7 +24,9 @@ trait AbstractBucket {
      next_flush = now

    while (next_flush <= now) {
      flush; next_flush += flush_timeout
      StorageAdapter.store(key, next_flush, flush)

      next_flush += key.flush_interval
    }

    sample(value)
+3 −7
Original line number Diff line number Diff line
@@ -30,19 +30,15 @@ object BucketFactory {
    bucket
  }

  def create_bucket(key: BucketKey) : AbstractBucket = {
    val flush_timeout = java.lang.Double.parseDouble(key.flush_timeout).
      longValue * 1000

  def create_bucket(key: BucketKey) : AbstractBucket =
    key.mode match {

      case "sum" =>
        return new SumBucket(flush_timeout)
        return new SumBucket(key)

      case "mean" =>
        return new MeanBucket(flush_timeout)
        return new MeanBucket(key)

    }
  }

}
+3 −1
Original line number Diff line number Diff line
@@ -14,7 +14,9 @@ object InstructionFactory {
  def parse(str: String) : AbstractInstruction = str match {

    case X_SAMPLE(key, mode, flush_interval, value) =>
      new SampleInstruction(key, mode, flush_interval, value)
      new SampleInstruction(BucketKey(key, mode,
        java.lang.Double.parseDouble(flush_interval).longValue * 1000),
        java.lang.Double.parseDouble(value))

    case _ =>
      new ErrorInstruction("invalid command")
+2 −2
Original line number Diff line number Diff line
@@ -7,8 +7,8 @@

package com.fnordmetric.enterprise

class MeanBucket(_flush_timeout: Long) extends AbstractBucket {
  val flush_timeout = _flush_timeout
class MeanBucket(_key: BucketKey) extends AbstractBucket {
  val key = _key
  var tmp_sum : Double = 0
  var tmp_cnt : Int = 0

+2 −6
Original line number Diff line number Diff line
@@ -7,14 +7,10 @@

package com.fnordmetric.enterprise

class SampleInstruction(key: String, mode: String, flush_interval: String, value: String) extends AbstractInstruction {
class SampleInstruction(key: BucketKey, value: Double) extends AbstractInstruction {

  def execute : String = {
    val bucket = BucketFactory.find_or_create_bucket(
      BucketKey(key, mode, flush_interval))

    bucket.sample_and_flush(java.lang.Double.parseDouble(value))

    BucketFactory.find_or_create_bucket(key).sample_and_flush(value)
    "OK"
  }

Loading