You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jf...@apache.org on 2003/09/27 18:49:13 UTC

cvs commit: jakarta-commons/daemon/src/native/unix/native java.c java.h jsvc-unix.c

jfclere     2003/09/27 09:49:13

  Modified:    daemon/src/java/org/apache/commons/daemon/support
                        DaemonLoader.java
               daemon/src/native/unix/native java.c java.h jsvc-unix.c
  Log:
  Get the destroy method called... Before exiting the JVM.
  
  Revision  Changes    Path
  1.3       +19 -1     jakarta-commons/daemon/src/java/org/apache/commons/daemon/support/DaemonLoader.java
  
  Index: DaemonLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/daemon/src/java/org/apache/commons/daemon/support/DaemonLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DaemonLoader.java	26 Sep 2003 21:09:20 -0000	1.2
  +++ DaemonLoader.java	27 Sep 2003 16:49:13 -0000	1.3
  @@ -241,6 +241,24 @@
               stop.invoke(daemon,arg);
   
               /* Run garbage collector */
  +            System.gc();
  +
  +        } catch (Throwable t) {
  +            /* In case we encounter ANY error, we dump the stack trace and
  +               return false (load, start and stop won't be called). */
  +            t.printStackTrace(System.err);
  +            return(false);
  +        }
  +        return(true);
  +    }
  +
  +    public static boolean destroy() {
  +        try {
  +            /* Attempt to stop the daemon */
  +            Object arg[] = null;
  +            destroy.invoke(daemon,arg);
  +
  +            /* Run garbage collector */
               daemon=null;
               controller=null;
               System.gc();
  
  
  
  1.2       +26 -2     jakarta-commons/daemon/src/native/unix/native/java.c
  
  Index: java.c
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/daemon/src/native/unix/native/java.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- java.c	4 Sep 2003 23:28:20 -0000	1.1
  +++ java.c	27 Sep 2003 16:49:13 -0000	1.2
  @@ -252,7 +252,7 @@
   }
   
   /* Destroy the Java VM */
  -bool java_destroy(int exit) {
  +bool JVM_destroy(int exit) {
       jclass system=NULL;
       jmethodID method;
       char System[]="java/lang/System";
  @@ -453,3 +453,27 @@
       return(true);
   }
   
  +/* Call the destroy method in our daemon loader */
  +bool java_destroy(void) {
  +    jmethodID method;
  +    jboolean ret;
  +    char destroy[]="destroy";
  +    char destroyparams[]="()Z";
  +
  +    jsvc_xlate_to_ascii(destroy);
  +    jsvc_xlate_to_ascii(destroyparams); 
  +    method=(*env)->GetStaticMethodID(env,cls,destroy,destroyparams);
  +    if (method==NULL) {
  +        log_error("Cannot found Daemon Loader \"destroy\" entry point");
  +        return(false);
  +    }
  +
  +    ret=(*env)->CallStaticBooleanMethod(env,cls,method);
  +    if (ret==FALSE) {
  +        log_error("Cannot destroy daemon");
  +        return(false);
  +    }
  +
  +    log_debug("Daemon destroyed successfully");
  +    return(true);
  +}
  
  
  
  1.2       +3 -2      jakarta-commons/daemon/src/native/unix/native/java.h
  
  Index: java.h
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/daemon/src/native/unix/native/java.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- java.h	4 Sep 2003 23:28:20 -0000	1.1
  +++ java.h	27 Sep 2003 16:49:13 -0000	1.2
  @@ -61,9 +61,10 @@
   
   char *java_library(arg_data *args, home_data *data);
   bool java_init(arg_data *args, home_data *data);
  -bool java_destroy(int exit);
  +bool java_destroy(void);
   bool java_load(arg_data *args);
   bool java_start(void);
   bool java_stop(void);
   bool java_version(void);
   bool java_check(arg_data *args);
  +bool JVM_destroy(int exit);
  
  
  
  1.7       +6 -3      jakarta-commons/daemon/src/native/unix/native/jsvc-unix.c
  
  Index: jsvc-unix.c
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/daemon/src/native/unix/native/jsvc-unix.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- jsvc-unix.c	26 Sep 2003 20:52:12 -0000	1.6
  +++ jsvc-unix.c	27 Sep 2003 16:49:13 -0000	1.7
  @@ -356,14 +356,17 @@
       while (!stopping) sleep(60); /* pause() not threadsafe */
       log_debug("Shutdown or reload requested: exiting");
   
  -    /* Start the service */
  +    /* Stop the service */
       if (java_stop()!=true) return(6);
   
       if (doreload==true) ret=123;
       else ret=0;
   
  +    /* Destroy the service */
  +    java_destroy();
  +
       /* Destroy the Java VM */
  -    if (java_destroy(ret)!=true) return(7);
  +    if (JVM_destroy(ret)!=true) return(7);
   
       return(ret);
   }