Sha256: 8853893a0ae70e853903a57108572b67ad177713b2c4b160c97639d74be8aaa6

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

package com.twitter.birdname

import java.util.concurrent.Executors
import scala.collection.mutable
import com.twitter.util._
import config._

class BirdNameServiceImpl(config: BirdNameServiceConfig) extends BirdNameServiceServer {
  val serverName = "BirdName"
  val thriftPort = config.thriftPort
  
  /**
   * These services are based on finagle, which implements a nonblocking server.  If you 
   * are making blocking rpc calls, it's really important that you run these actions in
   * a thread pool, so that you don't block the main event loop.  This thread pool is only
   * needed for these blocking actions.  The code looks like:
   *
   *     // Depends on com.twitter.util >= 1.6.10
   *     val futurePool = new FuturePool(Executors.newFixedThreadPool(config.threadPoolSize))
   * 
   *     def hello() = futurePool {
   *       someService.blockingRpcCall
   *     }
   * 
   */   

  val database = new mutable.HashMap[String, String]()  

  def get(key: String) = {
    database.get(key) match {
      case None =>
        log.debug("get %s: miss", key)
        Future.exception(new BirdNameException("No such key"))
      case Some(value) =>
        log.debug("get %s: hit", key)
        Future(value)
    }
  }

  def put(key: String, value: String) = {
    log.debug("put %s", key)
    database(key) = value
    Future.void
  }
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
scala-bootstrapper-0.9.1 lib/template/src/main/scala/com/twitter/birdname/BirdNameServiceImpl.scala.erb
scala-bootstrapper-0.9.0 lib/template/src/main/scala/com/twitter/birdname/BirdNameServiceImpl.scala.erb
scala-bootstrapper-0.8.1 lib/template/src/main/scala/com/twitter/birdname/BirdNameServiceImpl.scala.erb
scala-bootstrapper-0.8.0 lib/template/src/main/scala/com/twitter/birdname/BirdNameServiceImpl.scala.erb