The reason is we have our own Dispatcher which extends akka.dispatch.Dispatcher, the reflection call 'getDeclaredField' threw the error, because it could not get the inherited class fields.
So we could not upgrade, any possible fixes?
Thanks
--
You received this message because you are subscribed to the Google Groups "kamon-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kamon-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
1) Create a custom dispatcher(just copy the code)
-----------
package my.custom.actor.system
import java.util.concurrent.TimeUnit
import akka.dispatch._
import com.typesafe.config.Config
import play.api.Logger
import scala.concurrent.ExecutionContext
import scala.concurrent.duration.{Duration, FiniteDuration}
/**
* Configurator for a context propagating dispatcher.
*/
class ContextPropagatingDispatcherConfigurator(config: Config, prerequisites: DispatcherPrerequisites)
extends MessageDispatcherConfigurator(config, prerequisites) {
private val instance = new ContextPropagatingDisptacher(
this,
config.getString("id"),
config.getInt("throughput"),
FiniteDuration(config.getDuration("throughput-deadline-time", TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS),
configureExecutor(),
FiniteDuration(config.getDuration("shutdown-timeout", TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS))
override def dispatcher(): MessageDispatcher = instance
}
/**
* A context propagating dispatcher.
*
* This dispatcher propagates the current request context if it's set when it's executed.
*/
class ContextPropagatingDisptacher(_configurator: MessageDispatcherConfigurator,
id: String,
throughput: Int,
throughputDeadlineTime: Duration,
executorServiceFactoryProvider: ExecutorServiceFactoryProvider,
shutdownTimeout: FiniteDuration)
extends Dispatcher(_configurator, id, throughput, throughputDeadlineTime, executorServiceFactoryProvider, shutdownTimeout) {
self =>
override def prepare(): ExecutionContext = new ExecutionContext {
// capture the context
val context = RequestContext.capture()
def execute(r: Runnable) = self.execute(new Runnable {
// Run the runnable with the captured context
def run() = context.withContext(r.run())
})
def reportFailure(t: Throwable) = self.reportFailure(t)
}
}
/**
* The current request context.
*/
object RequestContext {
/**
* Capture the current request context.
*/
def capture(): CapturedRequestContext = new CapturedRequestContext {
val requestInfoOpt: Option[RequestInfo] = Some(RequestInfo(
Some("Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2224.3 Safari/537.36"),
None,
Some("127.0.0.1"),
Some("http://localhost/test")
))
def withContext[T](block: => T) = {
requestInfoOpt map { requestInfo =>
try {
block
} catch {
case e: Throwable =>
Logger.error("Uncaught exception | " + requestInfoOpt, e)
throw e
}
}
}
}
}
/**
* A captured request context
*/
trait CapturedRequestContext {
/**
* Execute the given block with the captured request context.
*/
def withContext[T](block: => T)
}
case class RequestInfo(
userAgentHeaderOpt: Option[String],
forwardedForHeaderOpt: Option[String],
clientIpOpt: Option[String],
requestUriOpt: Option[String]) {
val uuid = new com.eaio.uuid.UUID().toString
}
-----------
2) Add the following to the config file(application.conf)
----------
akka {
actor {
default-dispatcher = {
type = "my.custom.actor.system.ContextPropagatingDispatcherConfigurator"
}
}
}
---------------
3) I copied the your code and put it in the play application controller, it throws the error:
-----------
object Application extends Controller {
def index = Action { request =>
implicit lazy val system = ActorSystem("test-custom-dispatcher")
val defaultDispatcher = system.dispatcher
val executorServiceDelegateField = defaultDispatcher.getClass.getDeclaredField("executorServiceDelegate")
executorServiceDelegateField.setAccessible(true)
Ok("it does work")
}
}
----------
Thanks
Hui