pekko/akka-docs/rst/java/code/docs/camel/ActivationTestBase.java

50 lines
1.6 KiB
Java
Raw Normal View History

2012-07-15 14:12:03 +02:00
package docs.camel;
2012-07-23 01:36:12 +02:00
//#CamelActivation
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.camel.Camel;
import akka.camel.CamelExtension;
import akka.camel.javaapi.UntypedConsumerActor;
2012-07-23 15:49:19 +02:00
import scala.concurrent.Future;
import scala.concurrent.util.Duration;
import scala.concurrent.util.FiniteDuration;
2012-07-23 01:36:12 +02:00
import static java.util.concurrent.TimeUnit.SECONDS;
//#CamelActivation
2012-07-15 14:12:03 +02:00
import org.junit.Test;
public class ActivationTestBase {
@Test
public void testActivation() {
//#CamelActivation
2012-07-23 01:36:12 +02:00
// ..
2012-07-15 14:12:03 +02:00
ActorSystem system = ActorSystem.create("some-system");
Props props = new Props(MyConsumer.class);
ActorRef producer = system.actorOf(props,"myproducer");
Camel camel = CamelExtension.get(system);
// get a future reference to the activation of the endpoint of the Consumer Actor
2012-07-23 01:36:12 +02:00
FiniteDuration duration = Duration.create(10, SECONDS);
Future<ActorRef> activationFuture = camel.activationFutureFor(producer, duration, system.dispatcher());
2012-07-15 14:12:03 +02:00
//#CamelActivation
//#CamelDeactivation
2012-07-23 01:36:12 +02:00
// ..
2012-07-15 14:12:03 +02:00
system.stop(producer);
// get a future reference to the deactivation of the endpoint of the Consumer Actor
Future<ActorRef> deactivationFuture = camel.deactivationFutureFor(producer, duration, system.dispatcher());
2012-07-15 14:12:03 +02:00
//#CamelDeactivation
system.shutdown();
}
public static class MyConsumer extends UntypedConsumerActor {
public String getEndpointUri() {
return "direct:test";
}
public void onReceive(Object message) {
}
}
}