You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/10/17 08:49:28 UTC

svn commit: r1399113 - in /incubator/etch/trunk/binding-cpp: compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/ runtime/include/support/ runtime/include/transport/ runtime/src/main/support/ runtime/src/main/transport/

Author: veithm
Date: Wed Oct 17 06:49:27 2012
New Revision: 1399113

URL: http://svn.apache.org/viewvc?rev=1399113&view=rev
Log:
ETCH-243 Fixed bug in void function calls

Changed Connection Checker in order to avoid Race Condition
Enabling recreation of runtime if it has been destroyed before

Change-Id: Ia7d16052af22a5f7a4dfa2ee0708506222add095

Modified:
    incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
    incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm
    incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm
    incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h
    incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h
    incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubBase.h
    incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h
    incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h
    incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchQueuedPool.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp

Modified: incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm (original)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm Wed Oct 17 06:49:27 2012
@@ -55,14 +55,21 @@ status_t $clname::$n.name()AsyncResultRe
       // TODO set result to a runtime exception 
       return ETCH_OK;
     }
-    if(result->isInstanceOf(EtchException::TYPE())) {
-      setException(result);
-    }
+    
+    //result is NULL if it was a void call and no exception has been set
+    if (result.get() != NULL) {
+      if(result->isInstanceOf(EtchException::TYPE())) {
+        setException(result);
+      }
 #if($n.hasReturn())
-    else {
-      setResult(result);
-    }
+      else {
+        setResult(result);
+      }
 #end
+    } else {
+      setMailboxStatus();
+    }
+
 
   }
 

Modified: incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm (original)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm Wed Oct 17 06:49:27 2012
@@ -46,10 +46,6 @@ status_t $vf::Etch${intf.name()}RuntimeL
     //the runtime is closed and is removed
     $vf::SRuntimes.removeAt(index);
   }
-  if ($vf::SRuntimes.isEmpty()) {
-    //clean up all static members
-    $vf::DestroyValueFactory();
-  }
   return ETCH_OK;
 }
 
@@ -148,13 +144,13 @@ class ImportExportHelper$n.vname( $helpe
 
 //Static Variable Initialization
 EtchTypeMap* $vf::types() {
-static EtchTypeMap* ret = new EtchTypeMap();
-return ret;
+static EtchTypeMap ret;
+return &ret;
 }
 
 EtchClass2TypeMap* $vf::class2type() {
-static EtchClass2TypeMap* ret = new EtchClass2TypeMap();
-return ret;
+static EtchClass2TypeMap ret;
+return &ret;
 }
 
 #foreach ( $n in $intf.iterator() )
@@ -399,12 +395,4 @@ status_t $vf::InitValueFactory(EtchRunti
   class2type()->lock();
   
   return ETCH_OK;
-}
-
-status_t $vf::DestroyValueFactory()
-{
-  $vf::types()->clear();
-  delete $vf::types();
-  delete $vf::class2type();
-  return ETCH_OK;
 }
\ No newline at end of file

Modified: incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm (original)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm Wed Oct 17 06:49:27 2012
@@ -105,15 +105,13 @@ namespace $namespace {
        */
       status_t onRuntimeChanged(EtchRuntime* runtime);
     };
-  
+
     friend class ${i}Helper;
     friend class Etch${i}RuntimeListener;
     static status_t InitValueFactory(EtchRuntime* runtime);
-    static status_t DestroyValueFactory();
     static capu::Mutex SRuntimesMutex;
     static capu::List<capu::uint64_t> SRuntimes;
     static Etch${i}RuntimeListener S${i}RuntimeListener;
-    
   };
 }
 #endif

Modified: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResult.h Wed Oct 17 06:49:27 2012
@@ -50,8 +50,6 @@ public:
   capu::bool_t hasResult() {
     mMutex.lock();
     while(!mHasMailboxStatus) {
-      // TODO wait
-      break;
       mCond.wait(&mMutex);
     }
     mMutex.unlock();
@@ -64,11 +62,8 @@ public:
   status_t setResult(capu::SmartPointer<T> result) {
     mResult = result;
     mHasResult = true;
-    
-    mMutex.lock();
-    mHasMailboxStatus = true;
-    mCond.signal();
-    mMutex.unlock();
+
+    setMailboxStatus();
     return ETCH_OK;
   }
 

Modified: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchAsyncResultNone.h Wed Oct 17 06:49:27 2012
@@ -65,6 +65,11 @@ public:
   virtual status_t mailboxStatus(EtchMailbox* mb, EtchObject* state, capu::bool_t closed) {return ETCH_OK;};
 
 protected:
+  /**
+   * Sets the mailbox status to true and signals waiting threads
+   */
+  void setMailboxStatus();
+
   EtchRuntime* mRuntime;
   EtchMailbox* mMailbox;
   capu::Mutex mMutex;

Modified: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubBase.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubBase.h?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubBase.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubBase.h Wed Oct 17 06:49:27 2012
@@ -149,20 +149,30 @@ status_t EtchStubBase<T>::sessionMessage
   switch (type->getAsyncMode()) {
     case QUEUED:
       runnable = new EtchStubPoolRunnable<T>(this, sender, msg, helper);
+      //TODO: inject runtime and enable logging
+      //CAPU_LOG_TRACE(mRuntime->getLogger(), "EtchStubBase", "Adding stub pool runnable to queued pool");
       res = mQueuedPool->add(runnable);
-      if (res != ETCH_OK)
+      if (res != ETCH_OK) {
+        //CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchStubBase", "Error while adding runnable to pool");
         sessionNotify(NULL); //TODO Exception Handling
+      }
       return res;
     case FREE:
       runnable = new EtchStubPoolRunnable<T>(this, sender, msg, helper);
+      //CAPU_LOG_TRACE(mRuntime->getLogger(), "EtchStubBase", "Adding stub pool runnable to free pool");
       res = mFreePool->add(runnable);
-      if (res != ETCH_OK)
+      if (res != ETCH_OK) {
+        //CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchStubBase", "Error while adding runnable to pool");
         sessionNotify(NULL); //TODO Exception Handling
+      }
       return res;
     case NONE:
+      //CAPU_LOG_TRACE(mRuntime->getLogger(), "EtchStubBase", "Executing function in receiver thread");
       res = helper->run(this, mSvc, mObj, sender, msg);
-      if (res != ETCH_OK)
+      if (res != ETCH_OK) {
+        //CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchStubBase", "Error while executing function");
         sessionNotify(NULL); //TODO Exception Handling
+      }
       return res;
     default:
       //  throw new IllegalArgumentException("unknown async mode "+type.getAsyncMode());

Modified: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h Wed Oct 17 06:49:27 2012
@@ -65,6 +65,13 @@ public:
   virtual capu::bool_t isStarted() = 0;
 
   /**
+   * Check whether the receiving thread is terminated or not
+   * @return true if it is terminated
+   *         false otherwise
+   */
+  virtual capu::bool_t isTerminated() = 0;
+
+  /**
    * Main function that will be executed by thread
    * @param param parameter that will be passed to the thread
    */
@@ -125,6 +132,7 @@ protected:
   S *mSession;
   capu::Thread *mThread;
   capu::bool_t mIsStarted;
+  capu::bool_t mIsTerminated;
   static capu::Mutex mMutex;
   static capu::Mutex mMutexConnection;
   EtchMonitor mStatus;

Modified: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h Wed Oct 17 06:49:27 2012
@@ -92,6 +92,11 @@ public:
    * @see EtchConnection
    */
   capu::bool_t isStarted();
+
+  /**
+   * @see EtchConnection
+   */
+  capu::bool_t isTerminated();
 
   /**
    * @see capu::thread

Modified: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h Wed Oct 17 06:49:27 2012
@@ -55,8 +55,16 @@ public:
    */
   virtual ~EtchTcpListener();
 
+  /**
+   * @see EtchConnection
+   */
   virtual capu::bool_t isStarted();
 
+  /**
+   * @see EtchConnection
+   */
+  virtual capu::bool_t isTerminated();
+
   virtual status_t close();
 
   /**

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp Wed Oct 17 06:49:27 2012
@@ -21,7 +21,7 @@
 #define MAILBOX_NOTIFY_TIMEOUT 2000
 
 EtchAsyncResultNone::EtchAsyncResultNone(EtchRuntime* runtime, EtchMailbox* mailbox)
-  : mRuntime(runtime), mMailbox(mailbox), mHasMailboxStatus(false), mHasException(false) {
+  : mRuntime(runtime), mMailbox(mailbox), mHasMailboxStatus(false), mHasException(false), mException(NULL) {
     if(mailbox != NULL) {
       mMailbox->registerNotify(this, NULL, MAILBOX_NOTIFY_TIMEOUT);
     }
@@ -31,13 +31,14 @@ EtchAsyncResultNone::EtchAsyncResultNone
 EtchAsyncResultNone::~EtchAsyncResultNone() {
   if(mMailbox != NULL) {
     mMailbox->unregisterNotify(this);
+    mMailbox->closeDelivery();
     delete mMailbox;
   }
 }
 
 capu::bool_t EtchAsyncResultNone::hasException() {
   mMutex.lock();
-  while(!mHasMailboxStatus) {
+  while(mMailbox != NULL && !mHasMailboxStatus) {
     mCond.wait(&mMutex);
   }
   mMutex.unlock();
@@ -53,7 +54,10 @@ capu::SmartPointer<EtchException> EtchAs
 void EtchAsyncResultNone::setException(capu::SmartPointer<EtchException> exception) {
   mException = exception;
   mHasException = true;
+  setMailboxStatus();
+}
 
+void EtchAsyncResultNone::setMailboxStatus() {
   mMutex.lock();
   mHasMailboxStatus = true;
   mCond.signal();

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchQueuedPool.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchQueuedPool.cpp?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchQueuedPool.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchQueuedPool.cpp Wed Oct 17 06:49:27 2012
@@ -44,7 +44,7 @@ public:
   void run() {
     if(mRunnable.get() != NULL) {
       if(ETCH_OK != mRunnable->run()) {
-        // Log exception
+        //TODO: Log exception
         if(mRunnable->hasException()) {
           capu::SmartPointer<EtchException> exception;
           mRunnable->getException(&exception);
@@ -67,7 +67,7 @@ const EtchObjectType* EtchQueuedPool::TY
 EtchQueuedPool::EtchQueuedPool(capu::int32_t size)
 : mSizeMax(size), mIsOpen(true) {
   addObjectType(TYPE());
-  mPool = new capu::ThreadPool(mSizeMax);
+  mPool = new capu::ThreadPool(1);
 }
 
 EtchQueuedPool::~EtchQueuedPool() {
@@ -90,6 +90,7 @@ status_t EtchQueuedPool::add(capu::Smart
   }
 
   EtchQueuedPoolRunnable* pr = new EtchQueuedPoolRunnable(this, runnable);
+  //TODO: check max Size before adding a new Runnable
   capu::status_t status = mPool->add(pr);
   if(status != capu::CAPU_OK) {
     return ETCH_ERROR;

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp Wed Oct 17 06:49:27 2012
@@ -32,6 +32,7 @@ EtchTcpConnection::EtchTcpConnection(Etc
   }
   mThread = NULL;
   mIsStarted = false;
+  mIsTerminated = false;
   mSession = NULL;
   mSocket = socket;
 }
@@ -96,7 +97,7 @@ status_t EtchTcpConnection::openSocket(c
     mMutexConnection.unlock();
     return ETCH_ERROR;
   }
-  // if a reconnect but no retries allowed, then fail.
+  // if a reconnect but retries not allowed, then fail.
   if (reconnect && (mOptions.getReconnectDelay() == 0)) {
     mMutexConnection.unlock();
     return ETCH_ERROR;
@@ -255,6 +256,10 @@ capu::bool_t EtchTcpConnection::isStarte
   return mIsStarted;
 }
 
+capu::bool_t EtchTcpConnection::isTerminated() {
+  return mIsTerminated;
+}
+
 void EtchTcpConnection::run() {
 
   status_t status;
@@ -270,6 +275,7 @@ void EtchTcpConnection::run() {
 
     status = setupSocket();
     if (status != ETCH_OK) {
+      CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => Socket has not been successfully opened", mHost.c_str(), mPort);
       close();
       break;
     }
@@ -283,21 +289,26 @@ void EtchTcpConnection::run() {
     close();
     first = false;
   }
+   mIsTerminated = true;
 }
 
 status_t EtchTcpConnection::setupSocket() {
   if (mOptions.getBufferSize() != 0) {
     if (mSocket->setBufferSize(mOptions.getBufferSize()) != ETCH_OK) {
+      CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => setupSocket: Error while setting buffer size", mHost.c_str(), mPort);
       return ETCH_ERROR;
     }
   }
   if (mSocket->setKeepAlive((mOptions.getKeepAlive() != 0)) != ETCH_OK) {
+    CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => setupSocket: Error while setting keep alive", mHost.c_str(), mPort);
     return ETCH_ERROR;
   }
   if (mSocket->setLingerOption((mOptions.getLingerTime() >= 0), mOptions.getLingerTime()) != ETCH_OK) {
+    CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => setupSocket: Error while setting linger time", mHost.c_str(), mPort);
     return ETCH_ERROR;
   }
   if (mSocket->setNoDelay((mOptions.getNoDelay() != 0)) != ETCH_OK) {
+    CAPU_LOG_ERROR(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => setupSocket: Error while setting delay", mHost.c_str(), mPort);
     return ETCH_ERROR;
   }
   CAPU_LOG_TRACE(mRuntime->getLogger(), "EtchTcpConnection", "%s : %d => Settings for socket has been successfully configured", mHost.c_str(), mPort);

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp Wed Oct 17 06:49:27 2012
@@ -65,6 +65,7 @@ EtchTcpListener::EtchTcpListener(EtchURL
   }
   mSession = NULL;
   mIsStarted = false;
+  mIsTerminated = false;
   mThread = NULL;
   mSocket = NULL;
   mConnectionCheckerThread = NULL;
@@ -94,6 +95,10 @@ capu::bool_t EtchTcpListener::isStarted(
   return mIsStarted;
 }
 
+capu::bool_t EtchTcpListener::isTerminated() {
+  return mIsTerminated;
+}
+
 status_t EtchTcpListener::close() {
   if (mSocket != NULL) {
     return mSocket->close();
@@ -276,6 +281,7 @@ void EtchTcpListener::run() {
     first = false;
   }
   mIsStarted = false;
+  mIsTerminated = true;
 }
 
 status_t EtchTcpListener::setupSocket() {

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp?rev=1399113&r1=1399112&r2=1399113&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpTransportFactory.cpp Wed Oct 17 06:49:27 2012
@@ -176,7 +176,7 @@ status_t EtchTcpTransportFactory::MySess
       if (res == ETCH_OK) {
         EtchTcpConnection* con = (EtchTcpConnection*) stack->getTransportData();
         if (con != NULL) {
-          if (!con->isStarted()) {
+          if (con->isTerminated()) {
             //delete all instances for this stack
             delete stack;
             //remote stack from list