diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-23 14:23:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-23 14:23:38 -0400 |
commit | 376abfa34a53b1bb0ffd546650429fff52ba90a0 (patch) | |
tree | 01c3def9ed105505329a7e2cff92a64b5456e9d6 /examples | |
parent | 3d321f42c19d2166204079ba7eece66b36037042 (diff) | |
parent | 32a4f20b0b5994702f078f7d54a697e3ccd8b773 (diff) | |
download | cbt-376abfa34a53b1bb0ffd546650429fff52ba90a0.tar.gz cbt-376abfa34a53b1bb0ffd546650429fff52ba90a0.tar.bz2 cbt-376abfa34a53b1bb0ffd546650429fff52ba90a0.zip |
Merge pull request #455 from cvogt/akka-example
Example for providing cbt's classloader to Akka
Diffstat (limited to 'examples')
-rw-r--r-- | examples/akka-example/Main.scala | 27 | ||||
-rw-r--r-- | examples/akka-example/build/build.scala | 16 |
2 files changed, 43 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") + ) + +} |