Commit 119f5166 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

refactoring: metric vs bucket

parent 73b2ab81
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -7,28 +7,23 @@

package com.fnordmetric.enterprise

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

trait AbstractBucket {

  val key : BucketKey
  var next_flush : Long = 0

  def sample(value: Double) : Unit
  def flush() : Double

  def sample_and_flush(value: Double) = this.synchronized {
  def flush_every(interval: Long, proc: (Long, Double) => Unit) = {
    val now = FnordMetric.now

    if (next_flush == 0)
      next_flush = now

    while (next_flush <= now) {
      StorageAdapter.store(key, next_flush, flush)
      next_flush += key.flush_interval
      proc(next_flush, flush)
      next_flush += interval
    }

    sample(value)
  }

}
+4 −25
Original line number Diff line number Diff line
@@ -7,37 +7,16 @@

package com.fnordmetric.enterprise

import java.util.concurrent.ConcurrentHashMap

object BucketFactory {

  val buckets = new ConcurrentHashMap[BucketKey, AbstractBucket]()

  def find_or_create_bucket(key: BucketKey) : AbstractBucket = {
    var bucket : AbstractBucket = buckets.get(key)

    if (bucket == null) {
      buckets.synchronized {
        bucket = buckets.get(key)

        if (bucket == null) {
          bucket = create_bucket(key)
          buckets.put(key, bucket)
        }
      }
    }

    bucket
  }

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

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

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

    }

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

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

+1 −2
Original line number Diff line number Diff line
@@ -7,8 +7,7 @@

package com.fnordmetric.enterprise

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

+20 −0
Original line number Diff line number Diff line
// FnordMetric Enterprise
//   (c) 2011-2013 Paul Asmuth <paul@paulasmuth.com>
//
// Licensed under the MIT License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of
// the License at: http://opensource.org/licenses/MIT

package com.fnordmetric.enterprise

case class MetricKey(key: String, mode: String, flush_interval: Long)

class Metric {

  def sample(value: Double) = this.synchronized {
  /*flush...
    sample(value)*/
    println("........", value)
  }

}
Loading