Sha256: 93db75856a08b0cf3e2ff85048313671635bef2663b1b553a9e74702360dbb80

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 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")
    database(key) = value
    Future.void
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scala-bootstrapper-0.7.2 lib/template/src/main/scala/com/twitter/birdname/BirdNameServiceImpl.scala.erb