You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Bengt Rodehav <be...@rodehav.com> on 2010/10/14 14:41:09 UTC

Use simple language from within a processor

I have a configurable camel route for monitoring certain directories. I use
the quartz component to perform my monitoring actions at certain scheduled
times (e g to check that a certain file exists in a certain directory at a
certain time).

I configure my route by giving it the directory to monitor (and a few other
things). However, what directory to monitor depends on what day it is. E g
files that are processed are moved to an archive directory with a
subdirectory name with today's date ( e g ./archive/20101014).

I perform my actual monitoring in a custom processor. I would like to
configure this using the simple language, e g like this:

# Directory to monitor

directory=./archive/${date:now:yyyyMMdd}


I've been using the simple language before as part of the route. However, I
don't know how I can evaluate a simple language expression (like the
directory property above) from within my custom processor. Can anyone help
with this? My code is similar to the following:

from("quartz://" + group + "/" + timerName + "?cron=" + cron).process(new
> ConditionProcessor(condition, mDirectory));

...

public class ConditionProcessor implements Processor {

  private ICondition mCondition;

  private String mDirectory;


>   public ConditionProcessor(ICondition theCondition, String theDirectory) {

    mCondition = theCondition;

    mDirectory = theDirectory;

  }


>   public void process(Exchange theExchange) throws Exception {

    String evaluatedDirectory = ???; // Evaluate "theDirectory" with simple
> language

    if (!mCondition.check(evaluatedDirectory)) {

      // Send notification

    }

  }

}


I'm using Camel 2.4 now but will update to Camel 2.5 when it's available.

/Bengt

Re: Use simple language from within a processor

Posted by Bengt Rodehav <be...@rodehav.com>.
Thanks a lot Willem!

/Bengt

2010/10/14 Willem Jiang <wi...@gmail.com>

> You can create the expression with below code
>
>  Language language = camelContext.resolveLanguage(simple);
>  Expression expression =
> language.createExpression("./archive/${date:now:yyyyMMdd}"));
>
>  in the process(Exchange exchange) method, you can use the expression like
> this
>
>  String value = expression.evaluate(exchange, String.class);
>
>
>
> On 10/14/10 8:41 PM, Bengt Rodehav wrote:
>
>> I have a configurable camel route for monitoring certain directories. I
>> use
>> the quartz component to perform my monitoring actions at certain scheduled
>> times (e g to check that a certain file exists in a certain directory at a
>> certain time).
>>
>> I configure my route by giving it the directory to monitor (and a few
>> other
>> things). However, what directory to monitor depends on what day it is. E g
>> files that are processed are moved to an archive directory with a
>> subdirectory name with today's date ( e g ./archive/20101014).
>>
>> I perform my actual monitoring in a custom processor. I would like to
>> configure this using the simple language, e g like this:
>>
>> # Directory to monitor
>>
>> directory=./archive/${date:now:yyyyMMdd}
>>
>>
>> I've been using the simple language before as part of the route. However,
>> I
>> don't know how I can evaluate a simple language expression (like the
>> directory property above) from within my custom processor. Can anyone help
>> with this? My code is similar to the following:
>>
>> from("quartz://" + group + "/" + timerName + "?cron=" + cron).process(new
>>
>>> ConditionProcessor(condition, mDirectory));
>>>
>>
>> ...
>>
>> public class ConditionProcessor implements Processor {
>>
>>   private ICondition mCondition;
>>
>>   private String mDirectory;
>>
>>
>>    public ConditionProcessor(ICondition theCondition, String theDirectory)
>>> {
>>>
>>
>>     mCondition = theCondition;
>>
>>     mDirectory = theDirectory;
>>
>>   }
>>
>>
>>    public void process(Exchange theExchange) throws Exception {
>>>
>>
>>     String evaluatedDirectory = ???; // Evaluate "theDirectory" with
>> simple
>>
>>> language
>>>
>>
>>     if (!mCondition.check(evaluatedDirectory)) {
>>
>>       // Send notification
>>
>>     }
>>
>>   }
>>
>> }
>>
>>
>> I'm using Camel 2.4 now but will update to Camel 2.5 when it's available.
>>
>> /Bengt
>>
>>
>
> --
> Willem
> ----------------------------------
> Open Source Integration: http://www.fusesource.com
> Blog:    http://willemjiang.blogspot.com (English)
>         http://jnn.javaeye.com (Chinese)
> Twitter: http://twitter.com/willemjiang
>

Re: Use simple language from within a processor

Posted by Willem Jiang <wi...@gmail.com>.
You can create the expression with below code

  Language language = camelContext.resolveLanguage(simple);
  Expression expression = 
language.createExpression("./archive/${date:now:yyyyMMdd}"));

  in the process(Exchange exchange) method, you can use the expression 
like this

   String value = expression.evaluate(exchange, String.class);


On 10/14/10 8:41 PM, Bengt Rodehav wrote:
> I have a configurable camel route for monitoring certain directories. I use
> the quartz component to perform my monitoring actions at certain scheduled
> times (e g to check that a certain file exists in a certain directory at a
> certain time).
>
> I configure my route by giving it the directory to monitor (and a few other
> things). However, what directory to monitor depends on what day it is. E g
> files that are processed are moved to an archive directory with a
> subdirectory name with today's date ( e g ./archive/20101014).
>
> I perform my actual monitoring in a custom processor. I would like to
> configure this using the simple language, e g like this:
>
> # Directory to monitor
>
> directory=./archive/${date:now:yyyyMMdd}
>
>
> I've been using the simple language before as part of the route. However, I
> don't know how I can evaluate a simple language expression (like the
> directory property above) from within my custom processor. Can anyone help
> with this? My code is similar to the following:
>
> from("quartz://" + group + "/" + timerName + "?cron=" + cron).process(new
>> ConditionProcessor(condition, mDirectory));
>
> ...
>
> public class ConditionProcessor implements Processor {
>
>    private ICondition mCondition;
>
>    private String mDirectory;
>
>
>>    public ConditionProcessor(ICondition theCondition, String theDirectory) {
>
>      mCondition = theCondition;
>
>      mDirectory = theDirectory;
>
>    }
>
>
>>    public void process(Exchange theExchange) throws Exception {
>
>      String evaluatedDirectory = ???; // Evaluate "theDirectory" with simple
>> language
>
>      if (!mCondition.check(evaluatedDirectory)) {
>
>        // Send notification
>
>      }
>
>    }
>
> }
>
>
> I'm using Camel 2.4 now but will update to Camel 2.5 when it's available.
>
> /Bengt
>


-- 
Willem
----------------------------------
Open Source Integration: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: http://twitter.com/willemjiang