/*
 * Copyright 2013 Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apacheextras.camel.examples.rcode;

import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 *
 * @author cemmersb
 */
public class RCodeRunner {

  private final static Logger LOGGER = LoggerFactory.getLogger(RCodeRunner.class);
  private CamelContext camelContext;
  private RCodeRouteBuilder routeBuilder = null;

  public RCodeRunner() {
    try {
      initializeContext();
    } catch (Exception ex) {
      LOGGER.error("Unable to initialize context: {}", ex.getMessage());
    }
  }

  private void initializeContext() throws Exception {
    routeBuilder = new RCodeRouteBuilder(new File(System.getProperty("user.dir") + "./rcode-example/data"));
    camelContext = new DefaultCamelContext();
    camelContext.addRoutes(routeBuilder);
    camelContext.start();
  }

  @Override
  protected void finalize() throws Throwable {
    camelContext.stop();
    super.finalize();
  }

  public static void main(String... args) throws InterruptedException, Throwable {
    LOGGER.info("Starting RCodeRunner.");
    RCodeRunner rCodeRunner = new RCodeRunner();
    Thread.sleep(1000);
    LOGGER.info("Stopping RCodeRunner.");
    rCodeRunner.finalize();
  }
}

@@ -1,616 +1,4 @@
-/*%0A * Copyright 2013 Apache Software Foundation.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 pack
@@ -133,95 +133,97 @@
 xt;%0A
+%0A
 import 
-org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.File
+java.io.Console;%0Aimport java.io.File;%0Aimport java.util.concurrent.TimeUnit
 ;%0A%0A/**%0A
- *%0A
  * @
@@ -233,16 +233,22 @@
 hor 
-cemmersb
+Sebastian R%C3%BChl
 %0A */
@@ -283,445 +283,183 @@
 %0A  p
-rivate final static Logger LOGGER = LoggerFactory.getLogger(RCodeRunner.class);%0A  private CamelContext camelContext;%0A  private RCodeRouteBuilder routeBuilder = null;%0A%0A  public RCodeRunner() %7B%0A    try %7B%0A      initializeContext();%0A    %7D catch (Exception ex) %7B%0A      LOGGER.error(%22Unable to initialize context: %7B%7D%22, ex.getMessage());%0A    %7D%0A  %7D%0A%0A  private void initializeContext() throws Exception %7B%0A    routeBuilder = new RCodeRouteBuilder(
+ublic static void main(String... args) throws Exception %7B%0A    CamelContext camelContext = new DefaultCamelContext();%0A    File basePath = args.length %3E 0 ? new File(args%5B0%5D) : 
 new 
@@ -492,19 +492,20 @@
 ser.
-dir
+home
 %22) + %22
-.
 /
+.
 rcod
@@ -517,63 +517,12 @@
 mple
-/data%22));%0A    camelContext = new DefaultCamelContext();
+%22);%0A
 %0A   
@@ -545,17 +545,26 @@
 dRoutes(
-r
+new RCodeR
 outeBuil
@@ -566,19 +566,30 @@
 eBuilder
+(basePath)
 );%0A
+%0A
     came
@@ -612,386 +612,235 @@
 ;%0A  
-%7D%0A%0A  @Override%0A  protected void finalize() throws Throwable %7B%0A    camelContext.stop();%0A    super.finalize();%0A  %7D%0A%0A  public static void main(String... args) throws I
+  Console console = System.console();%0A    if (console != null) %7B%0A      console.printf(%22Please press e
 nter
-ruptedException, Throwable %7B%0A    LOGGER.info(%22Starting RCodeRunner.%22);%0A    RCodeRunner rCodeRunner = new RCodeRunner();%0A    Thread
+ to shutdown route.%22);%0A      console.readLine();%0A    %7D else %7B%0A      TimeUnit.SECONDS
 .sleep(
-1000
+5
 );%0A    
-LOGGER.info(%22Stopping RCodeRunner.%22);%0A    rCodeRunner.finalize
+%7D%0A    camelContext.stop
 ();%0A

migrate example to rcoderunner