List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:October 31 2007 3:05pm
Subject:Rev 227: Removed directors based callback. Implemented a new callback mechanism by hand. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connector...
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge

------------------------------------------------------------
revno: 227
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Wed 2007-10-31 15:04:37 +0000
message:
  Removed directors based callback. Implemented a new callback mechanism by hand. 
renamed:
  java/com/mysql/cluster/ndbj/INdbCallable.java =>
java/com/mysql/cluster/ndbj/BaseCallback.java
indbcallable.java-20070913212805-mw0t23qijtyjad85-1
modified:
  java/build.xml                 build.xml-20070521233115-yg3ylf2k3vuzr27o-1
  java/com/mysql/cluster/ndbj/NdbTransaction.java
ndbtransaction.java-20070517181935-98huwjarzuh25b30-27
  java/ndbj.i                    ndbj.i-20070913223244-5938mztpztyn9sry-1
  swig/NdbTransaction.i          ndbtransaction.i-20070227184716-ecjyhh3jgvmye4de-7
  swig/ndbglobals.i              globals.i-20070228021421-qkr4cbpxymyqdrf3-7
  java/com/mysql/cluster/ndbj/BaseCallback.java
indbcallable.java-20070913212805-mw0t23qijtyjad85-1
=== renamed file 'java/com/mysql/cluster/ndbj/INdbCallable.java' =>
'java/com/mysql/cluster/ndbj/BaseCallback.java'
--- a/java/com/mysql/cluster/ndbj/INdbCallable.java	2007-09-30 02:06:41 +0000
+++ b/java/com/mysql/cluster/ndbj/BaseCallback.java	2007-10-31 15:04:37 +0000
@@ -1,8 +1,41 @@
 package com.mysql.cluster.ndbj;
 
-
-public interface INdbCallable { 
-
-  void callback(int result, NdbTransaction myTrans);
-
+import com.mysql.cluster.ndbj.ndbjJNI;
+
+public class BaseCallback { 
+
+  private long create_time;
+  private long start_time;
+  private long end_time;
+
+  public BaseCallback() { 
+    create_time = 0;
+    start_time = 0;
+    end_time = 0;
+  }
+
+  protected final void jni_call_callback(int result, long transPtr, long create_time) {
+    this.create_time = create_time;
+    this.start_time = this.getMicroTime();
+    this.callback(result,new NdbTransactionImpl(transPtr,false));
+    this.end_time = this.getMicroTime();
+  };
+
+  public void callback(int result, NdbTransaction myTrans) {}
+
+  public final long getMicroTime() { 
+    return ndbjJNI.getMicroTime(); 
+  }
+
+  public final long getElapsedTime() { 
+    return this.getMicroTime() - this.create_time; 
+  }
+
+  public final long getExecuteTime() { 
+    return this.end_time - this.create_time; 
+  }
+
+  public final long getCallbackTime() { 
+    return this.end_time - this.start_time; 
+  } 
 };

=== modified file 'java/build.xml'
--- a/java/build.xml	2007-10-29 15:26:44 +0000
+++ b/java/build.xml	2007-10-31 15:04:37 +0000
@@ -48,7 +48,6 @@
       <fileset dir="com/mysql/cluster/mgmj" includes="NdbMgmSeverity.java" />
       <fileset dir="com/mysql/cluster/ndbj" includes="NdbColumn.java" />
       <fileset dir="com/mysql/cluster/ndbj" includes="AbortOption.java" />
-      <fileset dir="com/mysql/cluster/ndbj" includes="BaseCallback.java" />
       <fileset dir="com/mysql/cluster/ndbj" includes="ExecType.java" />
       <fileset dir="com/mysql/cluster/ndbj" includes="NdbDictionary.java" />
       <fileset dir="com/mysql/cluster/ndbj" includes="NdbEvent.java" />

=== modified file 'java/com/mysql/cluster/ndbj/NdbTransaction.java'
--- a/java/com/mysql/cluster/ndbj/NdbTransaction.java	2007-10-05 18:18:53 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbTransaction.java	2007-10-31 15:04:37 +0000
@@ -147,9 +147,6 @@
 	public int execute(ExecType execType, AbortOption abortOption) throws NdbApiException;
 	public int execute(ExecType execType) throws NdbApiException;
 
-	public void executeAsynchPrepare(ExecType execType, BaseCallback cb,
-			AbortOption abortOption);
-	public void executeAsynchPrepare(ExecType execType, BaseCallback cb);
 	/**
 	 * Creates a NdbOperationRef (primary key operation) and adds it to the transaction.
 	 * @param tableName name of the schema
@@ -257,17 +254,17 @@
 	 * @param cb
 	 * @param abortOption
 	 * @see NdbTransactionRef#executeAsynchPrepare(ExecTypeRef,
-	 *      INdbCallable,
+	 *      BaseCallback,
 	 *      AbortOptionRef)
 	 */
-	public void executeAsynchPrepare(ExecType execType, INdbCallable cb, AbortOption
abortOption);
+	public void executeAsynchPrepare(ExecType execType, BaseCallback cb, AbortOption
abortOption);
 	/**
 	 * @param execType
 	 * @param cb
 	 * @see NdbTransactionRef#executeAsynchPrepare(ExecTypeRef,
-	 *      INdbCallable)
+	 *      BaseCallback)
 	 */
-	public void executeAsynchPrepare(ExecType execType, INdbCallable cb);
+	public void executeAsynchPrepare(ExecType execType, BaseCallback cb);
 	public NdbOperationImpl getNdbOperation(NdbTable aTable) throws NdbApiException;
 	public NdbIndexScanOperationImpl getNdbIndexScanOperation(NdbIndex anIndex, NdbTable
aTable) throws NdbApiException;
 	public NdbIndexOperationImpl getNdbIndexOperation(NdbIndex anIndex, NdbTable aTable)
throws NdbApiException;

=== modified file 'java/ndbj.i'
--- a/java/ndbj.i	2007-10-30 18:04:07 +0000
+++ b/java/ndbj.i	2007-10-31 15:04:37 +0000
@@ -17,7 +17,7 @@
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
-%module(directors="1") ndbj
+%module ndbj
 
 
 %rename NdbBlob NdbBlobImpl;
@@ -37,68 +37,47 @@
 %include "various.i"
 %include "enums.swg"
 
-%include "config.h"
 
 %{
 #include <stdio.h>
-#include "config.h"
 
 typedef struct
 asynch_callback_t
 {  
   JNIEnv *env; 
-  jobject obj; 
-};
-
-typedef struct
-event_callback_t
-{  
-  JNIEnv *env; 
-  jobject obj; 
-};
-
-
-static void JavaCallBack(int result,
+  jobject obj;
+  long long create_time;
+};
+
+
+
+static void theCallBack(int result,
                      NdbTransaction *trans,
                      void *aObject)
 {
 
   asynch_callback_t * callback_data = (asynch_callback_t *)aObject;
 
-  JNIEnv *env = callback_data->env; 
-
-  jclass callablecls = env->GetObjectClass((callback_data->obj));
-
-  jmethodID mid = env->GetMethodID(callablecls, "callback", "(ILNdbTransaction;)V");
-  if (mid == NULL) { 
-    jclass clazz = env->FindClass("java/lang/RuntimeException");
-    env->ThrowNew(clazz,"No callback method!");
-  }
-
-  env->CallVoidMethod(callback_data->obj,mid,(jlong)result,trans);
-
-}
-
-static void EventCallBack(NdbEventOperation *theOp,
-                     Ndb *theNdb,
-                     void *aObject)
-{
-
-  event_callback_t * callback_data = (event_callback_t *)aObject;
-
-  JNIEnv *env = callback_data->env; 
-
-  jclass callablecls = env->GetObjectClass((callback_data->obj));
-
-  jmethodID mid = env->GetMethodID(callablecls, "callback", "(ILNdb;)V");
-  if (mid == NULL) { 
-    jclass clazz = env->FindClass("java/lang/RuntimeException");
-    env->ThrowNew(clazz,"No callback method!");
-  }
-
-  env->CallVoidMethod(callback_data->obj,mid,theOp,theNdb);
-
-}
+  JNIEnv *jenv = callback_data->env;
+//  printf("Running callback: env == %p .. callback_data->obj ==
%p\n",jenv,callback_data->obj); 
+
+  jclass callablecls = jenv->GetObjectClass((callback_data->obj));
+
+  // printf("\tcallablecls: %p\n",callablecls);
+  jmethodID mid = jenv->GetMethodID(callablecls, "jni_call_callback","(IJJ)V");
+
+  //jmethodID mid = jenv->GetMethodID(callablecls, "callback",
"(ILNdbTransaction;)V");
+  //printf("\tmid: %p\n",mid);
+  if ((mid == NULL) || (mid == 0)) { 
+    jenv->DeleteGlobalRef(callback_data->obj);
+    jclass clazz = jenv->FindClass("java/lang/RuntimeException");
+    jenv->ThrowNew(clazz,"No callback method!");
+  }
+
+ 
jenv->CallVoidMethod(callback_data->obj,mid,(jlong)result,trans,callback_data->create_time);
+  jenv->DeleteGlobalRef(callback_data->obj);
+}
+
 
 #define NDB_exception(excp, msg) { ndb_throw_exception(jenv, #excp,msg);  } 
 #define NDB_exception_err(excp, msg, err) { ndb_throw_exception(jenv, #excp,msg, err);  }

@@ -145,17 +124,17 @@
 
 %typemap(in) asynch_callback_t * cb
 %{ 
-  asynch_callback_t * callback_data; 
-    callback_data = new asynch_callback_t;
-    callback_data->env = jenv; 
-    callback_data->obj = $input;
-    
-    $1 = callback_data;
+    $1 = new asynch_callback_t;
+    $1->env = jenv; 
+    $1->obj = jenv->NewGlobalRef($input);
+    $1->create_time = 0;
+//    jclass callablecls = jenv->GetObjectClass(($1->obj));    
+//    printf("Registering callback: env==%p .. obj==%p ..
callbackcls==%p\n",jenv,$1->obj,callablecls);
  %}
 
 %typemap(in) event_callback_t * cb
 %{ 
-  event_callback_t * callback_data; 
+  
     callback_data = new event_callback_t;
     callback_data->env = jenv; 
     callback_data->obj = $input;
@@ -165,14 +144,9 @@
 
 %typemap(jni) asynch_callback_t * "jobject" 
 %typemap(jtype) asynch_callback_t * "Object"
-%typemap(jstype) asynch_callback_t * "INdbCallable"
+%typemap(jstype) asynch_callback_t * "BaseCallback"
 %typemap(javain) asynch_callback_t * "(Object)$javainput"
 
-%typemap(jni) event_callback_t * "jobject" 
-%typemap(jtype) event_callback_t * "Object"
-%typemap(jstype) event_callback_t * "INdbEventCallable"
-%typemap(javain) event_callback_t * "(Object)$javainput"
-
 %typemap(jtype) voidint "void";
 %typemap(jstype) voidint "void";
 %typemap(javaout) voidint { 
@@ -440,10 +414,6 @@
 
 %extend NdbTransaction { 
   
-  void executeAsynchPrepare(ExecType execType, asynch_callback_t * cb, AbortOption      
abortOption = AbortOnError){ 
-    self->executeAsynchPrepare(execType,JavaCallBack,(void *)cb, abortOption); 
-    
-  }
 };
 
 %typemap(javainterfaces) NdbOperation "NdbOperation,NdbInterpretedOperation";

=== modified file 'swig/NdbTransaction.i'
--- a/swig/NdbTransaction.i	2007-10-30 18:04:07 +0000
+++ b/swig/NdbTransaction.i	2007-10-31 15:04:37 +0000
@@ -133,15 +133,12 @@
     }
 */
     %ndbnoexception
-    void executeAsynchPrepare(ExecType execType,
-			      BaseCallback * cb,
-			      AbortOption abortOption = AbortOnError) {
-#ifdef DEBUG_ASYNC_TIMES
-    cb->setCreateTime();
-#endif
-      self->executeAsynchPrepare(execType,theNdbCallback,(void *)cb,abortOption);
-    };
 
+       void executeAsynchPrepare(ExecType execType, asynch_callback_t * cb, AbortOption  
    abortOption = AbortOnError){ 
+    cb->create_time=getMicroTime();
+    self->executeAsynchPrepare(execType,theCallBack,(void *)cb, abortOption); 
+    
+  }
 
     %ndbexception("NdbApiException") { 
       $action

=== modified file 'swig/ndbglobals.i'
--- a/swig/ndbglobals.i	2007-10-30 19:19:27 +0000
+++ b/swig/ndbglobals.i	2007-10-31 15:04:37 +0000
@@ -18,6 +18,7 @@
 */
 
 %include "globals.i"
+%include "config.h"
 
 %{
 #include <my_global.h>
@@ -25,10 +26,20 @@
 
 #include <mysql.h>
 #include <NdbApi.hpp> 
+
+#undef PACKAGE
+#undef PACKAGE_NAME
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
+#undef PACKAGE_VERSION
+#undef VERSION
+
+#include "config.h"
+
 //#include <m_ctype.h>
 
 
-  long long getTimeMicros() 
+  long long getMicroTime() 
   {
     struct timeval tTime;
     gettimeofday(&tTime, 0);
@@ -36,52 +47,6 @@
     return microSeconds;
   }
 
-  class BaseCallback { 
-
-
-  public:
-    long long createTime;
-
-    virtual ~BaseCallback() {};
-    virtual void callback(int res, NdbTransaction * trans) { 
-      printf("In BaseCallback::callback. Return Value: %d. Transaction: %p\n",res,trans);
-    }
-
-    void setCreateTime() { 
-      createTime = getTimeMicros();
-    }
-    long long getElapsedTime() { 
-      return getTimeMicros()-createTime; 
-    }
-
-  };
-
-  void theNdbCallback(int ret, NdbTransaction * trans, void * anyObject) {
-    BaseCallback * cb = (BaseCallback *)anyObject;
-    cb->callback(ret, trans);
-    #ifdef DEBUG_ASYNC_TIMES
-    long long elapsed = cb->getElapsedTime();
-    printf("Callback %p took %llu microseconds\n",cb,elapsed);
-    #endif
-
-  }
-
-  class BaseEventCallback {
-
-    public: 
-      virtual ~BaseEventCallback() {};
-      virtual void callback(NdbEventOperation *theOp, Ndb *theNdb) {
-        printf("In BaseEventCallback::callback.\n\tOperation: %p\n\tNdb: %p\n",
-               theOp,theNdb);
-    }
-  };
-
-
-  void theNdbEventCallback(NdbEventOperation * theOp, Ndb * theNdb, void * anyObject) { 
-    BaseEventCallback * cb = (BaseEventCallback *)anyObject;
-    cb->callback(theOp,theNdb);
-  }
-
 
 
 typedef int voidint; 
@@ -99,7 +64,7 @@
 } BYTES; 
 %}
 
-long long getTimeMicros();
+long long getMicroTime();
 /*
 typedef char my_bool;
 enum enum_mysql_timestamp_type
@@ -151,22 +116,3 @@
 typedef Uint32 NdbTimestamp;
 
 
-%feature("director") BaseCallback;
-
-class BaseCallback {
-  virtual ~BaseCallback() {};
-  public:
-  virtual void callback(int res, NdbTransaction * trans);
-  virtual long long getElapsedTime();
-  
-};
-
-%feature("director") BaseEventCallback;
-
-class BaseEventCallback {
-
-  public:
-    virtual ~BaseEventCallback() {};
-    virtual void callback(NdbEventOperation *theOp, Ndb *theNdb);
-};
-

Thread
Rev 227: Removed directors based callback. Implemented a new callback mechanism by hand. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connector...Monty Taylor31 Oct