Skip to content

Commit

Permalink
learn spray
Browse files Browse the repository at this point in the history
  • Loading branch information
itang committed Nov 30, 2012
1 parent 8f5d034 commit a3fc93c
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
10 changes: 10 additions & 0 deletions learn/spray/learn_spray/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
target/
/.lib/

*~
/.ensime

/.cache
/.classpath
/.project
/.settings/
1 change: 1 addition & 0 deletions learn/spray/learn_spray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# spray
37 changes: 37 additions & 0 deletions learn/spray/learn_spray/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* basic project info */
name := "test"

organization := "test"

version := "0.1"

description := "test"

startYear := Some(2012)

/* scala versions and options */
scalaVersion := "2.10.0-RC3"

// crossScalaVersions := Seq("2.9.1")

offline := false

scalacOptions ++= Seq("-deprecation", "-unchecked")

// scalacOptions ++= Seq("-Ydependent-method-types") // if using shapeless

javacOptions ++= Seq("-Xlint:unchecked", "-Xlint:deprecation")

mainClass in (Compile, run) := Some("test.Main")

/* dependencies */
libraryDependencies ++= Seq (
"io.spray" % "spray-io" % "1.1-M5",
"io.spray" % "spray-caching" % "1.1-M5",
"com.typesafe.akka" % "akka-actor_2.10.0-RC3" % "2.1.0-RC3"
)

resolvers ++= Seq(
"spray repo" at "http://repo.spray.io"
)

1 change: 1 addition & 0 deletions learn/spray/learn_spray/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.12.1
19 changes: 19 additions & 0 deletions learn/spray/learn_spray/project/build.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sbt._
import Keys._

object build extends Build {

val gcsettings = Defaults.defaultSettings

val gc = TaskKey[Unit]("gc", "runs garbage collector")
val gcTask = gc := {
println("requesting garbage collection")
System gc()
}

lazy val project = Project (
"project",
file("."),
settings = gcsettings ++ Seq(gcTask)
)
}
5 changes: 5 additions & 0 deletions learn/spray/learn_spray/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.4")

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")

addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.0")
29 changes: 29 additions & 0 deletions learn/spray/learn_spray/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package test

import java.util.concurrent.TimeUnit._

import scala.concurrent.Future
import scala.concurrent.duration.{ Duration }
import akka.actor.ActorSystem
import spray.caching.{ LruCache, Cache }
import spray.util._

object Main extends App {
implicit val system = ActorSystem()

def expensiveOp(): Double = {
Thread.sleep(500)
new util.Random().nextDouble()
}

val cache: Cache[Double] = LruCache()

def cachedOp[T](key: T): Future[Double] = cache(key) {
expensiveOp()
}

println(cachedOp("foo").await)
println(cachedOp("bar").await(Duration(100, MILLISECONDS)))

system.shutdown()
}

0 comments on commit a3fc93c

Please sign in to comment.