我是Finagle的初学者。
今天,我试图用finagle websocket构建一个hello世界,但我不明白为什么当我运行它时,它不会阻止收听并死亡。TestWS.scala:
package foo.bar
import com.twitter.finagle.HttpWebSocket
import com.twitter.finagle.Service
import com.twitter.finagle.websocket.WebSocket
import com.twitter.util.Future
import com.twitter.concurrent.Broker
import com.twitter.util.RandomSocket
object TestWS {
def main(args: Array[String]) {
val server = HttpWebSocket.serve(RandomSocket(), new Service[WebSocket, WebSocket] {
def apply(req: WebSocket): Future[WebSocket] = {
val outgoing = new Broker[String]
val socket = req.copy(messages = outgoing.recv)
req.messages foreach { outgoing ! _.reverse }
Future.value(socket)
}
})
}
}
死前只输出这些行:
May 19, 2014 4:00:35 PM com.twitter.finagle.Init$ apply
INFO: Finagle version 6.14.0 (rev=3c3e9b0370f67cb739feca51469dc20eb35aab67) built at 20140417-
我做错了什么?
等待服务器的惯用方法是:
val server = ...
Await.ready(server)
在建立任何连接之前,程序将退出。尝试添加
new CountDownLatch(1).await();
(或类似(HttpWebSocket.serve()
之后?