Wow, this is a really impressive body of work, arguably the most complete Scala framework outside of Lift (but much easier to use). Xitrum is truly a full stack web framework, all the bases are covered, including wtf-am-I-on-the-moon extras like ETags, static file cache identifiers & auto-gzip compression. Tack on built-in JSON converter, before/around/after interceptors, request/session/cookie/flash scopes, integrated validation (server & client-side, nice), built-in cache layer (Hazelcast), i18n a la GNU gettext, Netty (with Nginx, hello blazing fast), etc. and you have, wow.
詳細な使用ガイドがあります。
Xitrumは Scalatra よりパワフルに、 Lift より簡単であることで両者のスペクトルを満たすことを目的としています。 Xitrum はScalatraのようにcontroller-firstであり、Liftのような view-first ではありません。 多くの開発者にとって馴染み部会controller-firstスタイルです。
スケーラビリティが簡単!ノードをクラスタへ追加するだけでいいです。
import xitrum.Action
import xitrum.annotation.GET
@GET("url/to/HelloAction")
class HelloAction extends Action {
def execute() {
val urlToHelloActor = url[HelloActor]
respondHtml(
<xml:group>
<p>Hello {remoteIp}!</p>
<a href={urlToHelloActor}>Actor example</a>
</xml:group>
)
}
}
The above action runs directly on Netty's IO thread pool.
It's very fast if your action is simple.
If it's more complex, avoid blocking
request receiving and response responding,
by running it on another thread pool,
by extending xitrum.FutureAction
.
import scala.concurrent.duration._
import akka.actor.ReceiveTimeout
import xitrum.ActorAction
import xitrum.annotation.GET
@GET("url/to/HelloActor")
class HelloActor extends ActorAction {
def execute() {
log.info("Request received: " + request)
// Communicate with another actor
anotherActorRef ! "aMsg"
// Wait for the above actor to reply within 5s
context.setReceiveTimeout(5.seconds)
context.become {
case aReply =>
respondText(aReply)
case ReceiveTimeout =>
respondText("Timeout")
}
}
override def postStop() {
log.info("Connection closed or response sent")
super.postStop()
}
}
Actorを簡単にアノテーションを付けることで、そとのウェッブからアクセスできます!
import xitrum.{
WebSocketAction,
WebSocketText, WebSocketBinary,
WebSocketPing, WebSocketPong
}
import xitrum.annotation.WEBSOCKET
@WEBSOCKET("url/to/EchoWebSocketActor")
class EchoWebSocketActor extends WebSocketAction {
def execute() {
log.info("WebSocket onopen")
context.become {
case WebSocketText(text) =>
respondWebSocketText(text)
case WebSocketBinary(bytes) =>
respondWebSocketBinary(bytes)
case WebSocketPing =>
// Xitrum automatically sends pong for you,
// you don't have to send pong yourself
case WebSocketPong =>
// Client has received your ping
}
}
override def postStop() {
log.info("WebSocket onclose")
super.postStop()
}
}
import xitrum.{SockJsAction, SockJsText}
import xitrum.annotation.SOCKJS
@SOCKJS("url/to/EchoSockJsActor")
class EchoSockJsActor extends SockJsAction {
def execute() {
log.info("SockJS onopen")
context.become {
case SockJsText(text) =>
respondSockJsText(text)
}
}
override def postStop() {
log.info("SockJS onclose")
super.postStop()
}
}
xitrum-new プロジェクトを参照してください。
xitrum-new.zip をダウンロード、解凍し、次のコマンドを実行:
sbt/sbt run
空のプロジェクトが http://localhost:8000/ と https://localhost:4430/ で動くことを確認できます。
Eclipse プロジェクト生成:
sbt/sbt eclipse