Commit a45ac8a4 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

simple protocol parsing with regex

parent 263901a0
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -7,8 +7,8 @@

package com.fnordmetric.enterprise

class AbstractInstruction {
trait AbstractInstruction {

  def execute : String = "OK"
  def execute : String

}
+14 −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

class ErrorInstruction(err: String) extends AbstractInstruction {

  def execute : String = "ERROR " + err

}
+11 −2
Original line number Diff line number Diff line
@@ -9,7 +9,16 @@ package com.fnordmetric.enterprise

object InstructionFactory {

  def parse(str: String) : AbstractInstruction =
    new AbstractInstruction
  val X_SAMPLE = """^SAMPLE (.*)(delta|mean|sum)-([0-9]+) ([0-9]+\.?[0-9]+)$""".r

  def parse(str: String) : AbstractInstruction = str match {

    case X_SAMPLE(key, mode, flush_interval, value) =>
      new SampleInstruction(key, mode, flush_interval, value)

    case _ =>
      new ErrorInstruction("invalid command")

  }

}
+15 −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

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

  def execute : String = "OK"

}