diff options
author | Jakob Odersky <jakob@driver.xyz> | 2018-09-12 17:30:33 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-10-09 16:19:39 -0700 |
commit | eb6f97b4cac548999cbf192ee83d9ba9a253b7c8 (patch) | |
tree | 6d75a23efc841a6f51e780913387000206d1fe94 /src/main/scala/xyz/driver/core/database/MdcAsyncExecutor.scala | |
parent | 4d1197099ce4e721c18bf4cacbb2e1980e4210b5 (diff) | |
download | driver-core-eb6f97b4cac548999cbf192ee83d9ba9a253b7c8.tar.gz driver-core-eb6f97b4cac548999cbf192ee83d9ba9a253b7c8.tar.bz2 driver-core-eb6f97b4cac548999cbf192ee83d9ba9a253b7c8.zip |
Move database-related functionality to separate project
This committ includes a breaking change. The database-specific utility
"Converters" trait threw an exception "DatabaseException" defined in
the rest package, thus breaking the dependency graph. The solution was
to move the DatabaseException class from rest to database and not
inherit ServiceExceptio any more.
Unfortunately, the rest classes also require the database exception in
propagating errors so this funtionality has been removed. The
rationale is:
1. Database exceptions are rare and result in 500 errors anyway
making the status code opaque to what actual error caused it.
2. In core 2.0, an improved tracing framework will make diagnosing
and following database errors easier, thereby attenuating the need
to forward details on service exceptions in responses.
Diffstat (limited to 'src/main/scala/xyz/driver/core/database/MdcAsyncExecutor.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/database/MdcAsyncExecutor.scala | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/src/main/scala/xyz/driver/core/database/MdcAsyncExecutor.scala b/src/main/scala/xyz/driver/core/database/MdcAsyncExecutor.scala deleted file mode 100644 index 5939efb..0000000 --- a/src/main/scala/xyz/driver/core/database/MdcAsyncExecutor.scala +++ /dev/null @@ -1,53 +0,0 @@ -/** Code ported from "de.geekonaut" %% "slickmdc" % "1.0.0" - * License: @see https://github.com/AVGP/slickmdc/blob/master/LICENSE - * Blog post: @see http://50linesofco.de/post/2016-07-01-slick-and-slf4j-mdc-logging-in-scala.html - */ -package xyz.driver.core -package database - -import java.util.concurrent._ -import java.util.concurrent.atomic.AtomicInteger - -import scala.concurrent._ -import com.typesafe.scalalogging.StrictLogging -import slick.util.AsyncExecutor - -import logging.MdcExecutionContext - -/** Taken from the original Slick AsyncExecutor and simplified - * @see https://github.com/slick/slick/blob/3.1/slick/src/main/scala/slick/util/AsyncExecutor.scala - */ -object MdcAsyncExecutor extends StrictLogging { - - /** Create an AsyncExecutor with a fixed-size thread pool. - * - * @param name The name for the thread pool. - * @param numThreads The number of threads in the pool. - */ - def apply(name: String, numThreads: Int): AsyncExecutor = { - new AsyncExecutor { - val tf = new DaemonThreadFactory(name + "-") - - lazy val executionContext = { - new MdcExecutionContext(ExecutionContext.fromExecutor(Executors.newFixedThreadPool(numThreads, tf))) - } - - def close(): Unit = {} - } - } - - def default(name: String = "AsyncExecutor.default"): AsyncExecutor = apply(name, 20) - - private class DaemonThreadFactory(namePrefix: String) extends ThreadFactory { - private[this] val group = - Option(System.getSecurityManager).fold(Thread.currentThread.getThreadGroup)(_.getThreadGroup) - private[this] val threadNumber = new AtomicInteger(1) - - def newThread(r: Runnable): Thread = { - val t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement, 0) - if (!t.isDaemon) t.setDaemon(true) - if (t.getPriority != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY) - t - } - } -} |