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

stub tcp server implementation

parent c1aeab03
Loading
Loading
Loading
Loading
+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 AbstractInstruction {

  def execute : String = "OK"

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

object InstructionFactory {

  def parse(str: String) : AbstractInstruction =
    new AbstractInstruction

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

import java.net.InetSocketAddress
import org.jboss.netty.buffer.ChannelBuffer
import org.jboss.netty.buffer.ChannelBuffers
import org.jboss.netty.channel._

class TCPHandler extends SimpleChannelUpstreamHandler {

  override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) {
    val ins = InstructionFactory.parse(e.getMessage.toString)
    e.getChannel.write(ins.execute + "\n")
  }

  override def exceptionCaught(ctx: ChannelHandlerContext, e: ExceptionEvent) {
    FnordMetric.error("[TCP] Exception: " + e.getCause, false)
    e.getChannel.close()
  }

}
+3 −1
Original line number Diff line number Diff line
package com.fnordmetric.enterprise
// FnordMetric Enterprise
//   (c) 2011-2013 Paul Asmuth <paul@paulasmuth.com>
//
@@ -6,6 +5,8 @@ package com.fnordmetric.enterprise
// 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

import java.net.InetSocketAddress
import java.util.concurrent._
import org.jboss.netty.bootstrap.ServerBootstrap
@@ -38,6 +39,7 @@ class TCPServer(port: Int, threads: Int) {

      pipeline.addLast("decoder", new StringDecoder)
      pipeline.addLast("eccoder", new StringEncoder)
      pipeline.addLast("handler", new TCPHandler)

      pipeline
    }