aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-23 12:00:47 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-23 12:06:24 -0400
commit32a4f20b0b5994702f078f7d54a697e3ccd8b773 (patch)
tree01c3def9ed105505329a7e2cff92a64b5456e9d6 /examples
parent3d321f42c19d2166204079ba7eece66b36037042 (diff)
downloadcbt-32a4f20b0b5994702f078f7d54a697e3ccd8b773.tar.gz
cbt-32a4f20b0b5994702f078f7d54a697e3ccd8b773.tar.bz2
cbt-32a4f20b0b5994702f078f7d54a697e3ccd8b773.zip
Example for providing cbt's classloader to Akka
Diffstat (limited to 'examples')
-rw-r--r--examples/akka-example/Main.scala27
-rw-r--r--examples/akka-example/build/build.scala16
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")
+ )
+
+}