Last active
August 29, 2015 14:21
-
-
Save gautric/7b03d5b352d29ee71dbb to your computer and use it in GitHub Desktop.
CamelMain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.camellabs.component.pi4j; | |
import org.apache.camel.CamelContext; | |
import org.apache.camel.builder.RouteBuilder; | |
import org.apache.camel.impl.DefaultCamelContext; | |
import org.apache.camel.model.RouteDefinition; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
/** | |
* A simple application to run RaspberryPi Camel | |
*/ | |
public final class CamelMain { | |
private static final Logger LOG = LoggerFactory.getLogger(CamelMain.class); | |
private CamelMain() { | |
} | |
public static class CommandLineRouteBuilder extends RouteBuilder { | |
String[] args; | |
CommandLineRouteBuilder(String[] args) { | |
this.args = args; | |
} | |
@Override | |
public void configure() throws Exception { | |
RouteDefinition rd = from(args[0]).id("raspberrypi-route"); | |
rd = rd.to(Pi4jConstants.LOG_COMPONENT); | |
for (int i = 1; i < args.length; i++) { | |
rd = rd.to(args[i]); | |
} | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
LOG.info("main"); | |
for (int i = 0; i < args.length; i++) { | |
LOG.info("args[" + i + "] = " + args[i]); | |
} | |
CamelContext context = new DefaultCamelContext(); | |
context.addRoutes(new CommandLineRouteBuilder(args)); | |
context.start(); | |
Thread.sleep(60000); | |
context.stop(); | |
System.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment