FAQ
Hello All,

I am using thread dsl to implement parallel processing in my route.

I have one ROUTE_FTP -- from (ftp).to(fileUrl).bean(endRoute);

I want to use thread dsl .. so that threads pick up files n do processing
simultaneously. With camel , it was so easy to do this.

I created a ThreadPoolProfile whose size is 5 and registered with
ExecutorServiceManager

ExecutorService service ;

ThreadPoolProfile customProfile = new ThreadPoolProfile("customProfile");
customProfile.setPoolSize(5);
customProfile.setMaxPoolSize(5);

camelContext.getExecutorServiceManager().registerThreadPoolProfile(customProfile);
service = camelContext.getExecutorServiceManager().newThreadPool(this,
localRouteName, customProfile);

from(fileUrl).noAutoStartup().routeId(localRouteName)
.threads()
.bean(processManager)
.bean(endRoute,localMethod).stop()
.setExecutorService(service);

later when route is completed , i am calling this to remove the threads.
camelContext.getExecutorServiceManager().shutdown(service);

Everything is working perfectly. I would like to learn how better we could
make this.

Only concern i have is .. ROUTE_FTP and ROUTE_LOCAL can be given commands to
suspend, resume and cancel.

when my action is suspend/resume/cancel , camel is unable to do the action.
How to achieve this. I want the threads also to be suspended/resumed/cancel
along with my route.

sample pause function
public void pause() {
try {
for (String routeId : routesIds) {
ServiceStatus routeStatus = camelContext.getRouteStatus(routeId);
if (routeStatus.isStarted()) {
camelContext.suspendRoute(routeId);
logger.info("Route : "+routeId+" suspended");
} else if (routeStatus.isStopped()) {
logger.info(true, tubeMessage.getSourceName(), "Route : " + routeId + "
is stopped , so cant pause");
}
}
} catch (Exception e) {
logger.error(true, tubeMessage.getSourceName(), "Problem while pausing
the mediation process " + e.getMessage());
}
}// pause

What things should be done in order to do this. Earlier , without threads(),
suspend/resume/cancel were working fine.

Please help me

Thanks & Regards
Nafees



--
View this message in context: http://camel.465427.n5.nabble.com/Routes-controlling-thread-dsl-tp5719019.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Search Discussions

  • Claus Ibsen at Sep 10, 2012 at 10:37 am
    The FTP client library do not support concurrency, so you cannot
    download multiple FTP files at the same time.

    Read the red box at its documentation page
    http://camel.apache.org/ftp2

    On Mon, Sep 10, 2012 at 12:08 PM, Nafees wrote:
    Hello All,

    I am using thread dsl to implement parallel processing in my route.

    I have one ROUTE_FTP -- from (ftp).to(fileUrl).bean(endRoute);

    I want to use thread dsl .. so that threads pick up files n do processing
    simultaneously. With camel , it was so easy to do this.

    I created a ThreadPoolProfile whose size is 5 and registered with
    ExecutorServiceManager

    ExecutorService service ;

    ThreadPoolProfile customProfile = new ThreadPoolProfile("customProfile");
    customProfile.setPoolSize(5);
    customProfile.setMaxPoolSize(5);

    camelContext.getExecutorServiceManager().registerThreadPoolProfile(customProfile);
    service = camelContext.getExecutorServiceManager().newThreadPool(this,
    localRouteName, customProfile);

    from(fileUrl).noAutoStartup().routeId(localRouteName)
    .threads()
    .bean(processManager)
    .bean(endRoute,localMethod).stop()
    .setExecutorService(service);

    later when route is completed , i am calling this to remove the threads.
    camelContext.getExecutorServiceManager().shutdown(service);

    Everything is working perfectly. I would like to learn how better we could
    make this.

    Only concern i have is .. ROUTE_FTP and ROUTE_LOCAL can be given commands to
    suspend, resume and cancel.

    when my action is suspend/resume/cancel , camel is unable to do the action.
    How to achieve this. I want the threads also to be suspended/resumed/cancel
    along with my route.

    sample pause function
    public void pause() {
    try {
    for (String routeId : routesIds) {
    ServiceStatus routeStatus = camelContext.getRouteStatus(routeId);
    if (routeStatus.isStarted()) {
    camelContext.suspendRoute(routeId);
    logger.info("Route : "+routeId+" suspended");
    } else if (routeStatus.isStopped()) {
    logger.info(true, tubeMessage.getSourceName(), "Route : " + routeId + "
    is stopped , so cant pause");
    }
    }
    } catch (Exception e) {
    logger.error(true, tubeMessage.getSourceName(), "Problem while pausing
    the mediation process " + e.getMessage());
    }
    }// pause

    What things should be done in order to do this. Earlier , without threads(),
    suspend/resume/cancel were working fine.

    Please help me

    Thanks & Regards
    Nafees



    --
    View this message in context: http://camel.465427.n5.nabble.com/Routes-controlling-thread-dsl-tp5719019.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    Twitter: davsclaus, fusenews
    Blog: http://davsclaus.com
    Author of Camel in Action: http://www.manning.com/ibsen
  • Nafees at Sep 11, 2012 at 5:07 am
    Hello Claus,

    I might not be clear in presenting my problem, I have concurrency for the
    second route.

    ROUTE_LOCAL :
    fileUrl - file:///home/user/domediation

    from(fileUrl).noAutoStartup().routeId(localRouteName)
    .threads()
    .bean(processManager)
    .bean(endRoute,localMethod).stop()
    .setExecutorService(service);

    If we are trying to suspend this route , let the threads complete processing
    current file. But, they should not pick up next files. How this can be
    accomplished.

    Awaiting ur reply

    Nafees



    --
    View this message in context: http://camel.465427.n5.nabble.com/Routes-controlling-thread-dsl-tp5719019p5719074.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Claus Ibsen at Sep 11, 2012 at 9:25 am

    On Tue, Sep 11, 2012 at 5:44 AM, Nafees wrote:
    Hello Claus,

    I might not be clear in presenting my problem, I have concurrency for the
    second route.

    ROUTE_LOCAL :
    fileUrl - file:///home/user/domediation

    from(fileUrl).noAutoStartup().routeId(localRouteName)
    .threads()
    .bean(processManager)
    .bean(endRoute,localMethod).stop()
    .setExecutorService(service);

    If we are trying to suspend this route , let the threads complete processing
    current file. But, they should not pick up next files. How this can be
    accomplished.
    Just stop the route using the API, it will stop the route graceful.
    http://camel.apache.org/graceful-shutdown.html

    You can assign an id to the route using .routeId("myCoolRoute").
    And then stop the route using its id. There is API on CamelContext.
    Or from JMX etc.

    Awaiting ur reply

    Nafees



    --
    View this message in context: http://camel.465427.n5.nabble.com/Routes-controlling-thread-dsl-tp5719019p5719074.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    Twitter: davsclaus, fusenews
    Blog: http://davsclaus.com
    Author of Camel in Action: http://www.manning.com/ibsen
  • Claus Ibsen at Sep 11, 2012 at 9:25 am
    And check also this FAQ
    http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html
    On Tue, Sep 11, 2012 at 11:24 AM, Claus Ibsen wrote:
    On Tue, Sep 11, 2012 at 5:44 AM, Nafees wrote:
    Hello Claus,

    I might not be clear in presenting my problem, I have concurrency for the
    second route.

    ROUTE_LOCAL :
    fileUrl - file:///home/user/domediation

    from(fileUrl).noAutoStartup().routeId(localRouteName)
    .threads()
    .bean(processManager)
    .bean(endRoute,localMethod).stop()
    .setExecutorService(service);

    If we are trying to suspend this route , let the threads complete processing
    current file. But, they should not pick up next files. How this can be
    accomplished.
    Just stop the route using the API, it will stop the route graceful.
    http://camel.apache.org/graceful-shutdown.html

    You can assign an id to the route using .routeId("myCoolRoute").
    And then stop the route using its id. There is API on CamelContext.
    Or from JMX etc.

    Awaiting ur reply

    Nafees



    --
    View this message in context: http://camel.465427.n5.nabble.com/Routes-controlling-thread-dsl-tp5719019p5719074.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    Twitter: davsclaus, fusenews
    Blog: http://davsclaus.com
    Author of Camel in Action: http://www.manning.com/ibsen


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    Twitter: davsclaus, fusenews
    Blog: http://davsclaus.com
    Author of Camel in Action: http://www.manning.com/ibsen
  • Nafees at Sep 11, 2012 at 10:08 am
    Hello,

    This is my setup, I am associating a routeId to the route and using this I
    will be suspending/resuming/stopping the route on camelContext reference.

    String localRouteName = "ROUTE_LOCAL";
    ExecutorService service ;

    //Custom thread pool
    ThreadPoolProfile customProfile = new ThreadPoolProfile("customProfile");
    customProfile.setPoolSize(threads);
    customProfile.setMaxPoolSize(threads);

    camelContext.getExecutorServiceManager().registerThreadPoolProfile(customProfile);
    service = camelContext.getExecutorServiceManager().newThreadPool(this,
    localRouteName, customProfile);

    from(fileUrl).noAutoStartup().routeId(localRouteName)
    .threads()
    .bean(processManager)
    .bean(endRoute,localMethod).stop()
    .setExecutorService(service);

    e.g.
    public void pause() {
    try {
    for (String routeId : routesIds) {
    ServiceStatus routeStatus = camelContext.getRouteStatus(routeId);
    if (routeStatus.isStarted()) {
    camelContext.suspendRoute(routeId);
    logger.info("Route : "+routeId+" suspended");
    } else if (routeStatus.isStopped()) {
    logger.info(true, tubeMessage.getSourceName(), "Route : " + routeId + "
    is stopped , so cant pause");
    }
    }
    } catch (Exception e) {
    logger.error(true, tubeMessage.getSourceName(), "Problem while pausing
    the mediation process " + e.getMessage());
    }
    }

    The problem I am facing is, though i am calling
    camelContext.suspendRoute("ROUTE_LOCAL"), it is not suspending it. The
    threads are picking the files one after the other. I want to know whether
    there is any way in which the thread pool can be controlled..After all files
    are processed, then it is suspending/resuming/stopping.

    Prior to concurrency introduction, it was running fine.

    Please guide me.

    Thanks
    Nafees




    --
    View this message in context: http://camel.465427.n5.nabble.com/Routes-controlling-thread-dsl-tp5719019p5719102.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Claus Ibsen at Sep 11, 2012 at 10:15 am
    You need to set the max queue of the pool to 0 if you dont want any
    backlog on the thread pool.

    On Tue, Sep 11, 2012 at 12:03 PM, Nafees wrote:
    Hello,

    This is my setup, I am associating a routeId to the route and using this I
    will be suspending/resuming/stopping the route on camelContext reference.

    String localRouteName = "ROUTE_LOCAL";
    ExecutorService service ;

    //Custom thread pool
    ThreadPoolProfile customProfile = new ThreadPoolProfile("customProfile");
    customProfile.setPoolSize(threads);
    customProfile.setMaxPoolSize(threads);

    camelContext.getExecutorServiceManager().registerThreadPoolProfile(customProfile);
    service = camelContext.getExecutorServiceManager().newThreadPool(this,
    localRouteName, customProfile);

    from(fileUrl).noAutoStartup().routeId(localRouteName)
    .threads()
    .bean(processManager)
    .bean(endRoute,localMethod).stop()
    .setExecutorService(service);

    e.g.
    public void pause() {
    try {
    for (String routeId : routesIds) {
    ServiceStatus routeStatus = camelContext.getRouteStatus(routeId);
    if (routeStatus.isStarted()) {
    camelContext.suspendRoute(routeId);
    logger.info("Route : "+routeId+" suspended");
    } else if (routeStatus.isStopped()) {
    logger.info(true, tubeMessage.getSourceName(), "Route : " + routeId + "
    is stopped , so cant pause");
    }
    }
    } catch (Exception e) {
    logger.error(true, tubeMessage.getSourceName(), "Problem while pausing
    the mediation process " + e.getMessage());
    }
    }

    The problem I am facing is, though i am calling
    camelContext.suspendRoute("ROUTE_LOCAL"), it is not suspending it. The
    threads are picking the files one after the other. I want to know whether
    there is any way in which the thread pool can be controlled..After all files
    are processed, then it is suspending/resuming/stopping.

    Prior to concurrency introduction, it was running fine.

    Please guide me.

    Thanks
    Nafees




    --
    View this message in context: http://camel.465427.n5.nabble.com/Routes-controlling-thread-dsl-tp5719019p5719102.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    Twitter: davsclaus, fusenews
    Blog: http://davsclaus.com
    Author of Camel in Action: http://www.manning.com/ibsen
  • Nafees at Sep 12, 2012 at 6:45 am
    I will incorporate ur suggestions, and come back again.

    Thank you

    Nafees



    --
    View this message in context: http://camel.465427.n5.nabble.com/Routes-controlling-thread-dsl-tp5719019p5719163.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedSep 10, '12 at 10:15a
activeSep 12, '12 at 6:45a
posts8
users2
websitecamel.apache.org

2 users in discussion

Nafees: 4 posts Claus Ibsen: 4 posts

People

Translate

site design / logo © 2022 Grokbase