From c0ae02ca07126e9a8418a84b459bbe75c9d2cf65 Mon Sep 17 00:00:00 2001 From: momania Date: Thu, 22 Jul 2010 18:20:53 +0200 Subject: [PATCH] WIP --- akka-core/src/test/scala/ScalazSpec.scala | 66 +++++++++++++++++++++++ project/build/AkkaProject.scala | 58 +++++++++++--------- 2 files changed, 100 insertions(+), 24 deletions(-) create mode 100644 akka-core/src/test/scala/ScalazSpec.scala diff --git a/akka-core/src/test/scala/ScalazSpec.scala b/akka-core/src/test/scala/ScalazSpec.scala new file mode 100644 index 0000000000..123f213f10 --- /dev/null +++ b/akka-core/src/test/scala/ScalazSpec.scala @@ -0,0 +1,66 @@ +package se.scalablesolutions.akka.actor + +import org.scalatest.junit.JUnitSuite +import org.junit.Test + +import Actor._ +import org.multiverse.api.latches.StandardLatch +import scalaz._ +import concurrent.{Strategy, Promise} +import java.lang.String +import Scalaz._ +import se.scalablesolutions.akka.config.ScalaConfig.{LifeCycle, Permanent} +import se.scalablesolutions.akka.dispatch.{Future, FutureTimeoutException} +import java.util.concurrent.{Executors, TimeUnit} + +class ScalazSpec extends JUnitSuite { + val actorRef = actorOf(new Actor { + protected def receive = { + case "one" => self.reply(1) + case "error" => TimeUnit.SECONDS.sleep(10) + } + }).start + + @Test def callActorAndGetValidation = { + + implicit val executorService = Executors.newFixedThreadPool(2) + import Strategy.Executor + + val promiseError: Promise[ValidationNEL[String, Option[Int]]] = promise(callActor("error")) + val promiseOne: Promise[ValidationNEL[String, Option[Int]]] = promise(callActor("error")) + + //[X]Promise[X] <-- Applicative / Monad + //[X]Option[X] <-- Applicative / Monad + //[X]Validation[String, X] <-- Applicative / Monad iff Semigroup[String] + //[X]Promise[Option[X]] <-- Applicative + + val pvi: Promise[ValidationNEL[String, Option[Int]]] = (promiseError |@| promiseOne) { + (v1, v2) => + (v1 |@| v2) { + (o1, o2) => + (o1 |@| o2) { _ + _} + } + } + + println(pvi.get) + + val listOptionInt: List[Option[Int]] = List.fill(5)(1.some) + // val listOptionInt = (listOptionInt.comp) map (_ * 2) + + println(listOptionInt.sequence[Option, Int]) + + } + + def callActor(msg: String): ValidationNEL[String, Option[Int]] = { + try { + val future: Future[Int] = (actorRef !!! msg) + future.await + future.exception match { + case Some((_, t)) => t.getMessage.failNel + case None => future.result.successNel + } + } catch { + case e: FutureTimeoutException => e.getMessage.failNel + } + } +} \ No newline at end of file diff --git a/project/build/AkkaProject.scala b/project/build/AkkaProject.scala index 89685dffd6..ede37d51fd 100644 --- a/project/build/AkkaProject.scala +++ b/project/build/AkkaProject.scala @@ -38,16 +38,22 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) { // ------------------------------------------------------------------------------------------------------------------- // All repositories *must* go here! See ModuleConigurations below. // ------------------------------------------------------------------------------------------------------------------- - object Repositories { - lazy val AkkaRepo = MavenRepository("Akka Repository", "http://scalablesolutions.se/akka/repository") - lazy val CodehausSnapshotRepo = MavenRepository("Codehaus Snapshots", "http://snapshots.repository.codehaus.org") +// object Repositories { +// lazy val AkkaRepo = MavenRepository("Akka Repository", "http://scalablesolutions.se/akka/repository") +// lazy val CodehausSnapshotRepo = MavenRepository("Codehaus Snapshots", "http://snapshots.repository.codehaus.org") lazy val EmbeddedRepo = MavenRepository("Embedded Repo", (info.projectPath / "embedded-repo").asURL.toString) - lazy val GuiceyFruitRepo = MavenRepository("GuiceyFruit Repo", "http://guiceyfruit.googlecode.com/svn/repo/releases/") - lazy val JBossRepo = MavenRepository("JBoss Repo", "https://repository.jboss.org/nexus/content/groups/public/") - lazy val JavaNetRepo = MavenRepository("java.net Repo", "http://download.java.net/maven/2") - lazy val SonatypeSnapshotRepo = MavenRepository("Sonatype OSS Repo", "http://oss.sonatype.org/content/repositories/releases") - lazy val SunJDMKRepo = MavenRepository("Sun JDMK Repo", "http://wp5.e-taxonomy.eu/cdmlib/mavenrepo") - } +// lazy val GuiceyFruitRepo = MavenRepository("GuiceyFruit Repo", "http://guiceyfruit.googlecode.com/svn/repo/releases/") +// lazy val JBossRepo = MavenRepository("JBoss Repo", "https://repository.jboss.org/nexus/content/groups/public/") +// lazy val JavaNetRepo = MavenRepository("java.net Repo", "http://download.java.net/maven/2") +// lazy val SonatypeSnapshotRepo = MavenRepository("Sonatype OSS Repo", "http://oss.sonatype.org/content/repositories/releases") +// lazy val SunJDMKRepo = MavenRepository("Sun JDMK Repo", "http://wp5.e-taxonomy.eu/cdmlib/mavenrepo") +// lazy val ScalazRepo = MavenRepository("Scalaz Repo", "http://scala-tools.org/repo-releases") +// } + + val mavenLocal = "Local Maven Repository" at "file:/e:/maven-repository" + + val efgfpNexusReleasesRepository = "Nexus Releases" at "http://nexus/nexus/content/groups/public" + val efgfpNexusSnaphotsRepository = "Nexus Snapshots" at "http://nexus/nexus/content/groups/public-snapshots" // ------------------------------------------------------------------------------------------------------------------- // ModuleConfigurations @@ -55,21 +61,22 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) { // must be resolved from a ModuleConfiguration. This will result in a significant acceleration of the update action. // Therefore, if repositories are defined, this must happen as def, not as val. // ------------------------------------------------------------------------------------------------------------------- - import Repositories._ - lazy val atmosphereModuleConfig = ModuleConfiguration("org.atmosphere", SonatypeSnapshotRepo) - lazy val grizzlyModuleConfig = ModuleConfiguration("com.sun.grizzly", JavaNetRepo) - lazy val guiceyFruitModuleConfig = ModuleConfiguration("org.guiceyfruit", GuiceyFruitRepo) - lazy val jbossModuleConfig = ModuleConfiguration("org.jboss", JBossRepo) - lazy val jdmkModuleConfig = ModuleConfiguration("com.sun.jdmk", SunJDMKRepo) - lazy val jerseyContrModuleConfig = ModuleConfiguration("com.sun.jersey.contribs", JavaNetRepo) - lazy val jerseyModuleConfig = ModuleConfiguration("com.sun.jersey", JavaNetRepo) - lazy val jgroupsModuleConfig = ModuleConfiguration("jgroups", JBossRepo) - lazy val jmsModuleConfig = ModuleConfiguration("javax.jms", SunJDMKRepo) - lazy val jmxModuleConfig = ModuleConfiguration("com.sun.jmx", SunJDMKRepo) - lazy val liftModuleConfig = ModuleConfiguration("net.liftweb", ScalaToolsSnapshots) - lazy val multiverseModuleConfig = ModuleConfiguration("org.multiverse", CodehausSnapshotRepo) - lazy val nettyModuleConfig = ModuleConfiguration("org.jboss.netty", JBossRepo) - lazy val scalaTestModuleConfig = ModuleConfiguration("org.scalatest", ScalaToolsSnapshots) +// import Repositories._ +// lazy val atmosphereModuleConfig = ModuleConfiguration("org.atmosphere", SonatypeSnapshotRepo) +// lazy val grizzlyModuleConfig = ModuleConfiguration("com.sun.grizzly", JavaNetRepo) +// lazy val guiceyFruitModuleConfig = ModuleConfiguration("org.guiceyfruit", GuiceyFruitRepo) +// lazy val jbossModuleConfig = ModuleConfiguration("org.jboss", JBossRepo) +// lazy val jdmkModuleConfig = ModuleConfiguration("com.sun.jdmk", SunJDMKRepo) +// lazy val jerseyContrModuleConfig = ModuleConfiguration("com.sun.jersey.contribs", JavaNetRepo) +// lazy val jerseyModuleConfig = ModuleConfiguration("com.sun.jersey", JavaNetRepo) +// lazy val jgroupsModuleConfig = ModuleConfiguration("jgroups", JBossRepo) +// lazy val jmsModuleConfig = ModuleConfiguration("javax.jms", SunJDMKRepo) +// lazy val jmxModuleConfig = ModuleConfiguration("com.sun.jmx", SunJDMKRepo) +// lazy val liftModuleConfig = ModuleConfiguration("net.liftweb", ScalaToolsSnapshots) +// lazy val multiverseModuleConfig = ModuleConfiguration("org.multiverse", CodehausSnapshotRepo) +// lazy val nettyModuleConfig = ModuleConfiguration("org.jboss.netty", JBossRepo) +// lazy val scalazModuleConfig = ModuleConfiguration("scalaz", ScalazRepo) +// lazy val scalaTestModuleConfig = ModuleConfiguration("org.scalatest", ScalaToolsSnapshots) lazy val embeddedRepo = EmbeddedRepo // This is the only exception, because the embedded repo is fast! // ------------------------------------------------------------------------------------------------------------------- @@ -171,6 +178,8 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) { lazy val sbinary = "sbinary" % "sbinary" % "2.8.0-0.3.1" % "compile" + lazy val scalaz = "com.googlecode.scalaz" % "scalaz-core_2.8.0" % "5.0" % "compile" + lazy val servlet = "javax.servlet" % "servlet-api" % "2.5" % "compile" lazy val sjson = "sjson.json" % "sjson" % "0.7-SNAPSHOT-2.8.0" % "compile" @@ -321,6 +330,7 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) { val multiverse = Dependencies.multiverse val netty = Dependencies.netty val protobuf = Dependencies.protobuf + val scalaz = Dependencies.scalaz val sbinary = Dependencies.sbinary val sjson = Dependencies.sjson val werkz = Dependencies.werkz