diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-23 12:00:47 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-23 12:06:24 -0400 |
commit | 32a4f20b0b5994702f078f7d54a697e3ccd8b773 (patch) | |
tree | 01c3def9ed105505329a7e2cff92a64b5456e9d6 | |
parent | 3d321f42c19d2166204079ba7eece66b36037042 (diff) | |
download | cbt-32a4f20b0b5994702f078f7d54a697e3ccd8b773.tar.gz cbt-32a4f20b0b5994702f078f7d54a697e3ccd8b773.tar.bz2 cbt-32a4f20b0b5994702f078f7d54a697e3ccd8b773.zip |
Example for providing cbt's classloader to Akka
-rw-r--r-- | examples/akka-example/Main.scala | 27 | ||||
-rw-r--r-- | examples/akka-example/build/build.scala | 16 | ||||
-rw-r--r-- | test/test.scala | 1 |
3 files changed, 44 insertions, 0 deletions
diff --git a/examples/akka-example/Main.scala b/examples/akka-example/Main.scala new file mode 100644 index 0000000..1e746f8 --- /dev/null +++ b/examples/akka-example/Main.scala @@ -0,0 +1,27 @@ +package cbt_examples.akka_example + +import akka.http.scaladsl.server._ +import akka.http.scaladsl.model._ +import akka.http.scaladsl.server.Directives._ +import akka.http.scaladsl.settings._ + +object Service extends HttpApp with App { + override protected def route = + path("test") { + get { + complete(HttpResponse()) + } + } + + // CBT isolates it's classloaders. Even when using `direct` mode and a flatClassLoader, + // it will not use the jvm's system classloader stack for the application. + // This means if applications are hard-coded against the system classloader, + // e.g. for loading configuration files from their users or their own jars, + // they will not find them. One way around this is telling CBT to fork the process. + // (via `override def fork = true` in your build) + // This "just" works, but you'll loose all caching speedup benefits. + // Alternatively, applications like akka often allow providing a custom + // classloader instead and then benefit from CBT's classloader caching. Here is how: + val system = akka.actor.ActorSystem( "my-actor-system", classLoader = Some(this.getClass.getClassLoader) ) + startServer("localhost", 8080, ServerSettings(system), system) +} diff --git a/examples/akka-example/build/build.scala b/examples/akka-example/build/build.scala new file mode 100644 index 0000000..7fb2cd1 --- /dev/null +++ b/examples/akka-example/build/build.scala @@ -0,0 +1,16 @@ +package cbt_examples_build.akka_example + +import cbt._ +import java.net.URL + +class Build(val context: Context) extends BaseBuild { + + override def defaultScalaVersion = "2.12.1" + + override def dependencies = + super.dependencies ++ + Resolver(mavenCentral).bind( + ScalaDependency("com.typesafe.akka", "akka-http", "10.0.5") + ) + +} diff --git a/test/test.scala b/test/test.scala index 6004311..9bb3f6b 100644 --- a/test/test.scala +++ b/test/test.scala @@ -226,6 +226,7 @@ object Main{ compile("../examples/scalafmt-example") compile("../examples/scalariform-example") compile("../examples/scalatest-example") + compile("../examples/akka-example") if(slow){ compile("../examples/scalajs-react-example/js") compile("../examples/scalajs-react-example/jvm") |