commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r923123 - in /commons/proper/daemon/trunk: ./ src/java/org/apache/commons/daemon/ src/java/org/apache/commons/daemon/support/ src/native/unix/native/
Date Mon, 15 Mar 2010 09:20:01 GMT
Author: mturk
Date: Mon Mar 15 09:20:00 2010
New Revision: 923123

URL: http://svn.apache.org/viewvc?rev=923123&view=rev
Log:
Fix DAEMON-128 by implementing failed native callback. It behaves like shutdown, but logs
provided message/exception to the native error log

Modified:
    commons/proper/daemon/trunk/RELEASE-NOTES.txt
    commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonContext.java
    commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonController.java
    commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonListener.java
    commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonPermission.java
    commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/support/DaemonLoader.java
    commons/proper/daemon/trunk/src/native/unix/native/java.c

Modified: commons/proper/daemon/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/RELEASE-NOTES.txt?rev=923123&r1=923122&r2=923123&view=diff
==============================================================================
--- commons/proper/daemon/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/daemon/trunk/RELEASE-NOTES.txt Mon Mar 15 09:20:00 2010
@@ -35,7 +35,7 @@ NEW FEATURES:
 
 BUG FIXES:
 
-1.0.3: DAEMON-108, DAEMON-139
+1.0.3: DAEMON-108, DAEMON-128, DAEMON-139
 
 1.0.2: DAEMON-16, DAEMON-31, DAEMON-40, DAEMON-45, DAEMON-49, DAEMON-60,
        DAEMON-84, DAEMON-90, DAEMON-91, DAEMON-92, DAEMON-93, DAEMON-94,

Modified: commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonContext.java
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonContext.java?rev=923123&r1=923122&r2=923123&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonContext.java (original)
+++ commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonContext.java Mon
Mar 15 09:20:00 2010
@@ -23,7 +23,7 @@ package org.apache.commons.daemon;
  * communicate with the Daemon container.
  *
  * @author Pier Fumagalli
- * @version 1.0 <i>(CVS $Revision$)</i>
+ * @version 1.0 <i>(SVN $Revision$)</i>
  */
 public interface DaemonContext
 {

Modified: commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonController.java
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonController.java?rev=923123&r1=923122&r2=923123&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonController.java (original)
+++ commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonController.java Mon
Mar 15 09:20:00 2010
@@ -21,45 +21,46 @@ package org.apache.commons.daemon;
 /**
  *
  * @author Pier Fumagalli
- * @version 1.0 <i>(CVS $Revision$)</i>
+ * @version 1.0 <i>(SVN $Revision$)</i>
  */
 public interface DaemonController
 {
 
     /**
-     *
+     * Shutdown the daemon.     
      */
     public void shutdown()
         throws IllegalStateException;
 
     /**
-     *
+     * Reload daemon
      */
     public void reload()
         throws IllegalStateException;
 
     /**
-     *
+     * Shudown daemon and log failed message.
      */
     public void fail()
         throws IllegalStateException;
 
     /**
-     *
+     * Shudown daemon and log failed message.
      */
     public void fail(String message)
         throws IllegalStateException;
 
     /**
-     *
+     * Shudown daemon and log failed message.
      */
     public void fail(Exception exception)
         throws IllegalStateException;
 
     /**
-     *
+     * Shudown daemon and log failed message.
      */
     public void fail(String message, Exception exception)
         throws IllegalStateException;
 
+}
 

Modified: commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonListener.java
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonListener.java?rev=923123&r1=923122&r2=923123&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonListener.java (original)
+++ commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonListener.java Mon
Mar 15 09:20:00 2010
@@ -19,6 +19,10 @@ package org.apache.commons.daemon;
 
 import java.util.EventListener;
 
+/**
+ * EvenListener type wrapper.
+ * @version 1.0 <i>(SVN $Revision$)</i>
+ */
 public interface DaemonListener extends EventListener
 {
 

Modified: commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonPermission.java
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonPermission.java?rev=923123&r1=923122&r2=923123&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonPermission.java (original)
+++ commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/DaemonPermission.java Mon
Mar 15 09:20:00 2010
@@ -83,7 +83,7 @@ import java.util.StringTokenizer;
  * </p>
  *
  * @author Pier Fumagalli
- * @version 1.0 <i>(CVS $Revision$)</i>
+ * @version 1.0 <i>(SVN $Revision$)</i>
  */
 public final class DaemonPermission extends Permission
 {

Modified: commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/support/DaemonLoader.java
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/support/DaemonLoader.java?rev=923123&r1=923122&r2=923123&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/support/DaemonLoader.java
(original)
+++ commons/proper/daemon/trunk/src/java/org/apache/commons/daemon/support/DaemonLoader.java
Mon Mar 15 09:20:00 2010
@@ -15,8 +15,6 @@
  *  limitations under the License.
  */
 
-/* @version $Id$ */
-
 package org.apache.commons.daemon.support;
 
 import org.apache.commons.daemon.DaemonContext;
@@ -24,6 +22,11 @@ import org.apache.commons.daemon.DaemonC
 
 import java.lang.reflect.Method;
 
+/*
+ * Used by jsvc for Daemon management.
+ *
+ * @version 1.0 <i>(SVN $Revision$)</i>
+ */
 public final class DaemonLoader
 {
 
@@ -246,6 +249,7 @@ public final class DaemonLoader
     }
 
     private static native void shutdown(boolean reload);
+    private static native void failed(String message);
 
     public static class Controller
         implements DaemonController
@@ -304,21 +308,40 @@ public final class DaemonLoader
         public void fail()
             throws IllegalStateException
         {
+            fail(null, null);
         }
 
         public void fail(String message)
             throws IllegalStateException
         {
+            fail(message, null);
         }
 
         public void fail(Exception exception)
             throws IllegalStateException
         {
+            fail(null, exception);
         }
 
         public void fail(String message, Exception exception)
             throws IllegalStateException
         {
+            synchronized (this) {
+                if (!this.isAvailable()) {
+                    throw new IllegalStateException();
+                }
+                else {
+                    this.setAvailable(false);
+                    String msg = message;
+                    if (exception != null) {
+                        if (msg != null)
+                            msg = msg + ": " + exception.toString();
+                        else
+                            msg = exception.toString();
+                    }
+                    DaemonLoader.failed(msg);
+                }
+            }
         }
 
     }

Modified: commons/proper/daemon/trunk/src/native/unix/native/java.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/java.c?rev=923123&r1=923122&r2=923123&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/unix/native/java.c (original)
+++ commons/proper/daemon/trunk/src/native/unix/native/java.c Mon Mar 15 09:20:00 2010
@@ -40,7 +40,7 @@ static jclass cls  = NULL;
 #define FALSE 0
 #define TRUE !FALSE
 
-static void shutdown(JNIEnv * env, jobject source, jboolean reload)
+static void shutdown(JNIEnv *env, jobject source, jboolean reload)
 {
     log_debug("Shutdown requested (reload is %d)", reload);
     if (reload == TRUE)
@@ -49,6 +49,19 @@ static void shutdown(JNIEnv * env, jobje
         main_shutdown();
 }
 
+static void failed(JNIEnv *env, jobject source, jstring message)
+{
+    if (message) {
+        const char *msg = (*env)->GetStringUTFChars(env, message, NULL);
+        log_error("Failed %s", msg ? msg : "(null)");
+        if (msg)
+            (*env)->ReleaseStringUTFChars(env, message, msg);
+    }
+    else
+        log_error("Failed requested");
+    main_shutdown();
+}
+
 /* Automatically restart when the JVM crashes */
 static void java_abort123(void)
 {
@@ -98,7 +111,7 @@ bool java_init(arg_data *args, home_data
     struct stat sb;
 #endif /* ifdef OS_DARWIN */
     jint(*symb) (JavaVM **, JNIEnv **, JavaVMInitArgs *);
-    JNINativeMethod nativemethod;
+    JNINativeMethod nativemethods[2];
     JavaVMOption *opt = NULL;
     dso_handle libh   = NULL;
     JavaVMInitArgs arg;
@@ -106,8 +119,10 @@ bool java_init(arg_data *args, home_data
     jint ret;
     int x;
     char loaderclass[]    = LOADER;
-    char shutdownclass[]  = "shutdown";
+    char shutdownmethod[] = "shutdown";
     char shutdownparams[] = "(Z)V";
+    char failedmethod[]   = "failed";
+    char failedparams[]   = "(Ljava/lang/String;)V";
 
     /* Decide WHAT virtual machine we need to use */
     libf = java_library(args, data);
@@ -264,12 +279,18 @@ bool java_init(arg_data *args, home_data
 #if defined(HAVE_SABLEVM)
     log_debug("sableVM doesn't support RegisterNatives");
 #else
-    jsvc_xlate_to_ascii(shutdownclass);
-    nativemethod.name = shutdownclass;
+    jsvc_xlate_to_ascii(shutdownmethod);
+    nativemethods[0].name = shutdownmethod;
     jsvc_xlate_to_ascii(shutdownparams);
-    nativemethod.signature = shutdownparams;
-    nativemethod.fnPtr = shutdown;
-    if ((*env)->RegisterNatives(env, cls, &nativemethod, 1) != 0) {
+    nativemethods[0].signature = shutdownparams;
+    nativemethods[0].fnPtr = shutdown;
+    jsvc_xlate_to_ascii(failedmethod);
+    nativemethods[1].name = failedmethod;
+    jsvc_xlate_to_ascii(failedparams);
+    nativemethods[1].signature = failedparams;
+    nativemethods[1].fnPtr = failed;
+
+    if ((*env)->RegisterNatives(env, cls, nativemethods, 2) != 0) {
         log_error("Cannot register native methods");
         return false;
     }



Mime
View raw message