3 Replies Latest reply on Feb 25, 2008 5:51 AM by Ales Justin

    To get Event when Jboss is called for shutdown

    venkata sathuluri Newbie

      I want to get event when jboss is called for shutdown.When i was walking through code i was not able to understand ..how to get event when it is about to shutdown...can anyone help me in understanding...whether it is possible to get event....if not please help me how to implement Shutdown hook..i.e to get event when we are shutting down Jboss..

        • 1. Re: To get Event when Jboss is called for shutdown
          Ales Justin Master

          You can provide your own impl of the Server interface.
          e.g. extend the current ServerImpl and override shutdown method to hook in your behavior.
          See ServerLoader usage in Main and ServerImpl for more details.

          • 2. Re: To get Event when Jboss is called for shutdown
            Ales Justin Master

            Or, there is already a nice hook provided for you.
            In the form of Bootstrap interface - see AbstractServerImpl.

             // Do the bootstraps in reverse order
             for (Bootstrap bootstrap : startedBootstraps)
             {
             Thread.currentThread().setContextClassLoader(bootstrap.getClass().getClassLoader());
             try
             {
             bootstrap.shutdown(this);
             }
             catch (Throwable t)
             {
             log.warn("Error shutting down bootstrap: " + bootstrap, t);
             }
             }
            

            Simply implement your behavior in some Bootstrap impl, and add this bean to bootstrap-beans.xml.
            It will get automatically picked up by ServerImpl, and added to the list of all bootstraps.



            • 3. Re: To get Event when Jboss is called for shutdown
              Ales Justin Master

               

              "svsubramanyam007" wrote:
              I want to get event when jboss is called for shutdown.When i was walking through code i was not able to understand ..how to get event when it is about to shutdown...can anyone help me in understanding...whether it is possible to get event.

              What's there to understand, it's a simple event/listener pattern:
               // Send a notification that server stop is initiated
               Notification msg = new Notification(STOP_NOTIFICATION_TYPE, this, 2);
               sendNotification(msg);
              
               List currentList;
               synchronized (lock) {
               currentList = listenerList;
               }
              
               final int size = currentList.size();
               for (int i = 0; i < size; i++) {
               ListenerInfo li = (ListenerInfo) currentList.get(i);
              
               if (li.filter == null
               || li.filter.isNotificationEnabled(notification)) {
               try {
               this.handleNotification(li.listener, notification,
               li.handback);
               } catch (Exception e) {
               trace("sendNotification",
               "exception from listener: " + e);
               }
               }
               }