So, what is your question?

On Thu, Jun 2, 2016 at 11:56 AM, Daniel Pompa [via Camel] <
ml-node+s465427n5783385...@n5.nabble.com> wrote:

> Hi, I created a project, I want that the route stops when the Camel Batch
> are complete, I used
> SimpleScheduledRoutePolicy but you have to define a start an end date, and
> always stop the route before the route finish to process. I did this, works
> fine, but I think there is a better way
>
>
> //Creamos una ruta adicional en el contexto
>         context.addRoutes(new RouteBuilder() {
>
>
>             public void configure() {
>
> onException(Exception.class).setRedeliveryPolicy(redeliveryPolicy);
>
>
>             from("smb://"+ inputXrtSmbDomain +";"+ inputXrtSmbUser +"@"+
> inputXrtSmbServer +"/"+ inputXrtSmbFolder +"?password="+
> inputXrtSmbPassword + "&delete=false&delay=60000")
>             .routeId("sap-xrt-connect-interface-receive-" + fileNameOnly)
>
> .setProperty("CamelBatchComplete").simple("${property.CamelBatchComplete}")
>             .process(new Processor() {
>                 @Override
>                 public void process(Exchange exchange) throws Exception {
>
>                 CamelBatchComplete =
> exchange.getProperty("CamelBatchComplete").toString();
>                 }
>                 })
>             .filter().method(new GenericFileFilter<T> (){
>
>                 @Override
>                 public boolean accept(GenericFile<T> file) {
>
>                 Date fileNameLastModified = new
> Date(file.getLastModified());
>
>
>                 //Se realiza la comprobacion de fechas
>                 if(fileNameLastModified.after(documentDateBefore) &&
> fileNameLastModified.before(documentDateAfter)){
>                 return true;
>                 }else{
>                 return false;
>                 }
>
>                 }
>                 }).process(new Processor() {
>                 @Override
>                 public void process(Exchange exchange) throws Exception {
>
>                 GenericFileMessage<File> msg =
> exchange.getIn(GenericFileMessage.class);
>                         String fileName []=
> msg.getGenericFile().getFileNameOnly().split("\\.");
>
>                         // Se realiza la validacion de cuando el fichero
> tiene extension o no
>                         String destinationPath = String.format("%s%s_%s",
> fileNameOnly,fileName[0], 2 <= fileName.length ? fileName[1] : "");
>
>                         exchange.getOut().setBody(msg.getBody());
>                 exchange.getOut().setHeader(Exchange.FILE_NAME,
> destinationPath);
>
>                    }
>                 })
>                 .to("sftp://"+ outputSapFtpUser +"@"+ outputSapFtpServer
> +"/"+ outputSapFtpPFolder +"?flatten=true&password="+ outputSapFtpPassword
> +"&passiveMode="+ outputSapFtpPassiveMode +"&binary=true&autoCreate=false")
>                 .log("sent file ${file:name} to SAP");
>             }
>         });
>
>
> The Stop Code
>
>
> if(context.getRouteStatus("sap-xrt-connect-interface-receive-" +
> fileNameOnly).isStarted()){  // Se verifica si se inicio la ruta
>
>                 int CamelBatchValidator = 0;
>                 do{
>
>                 Thread.sleep(10000); // Se realiza la verificacion cada 10
> segundos si la interfaz culmino su procesamiento
>
>                 if (CamelBatchComplete=="true"){
>
>                  Thread.sleep(20000); // Tiempo adicional para verificar
> que todo ha culminado
>
>                  context.stopRoute("sap-xrt-connect-interface-receive-" +
> fileNameOnly);
>
>                  Thread.sleep(10000);
>
>                  context.removeRoute("sap-xrt-connect-interface-receive-"
> + fileNameOnly);
>
>                      CamelBatchValidator=1;
>                      CamelBatchComplete = null;
>                 }else{
>
>                 //Si la ruta esta vacia o hay error al conectar , esto
> hara que entre en el IF de arriba y elimine la ruta
>                 if(CamelBatchComplete == null){
>
>                 CamelBatchComplete="true";
>                 }
>
>                 }
>
>
>                 }while(CamelBatchValidator==0);
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/How-to-stop-a-dynamic-route-tp5783385.html
> To start a new topic under Camel - Users, email
> ml-node+s465427n465428...@n5.nabble.com
> To unsubscribe from Camel - Users, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: 
http://camel.465427.n5.nabble.com/How-to-stop-a-dynamic-route-tp5783385p5783387.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to