2012-01-19 14:38:44 +00:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.camel
|
|
|
|
|
|
2012-06-29 13:33:20 +02:00
|
|
|
import akka.camel.internal._
|
|
|
|
|
import akka.util.Timeout
|
2012-01-19 14:38:44 +00:00
|
|
|
import akka.actor.{ ActorSystem, Props, ActorRef }
|
|
|
|
|
import akka.pattern._
|
2012-06-29 13:33:20 +02:00
|
|
|
import scala.concurrent.util.Duration
|
2012-08-14 13:16:43 +02:00
|
|
|
import concurrent.{ ExecutionContext, Future }
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-03-01 17:32:10 +01:00
|
|
|
/**
|
|
|
|
|
* Activation trait that can be used to wait on activation or de-activation of Camel endpoints.
|
|
|
|
|
* The Camel endpoints are activated asynchronously. This trait can signal when an endpoint is activated or de-activated.
|
|
|
|
|
*/
|
2012-01-19 14:38:44 +00:00
|
|
|
trait Activation {
|
2012-05-23 15:17:49 +02:00
|
|
|
def system: ActorSystem //FIXME Why is this here, what's it needed for and who should use it?
|
2012-03-01 17:32:10 +01:00
|
|
|
|
2012-05-23 15:17:49 +02:00
|
|
|
private val activationTracker = system.actorOf(Props[ActivationTracker], "camelActivationTracker") //FIXME Why is this also top level?
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-07-25 20:11:18 +02:00
|
|
|
* Produces a Future with the specified endpoint that will be completed when the endpoint has been activated,
|
|
|
|
|
* or if it times out, which will happen after the specified Timeout.
|
|
|
|
|
*
|
2012-03-01 17:32:10 +01:00
|
|
|
* @param endpoint the endpoint to be activated
|
|
|
|
|
* @param timeout the timeout for the Future
|
2012-01-19 14:38:44 +00:00
|
|
|
*/
|
2012-08-14 13:16:43 +02:00
|
|
|
def activationFutureFor(endpoint: ActorRef)(implicit timeout: Duration, executor: ExecutionContext): Future[ActorRef] =
|
2012-07-22 21:40:09 +02:00
|
|
|
(activationTracker.ask(AwaitActivation(endpoint))(Timeout(timeout))).map[ActorRef]({
|
2012-08-14 13:16:43 +02:00
|
|
|
case EndpointActivated(`endpoint`) ⇒ endpoint
|
|
|
|
|
case EndpointFailedToActivate(`endpoint`, cause) ⇒ throw cause
|
|
|
|
|
})
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-07-25 20:11:18 +02:00
|
|
|
* Produces a Future which will be completed when the given endpoint has been deactivated or
|
|
|
|
|
* or if it times out, which will happen after the specified Timeout.
|
|
|
|
|
*
|
2012-03-01 17:32:10 +01:00
|
|
|
* @param endpoint the endpoint to be deactivated
|
|
|
|
|
* @param timeout the timeout of the Future
|
2012-01-19 14:38:44 +00:00
|
|
|
*/
|
2012-08-14 13:16:43 +02:00
|
|
|
def deactivationFutureFor(endpoint: ActorRef)(implicit timeout: Duration, executor: ExecutionContext): Future[ActorRef] =
|
|
|
|
|
(activationTracker.ask(AwaitDeActivation(endpoint))(Timeout(timeout))).map[ActorRef]({
|
|
|
|
|
case EndpointDeActivated(`endpoint`) ⇒ endpoint
|
|
|
|
|
case EndpointFailedToDeActivate(`endpoint`, cause) ⇒ throw cause
|
|
|
|
|
})
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|