alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Akka/Scala example source code file (ActivationTestBase.java)

This example Akka source code file (ActivationTestBase.java) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Akka and Scala source code examples by using tags.

All credit for the original source code belongs to akka.io; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Akka tags/keywords

activationtestbase, actorref, actorsystem, future, myconsumer, props, seconds, string, suppresswarnings, test, untypedconsumeractor

The ActivationTestBase.java Akka example source code

package docs.camel;
//#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;
    import akka.testkit.JavaTestKit;
    import akka.testkit.TestKit;
    import akka.util.Timeout;
    import scala.concurrent.Future;
    import scala.concurrent.duration.Duration;
    import static java.util.concurrent.TimeUnit.SECONDS;
//#CamelActivation

import org.junit.Test;

public class ActivationTestBase {

  @SuppressWarnings("unused")
  @Test
  public void testActivation() {
    //#CamelActivation

    // ..
    ActorSystem system = ActorSystem.create("some-system");
    Props props = Props.create(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
    Timeout timeout = new Timeout(Duration.create(10, SECONDS));
    Future<ActorRef> activationFuture = camel.activationFutureFor(producer,
      timeout, system.dispatcher());
    //#CamelActivation
    //#CamelDeactivation
    // ..
    system.stop(producer);
    // get a future reference to the deactivation of the endpoint of the Consumer Actor
    Future<ActorRef> deactivationFuture = camel.deactivationFutureFor(producer,
      timeout, system.dispatcher());
    //#CamelDeactivation
    JavaTestKit.shutdownActorSystem(system);
  }

  public static class MyConsumer extends UntypedConsumerActor {
    public String getEndpointUri() {
      return "direct:test";
    }

    public void onReceive(Object message) {
    }
  }
}

Other Akka source code examples

Here is a short list of links related to this Akka ActivationTestBase.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.