Created
June 23, 2012 21:44
-
-
Save jwaldrop/2980145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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