Created
January 23, 2012 06:18
-
-
Save corruptmemory/1661131 to your computer and use it in GitHub Desktop.
blueeyes PONG
This file contains hidden or 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.corruptmemory.blueeyes_pong | |
import akka.dispatch.{Future,Promise} | |
import akka.util.Timeout | |
import blueeyes.{BlueEyesServer,BlueEyesServiceBuilder} | |
import blueeyes.core.data.FileSource._ | |
import blueeyes.core.data.{FileSource, ByteChunk, BijectionsChunkJson, BijectionsChunkString, BijectionsChunkFutureJson} | |
import blueeyes.core.http.HttpStatusCodes._ | |
import blueeyes.core.http.MimeTypes._ | |
import blueeyes.core.http.combinators.HttpRequestCombinators | |
import blueeyes.core.http.{HttpHeaders, HttpStatusCodes, HttpStatus, HttpRequest, HttpResponse} | |
import blueeyes.core.service.ServerHealthMonitorService | |
import blueeyes.core.service.engines.HttpClientXLightWeb | |
import blueeyes.health.metrics._ | |
import com.weiglewilczek.slf4s.Logging | |
import java.io.File | |
import java.util.concurrent.CountDownLatch | |
import net.lag.configgy.{Configgy, ConfigMap} | |
object Pong extends PongStart { | |
def main(args: Array[String]) { | |
startServer() | |
} | |
} | |
object PongServer extends BlueEyesServer with PongService | |
trait PongStart extends Logging { self => | |
private var server: Option[BlueEyesServer] = _ | |
var port = 8084 | |
private val configPattern = """server{ | |
port = %d | |
sslPort = %d | |
sslEnable = false | |
}""" | |
def startServer() { | |
def start(port: Int) { | |
Configgy.configureFromString(configPattern.format(port, port + 1)) | |
server = Some(PongServer) | |
server.get.start onFailure { | |
case v => | |
logger.error("Server failed to start, trying port " + (port + 2)) | |
start(port + 2) | |
} | |
} | |
start(port) | |
} | |
def stopServer = server.foreach(_.stop) | |
} | |
trait PongService extends BlueEyesServiceBuilder with HttpRequestCombinators { | |
implicit def queryTimeout = Timeout(30000) | |
import BijectionsChunkJson._ | |
import BijectionsChunkString._ | |
import BijectionsChunkFutureJson._ | |
val pongService = service("pong", "1.0.0") { context => | |
startup { Promise.successful(()) }-> | |
request { (_:Unit) => | |
describe("Returns PONG"){ | |
path("/ping") { | |
produce(text/plain) { | |
get { request: HttpRequest[ByteChunk] => Future(HttpResponse(content = Some("PONG"))) } | |
} | |
} | |
} | |
}-> shutdown { _ => Future(()) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment