correct way to shutdown

Help
Duke
2006-02-25
2013-04-08
  • Duke
    Duke
    2006-02-25

    What is the correct way to manually trigger a shutdown.

    I'm embedding MantaRay within my application which runs as a Windows service. When I stop the service, it doesnt seem to be calling "ServiceRecallShutdownHook" but if I terminate the program programmatically, the shutdown hook is triggered correctly.

    Is there a way I can shutdown mantaray gracefully from my own shutdownhook handler?

    Thanks

    Duke

     
    • Duke
      Duke
      2006-02-25

      I tried registering the shutdown hook below but this does not work when stopping as service.

      Runtime.getRuntime().addShutdownHook(new org.mr.kernel.services.ServiceRecallShutdownHook());

      It works ok when running from the command line, the shutdown hook gets invoked twice.

      Any ideas?

      Thanks

      Duke

       
      • Yuval Lubowich
        Yuval Lubowich
        2006-02-25

        Duke,

        Can you add more information about the "service", how do you run it? Did you use a 3rd party tool? Did you write something yourself? Do you see anything in the log files?

        I am guessing from your previous question that your own shutdown hook is called when the service terminates. Is that correct?

        I may be looking at this issue for the wrong reasons, but it maybe that when the service is stopped, some time is given to the JMV to gracefully terminate, after that the JVM is killed violently???

        Again more information might help us in figuring out this thing.

        Yuval Lubowich
        Chief Architect
        MantaRay Team

         
    • Duke
      Duke
      2006-02-27

      Hi Yuval,

      The tool that I use to register the java app as a service requires that you specific the method that is called when the windows service is shutdown. The shutdown hook doesnt actually get triggered (including my own). My terminate method is just called from this wrapper.

      Is there a way I can manually shutdown mantaray rather than relying on the shutdown hook?

      Thanks a bunch.

      Duke

       
      • Yuval Lubowich
        Yuval Lubowich
        2006-02-27

        Duke,

        A programmatic way of shutting down MantaRay is in the works and will probably make the next release.
        I will post a reply on this thread when this feature is ready.

        Yuval

         
        • Hi, I have a similar problem: I initialized the JMS using SimpleAPI. Then I open a Publisher. Then I wait 2 seconds, call new ServiceRecallShutdownHook().run() and wait for the VM to terminate. Nothing happens actually, there are still a lot of Threads hanging around (AgentMonitorExecThread, TimeoutMonitorStat_Timer, NetworkSelector, Incoming messagesExecThread, IncomingClientMessagesExecThread, GroupReactor, ADControlSenderThread, DynamicQueuesCoordinator, Session[..]@ExecThread). These threads keep the VM from terminating. Is there a way to stop them manually, without calling System.exit()?

          Here is my example code:

          import org.mr.MantaAgent;
          import org.mr.api.simple.Publisher;
          import org.mr.api.simple.SimpleAPI;
          import org.mr.kernel.services.ServiceRecallShutdownHook;

          public class MessageTool {
            private static final String configPath = ".";
            private Publisher publisher = null;

            public MessageTool() throws Exception {
              final SimpleAPI api = new SimpleAPI(configPath);
              this.publisher = api.openPublisher("TROJAN");
            }

            public static void main(final String[] args) throws Exception {
              new MessageTool();
              Thread.sleep(2000);
              new ServiceRecallShutdownHook().run();
            }

          }

          Thanks in advance,
          regards Hans.

           
          • aviad
            aviad
            2006-08-08

            Hi Hans
            I suspect that you got the whole concept wrong, as I will explain:
            MantaRay runs daemon threads that are up as long as the JVM is running, the
            ServiceRecallShutdownHook - is as its name proposes only recalls the
            services registered on the current layer before the JVM terminates.
            This class is to be called by the system only!!! It is being called only on
            termination of the JVM.
            If you wish to terminate the JVM by code you can use the System.exit() method.
            If you want to do it from the shell you can use ctrl C.
            All the thread remain running during until the JVM terminates since at any given time the “world” might change – that is new subscribers might be created, or even durable subscribers that must be kept persistently for the next time one might want to sent them messages.
            But we do have in our road map the ability to shutdown MantaRay completely and terminate all MantaRay threads.
            You mentioned that you use the simple API instead of the JMS API, well The JMS API is supposed to be faster then the Simple API, the Simple API goal is to provide a less cumbersome way to send messages.

            Hopes that makes things a little clearer
            Aviad
            MantaRay team

             
            • OK, I understand. Many thanks!

               
    • Duke
      Duke
      2006-02-27

      Just thought of the right way to shutdown. I should just call System.exit() from the windows service wrapper rather than calling my terminate method directly.

      Thanks for you help Yuval.

      Duke

       
    • Was the programmatic method of shutting down MantaRay (without shutting down the JVM) ever released ?