Reformating configuration and examples for PDF (Scala, and leftovers). See #2413

This commit is contained in:
Björn Antonsson 2012-10-01 20:35:19 +02:00
parent 309bb53d98
commit 08ef942242
46 changed files with 330 additions and 191 deletions

View file

@ -28,13 +28,15 @@ public class ActivationTestBase {
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());
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());
Future<ActorRef> deactivationFuture = camel.deactivationFutureFor(producer,
timeout, system.dispatcher());
//#CamelDeactivation
system.shutdown();
}

View file

@ -23,7 +23,8 @@ public class CamelExtensionTestBase {
ActorSystem system = ActorSystem.create("some-system");
Camel camel = CamelExtension.get(system);
CamelContext camelContext = camel.context();
// camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false"))
// camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent(
// "vm://localhost?broker.persistent=false"));
//#CamelExtensionAddComponent
system.shutdown();
}

View file

@ -8,7 +8,8 @@ import scala.concurrent.util.FiniteDuration;
import java.util.concurrent.TimeUnit;
public class Consumer4 extends UntypedConsumerActor {
private final static FiniteDuration timeout = Duration.create(500, TimeUnit.MILLISECONDS);
private final static FiniteDuration timeout =
Duration.create(500, TimeUnit.MILLISECONDS);
@Override
public FiniteDuration replyTimeout() {

View file

@ -12,12 +12,15 @@ import scala.Option;
public class ErrorThrowingConsumer extends UntypedConsumerActor{
private String uri;
private static Mapper<RouteDefinition, ProcessorDefinition<?>> mapper = new Mapper<RouteDefinition, ProcessorDefinition<?>>() {
public ProcessorDefinition<?> apply(RouteDefinition rd) {
// Catch any exception and handle it by returning the exception message as response
return rd.onException(Exception.class).handled(true).transform(Builder.exceptionMessage()).end();
}
};
private static Mapper<RouteDefinition, ProcessorDefinition<?>> mapper =
new Mapper<RouteDefinition, ProcessorDefinition<?>>() {
public ProcessorDefinition<?> apply(RouteDefinition rd) {
// Catch any exception and handle it by returning the exception message
// as response
return rd.onException(Exception.class).handled(true).
transform(Builder.exceptionMessage()).end();
}
};
public ErrorThrowingConsumer(String uri){
this.uri = uri;
@ -37,7 +40,8 @@ public class ErrorThrowingConsumer extends UntypedConsumerActor{
}
@Override
public Mapper<RouteDefinition, ProcessorDefinition<?>> getRouteDefinitionHandler() {
public Mapper<RouteDefinition,
ProcessorDefinition<?>> getRouteDefinitionHandler() {
return mapper;
}

View file

@ -39,7 +39,8 @@ public class ProducerTestBase {
ActorRef producer = system.actorOf(props,"jmsproducer");
Map<String,Object> headers = new HashMap<String, Object>();
headers.put(CamelMessage.MessageExchangeId(),"123");
producer.tell(new CamelMessage("<order amount=\"100\" currency=\"PLN\" itemId=\"12345\"/>",headers), null);
producer.tell(new CamelMessage("<order amount=\"100\" currency=\"PLN\" " +
"itemId=\"12345\"/>",headers), null);
//#Correlate
system.stop(producer);
system.shutdown();

View file

@ -6,7 +6,8 @@ public class HttpSample {
public static void main(String[] args) {
//#HttpExample
// Create the actors. this can be done in a Boot class so you can
// run the example in the MicroKernel. just add the below three lines to your boot class.
// run the example in the MicroKernel. just add the three lines to below
// your boot class.
ActorSystem system = ActorSystem.create("some-system");
final ActorRef httpTransformer = system.actorOf(new Props(HttpTransformer.class));

View file

@ -11,7 +11,8 @@ public class HttpTransformer extends UntypedActor{
public void onReceive(Object message) {
if (message instanceof CamelMessage) {
CamelMessage camelMessage = (CamelMessage) message;
CamelMessage replacedMessage = camelMessage.mapBody(new Mapper<Object, String>(){
CamelMessage replacedMessage =
camelMessage.mapBody(new Mapper<Object, String>(){
@Override
public String apply(Object body) {
String text = new String((byte[])body);

View file

@ -19,7 +19,8 @@ public class Consumer3 extends UntypedConsumerActor{
public void onReceive(Object message) {
if (message instanceof CamelMessage) {
CamelMessage camelMessage = (CamelMessage) message;
transformer.forward(camelMessage.getBodyAs(String.class, getCamelContext()),getContext());
transformer.forward(camelMessage.getBodyAs(String.class, getCamelContext()),
getContext());
} else
unhandled(message);
}

View file

@ -9,7 +9,8 @@ public class CustomRouteBuilder extends RouteBuilder{
public void configure() throws Exception {
from("direct:welcome").process(new Processor(){
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(String.format("Welcome %s",exchange.getIn().getBody()));
exchange.getOut().setBody(String.format("Welcome %s",
exchange.getIn().getBody()));
}
});
}

View file

@ -7,7 +7,8 @@ public class CustomRouteSample {
public static void main(String[] args) {
try {
//#CustomRouteExample
// the below lines can be added to a Boot class, so that you can run the example from a MicroKernel
// the below lines can be added to a Boot class, so that you can run the
// example from a MicroKernel
ActorSystem system = ActorSystem.create("some-system");
final ActorRef producer = system.actorOf(new Props(Producer1.class));
final ActorRef mediator = system.actorOf(new Props(new UntypedActorFactory() {

View file

@ -15,14 +15,16 @@ public class Transformer extends UntypedActor {
public void onReceive(Object message) {
if (message instanceof CamelMessage) {
// example: transform message body "foo" to "- foo -" and forward result to producer
// example: transform message body "foo" to "- foo -" and forward result
// to producer
CamelMessage camelMessage = (CamelMessage) message;
CamelMessage transformedMessage = camelMessage.mapBody(new Mapper<String, String>(){
@Override
public String apply(String body) {
return String.format("- %s -",body);
}
});
CamelMessage transformedMessage =
camelMessage.mapBody(new Mapper<String, String>(){
@Override
public String apply(String body) {
return String.format("- %s -",body);
}
});
producer.forward(transformedMessage, getContext());
} else
unhandled(message);

View file

@ -57,9 +57,9 @@ public class CustomRouterDocTestBase {
public void demonstrateDispatchers() {
//#dispatchers
final ActorRef router = system.actorOf(new Props(MyActor.class)
// head router runs on "head" dispatcher
// head router will run on "head" dispatcher
.withRouter(new RoundRobinRouter(5).withDispatcher("head"))
// MyActor workers run on "workers" dispatcher
// MyActor workers will run on "workers" dispatcher
.withDispatcher("workers"));
//#dispatchers
}
@ -104,7 +104,6 @@ public class CustomRouterDocTestBase {
}
//#crMessages
//#CustomRouter
static
//#CustomRouter

View file

@ -46,7 +46,8 @@ public class RemoteDeploymentDocTestBase {
addr = AddressFromURIString.parse("akka://sys@host:1234"); // the same
//#make-address
//#deploy
ActorRef ref = system.actorOf(new Props(SampleActor.class).withDeploy(new Deploy(new RemoteScope(addr))));
ActorRef ref = system.actorOf(new Props(SampleActor.class).withDeploy(
new Deploy(new RemoteScope(addr))));
//#deploy
assert ref.path().address().equals(addr);
}