camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Is there a way to send a message when I am terminating?
Date Fri, 08 Nov 2013 14:12:12 GMT
Look better at the javadoc / api.

There is afterStart / beforeStop methods.

And you should use the run method to keep it running.
And enableHangup if you want Camel to detect if the JVM is terminated
with ctrl +c, etc. And stop graceful.

On Fri, Nov 8, 2013 at 1:54 PM, pmp.martins
<pmp.martins@campus.fct.unl.pt> wrote:
> Hey, I have read the Main API and decided to override the doStart and doStop
> methods. However, they don't work as one may expect, espcially the doStop
> method, which seems quite useless.
>
> First I have a problem. In my main, when I use main.start(), the progam does
> not hangup, even though I specify that I want hangupsupport. Therefore, I
> have to use the run() method, instead of the start() method.
>
> Then there is the stop() method. In my example, using main.stop() seems
> useless at best. For a method that is supposed to stop the server (or so it
> is what I assume) it simply does not work when I use main.run() instead of
> main.start().
>
> Now to the doStart() and doStop() methods that I override. The doStart()
> method is always called when I call main.start() or main.run(), which is
> what I expected.
>
> However, the doStop() method only is called when I use main.start(). I will
> not run if I use main.run(). Furthermore, if the server is running, and I
> terminate it using CTRL+C, the doStop() method will not be called as well.
>
> This leaves me with the question: am I using the methods wrong or are they
> bugged? I believe it is the first one, but I am not sure.
>
> Here is the sample app I am testing, in case you need:
>
> public class MyApp_B extends Main{
>
>         public static void main(String... args) throws Exception {
>                 MyApp_B main = new MyApp_B();
>
>                 main.enableHangupSupport();
>
>                 main.addRouteBuilder(
>                                 new RouteBuilder(){
>                                         @Override
>                                         public void configure() throws Exception {
>                                                 //TODO main job of the route here, change
and forward reports
>                                         }
>                                 }
>                 );
>
>                 System.out.println("Starting Camel MyApp_B. Use ctrl + c to terminate
the
> JVM.\n");
>                 main.run();
>
>                 //main.start() wont hangup, the program terminates immediately
>                 //main.stop() wont work with main.run(), only works with main.start()
>         }
>
>
>         @Override
>         protected void doStart(){
>                 System.out.println("Starting !");
>
>                 addRouteBuilder(new RouteBuilder(){
>                         @Override
>                         public void configure() throws Exception {
>                                 // TODO generate Message with local IP and send it to
master asking him
> to ADD me
>                         }
>                 });
>         }
>
>         @Override
>         protected void doStop(){
>                 System.out.println("Stopping !");
>
>                 addRouteBuilder(new RouteBuilder(){
>                         @Override
>                         public void configure() throws Exception {
>                                 // TODO generate Message with local IP and send it to
master asking him
> to REMOVE me
>                         }
>                 });
>         }
> }
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Is-there-a-way-to-send-a-message-when-I-am-terminating-tp5742834p5742851.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Mime
View raw message