Search in sources :

Example 1 with DelegatingRuntime

use of org.apache.camel.k.support.DelegatingRuntime in project camel-k-runtime by apache.

the class Application method load.

@GET
@Path("/load")
@Produces(MediaType.TEXT_PLAIN)
public String load() throws Exception {
    final String code = "" + "\n- from:" + "\n    uri: \"timer:tick?period=1&delay=60000\"" + "\n    steps:" + "\n      - log: \"${body}\"";
    final YamlRoutesBuilderLoader loader = new YamlRoutesBuilderLoader();
    loader.setCamelContext(context);
    loader.build();
    final Runtime rt = new DelegatingRuntime(runtime) {

        @Override
        public void stop() throws Exception {
            stopped.set(true);
        }
    };
    final CronSourceLoaderInterceptor interceptor = new CronSourceLoaderInterceptor();
    interceptor.setRuntime(rt);
    interceptor.setOverridableComponents("timer");
    final RouteBuilder builder = (RouteBuilder) loader.loadRoutesBuilder(ResourceHelper.fromBytes("my-cron.yaml", code.getBytes(StandardCharsets.UTF_8)));
    builder.addLifecycleInterceptor(interceptor);
    try {
        context.addRoutes(builder);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return "" + context.getRoutesSize();
}
Also used : DelegatingRuntime(org.apache.camel.k.support.DelegatingRuntime) Runtime(org.apache.camel.k.Runtime) RouteBuilder(org.apache.camel.builder.RouteBuilder) DelegatingRuntime(org.apache.camel.k.support.DelegatingRuntime) CronSourceLoaderInterceptor(org.apache.camel.k.cron.CronSourceLoaderInterceptor) YamlRoutesBuilderLoader(org.apache.camel.dsl.yaml.YamlRoutesBuilderLoader) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 YamlRoutesBuilderLoader (org.apache.camel.dsl.yaml.YamlRoutesBuilderLoader)1 Runtime (org.apache.camel.k.Runtime)1 CronSourceLoaderInterceptor (org.apache.camel.k.cron.CronSourceLoaderInterceptor)1 DelegatingRuntime (org.apache.camel.k.support.DelegatingRuntime)1