Permalink
Browse files

com.twitter.admin.Service <= ServerBuilder

  • Loading branch information...
1 parent 8b2a3c9 commit 89ac034d934f6d492771b564b8869768c08586cd @mariusae mariusae committed Feb 18, 2011
@@ -0,0 +1,29 @@
+package com.twitter.finagle.builder
+
+/**
+ * Make a com.twitter.admin.Service from a finagle ServerBuilder.
+ */
+
+import com.twitter.admin
+import com.twitter.util.Duration
+import com.twitter.conversions.time._
+
+import com.twitter.finagle.Service
+
+class ServerBuildertoTwitterService[Req, Rep](
+ builder: ServerBuilder[Req, Rep],
+ service: Service[Req, Rep],
+ gracePeriod: Duration = 10.seconds)
+ extends admin.Service
+{
+ private[this] var server: Option[Server] = None
+
+ def start() {
+ if (!server.isDefined)
+ server = Some(builder.build(service))
+ }
+
+ def shutdown() {
+ server foreach { _.close(gracePeriod) }
+ }
+}

0 comments on commit 89ac034

Please sign in to comment.