Skip to content

Instantly share code, notes, and snippets.

@jwaldrop
Created June 23, 2012 21:44
Show Gist options
  • Save jwaldrop/2980145 to your computer and use it in GitHub Desktop.
Save jwaldrop/2980145 to your computer and use it in GitHub Desktop.
package com.twitter.sample
import com.twitter.conversions.time._
import com.twitter.finagle.builder.{ServerBuilder, Server}
import com.twitter.finagle.thrift.ThriftServerFramedCodec
import com.twitter.sample.thrift._
import com.twitter.util.Future
import java.net.InetSocketAddress
import org.apache.thrift.protocol.TBinaryProtocol
object SampleMain {
def main(args: Array[String]) {
val server = new EchoServer()
server.start(8080)
server.shutdown()
}
}
class EchoServer extends EchoService.ServiceIface {
var server: Server = null
var service: EchoService.Service = null
def start(port: Int) {
try {
service = new EchoService.Service(this, new TBinaryProtocol.Factory())
server = ServerBuilder()
.bindTo(new InetSocketAddress(port))
.codec(ThriftServerFramedCodec())
.name("finagle thrift server")
.build(service)
} catch {
case e: Exception =>
e.printStackTrace()
}
}
def shutdown() {
if (service != null) {
println("1")
service.release()
}
if (server != null) {
println("2")
server.close(1.second)
}
println("3")
}
def echo(message: String): Future[String] = {
Future.value(message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment