You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by fi...@apache.org on 2012/08/02 17:13:36 UTC
svn commit: r1368517 - in /incubator/etch/trunk/binding-cpp/runtime:
include/common/ include/serialization/ include/support/ src/main/
src/main/serialization/ src/main/support/ src/test/ src/test/support/
Author: fitzner
Date: Thu Aug 2 15:13:36 2012
New Revision: 1368517
URL: http://svn.apache.org/viewvc?rev=1368517&view=rev
Log:
ETCH-141: EtchThreadPools and Implementation of StubBase
- Implementation of ThreadPool Wrappers for ETCH
=> EtchFreePool: n Threads at a time, further Threads are not accepted (not queued)
=> EtchQueuedPool: 1 Thread at a time, Queued to unlimited list
Change-Id: I408f8a3bbe24d51fe96919aee30b30849ef68376
Added:
incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPool.cpp
- copied, changed from r1368516, incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPool.h
incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchQueuedPool.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchQueuedPoolTest.cpp
Removed:
incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchStubBase.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchType.h
incubator/etch/trunk/binding-cpp/runtime/include/support/EtchFreePool.h
incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPool.h
incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPoolRunnable.h
incubator/etch/trunk/binding-cpp/runtime/include/support/EtchQueuedPool.h
incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubBase.h
incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubHelper.h
incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchType.cpp
incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchFreePool.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchFreePoolTest.cpp
Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h Thu Aug 2 15:13:36 2012
@@ -65,8 +65,10 @@ enum EtchObjectTypeIds {
EOTID_RUNTIME_EXCEPTION,
EOTID_ARRAY_VALUE,
EOTID_FREEPOOL,
+ EOTID_QUEUEDPOOL,
EOTID_WAIT_UP,
- EOTID_WAIT_DOWN
+ EOTID_WAIT_DOWN,
+ EOTID_STUBHELPER
};
class EtchObjectType : public EtchObject {
Modified: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchType.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchType.h?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchType.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchType.h Thu Aug 2 15:13:36 2012
@@ -195,6 +195,18 @@ public:
*/
void setImportExportHelper(EtchImportExportHelper* helper);
+
+ /**
+ * @return the associated StubHelper.
+ */
+ EtchObject* getStubHelper();
+
+ /**
+ * Sets the associated StubHelper
+ * @param StubHelper as EtchObject
+ */
+ void setStubHelper(EtchObject* stubHelper);
+
/**
* @return the field with the value of this response.
*/
@@ -249,6 +261,7 @@ private:
EtchField mResponseField;
const EtchObjectType* mComponentType;
EtchImportExportHelper* mHelper;
+ EtchObject* mStubHelper;
};
#endif /* ETCHTYPE_H */
Modified: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchFreePool.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchFreePool.h?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchFreePool.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchFreePool.h Thu Aug 2 15:13:36 2012
@@ -19,6 +19,7 @@
#ifndef __ETCHFREEPOOL_H__
#define __ETCHFREEPOOL_H__
+#include "capu/os/Mutex.h"
#include "capu/container/List.h"
#include "support/EtchPool.h"
#include "support/EtchPoolRunnable.h"
@@ -36,6 +37,11 @@ class EtchFreePool : public EtchPool
public:
/**
+ * Internal friend class
+ */
+ friend class EtchFreePoolRunnable;
+
+ /**
* EtchObjectType for EtchFreePool.
*/
static const EtchObjectType* TYPE();
@@ -57,24 +63,36 @@ public:
* threads are allowed to start.
* @return error if somthings goes wrong
*/
- capu::status_t close();
+ status_t close();
+
+ /**
+ * Return the current pool size
+ */
+ capu::int32_t getSize();
/**
* Joins each of the threads in this pool until there
* are none left. The pool will be closed first.
* @return error if somthings goes wrong
*/
- capu::status_t join();
+ status_t join();
/**
* @see EtchPool
*/
- virtual capu::status_t add(capu::SmartPointer<EtchPoolRunnable> runnable);
+ virtual status_t add(capu::SmartPointer<EtchPoolRunnable> runnable);
private:
- capu::int32_t mMaxSize;
+ capu::int32_t mSize;
+ capu::int32_t mSizeMax;
capu::bool_t mIsOpen;
- capu::List<capu::Thread*> mThreads;
+ capu::Mutex mMutex;
+ capu::Thread** mThreads;
+
+ /**
+ * Checks thread list and clean up
+ */
+ status_t check();
};
#endif /* __ETCHFREEPOOL_H__ */
Modified: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPool.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPool.h?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPool.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPool.h Thu Aug 2 15:13:36 2012
@@ -24,11 +24,10 @@
#include "support/EtchPoolRunnable.h"
/**
- * Interface to a queued or free thread pool.
- */
+ * Interface to a pool of runnables.
+ */
class EtchPool
- : public EtchObject
-{
+ : public EtchObject {
public:
/**
@@ -48,7 +47,7 @@ public:
* @return error if there is a problem scheduling the
* runnable to run
*/
- virtual capu::status_t add(capu::SmartPointer<EtchPoolRunnable> runnable) = 0;
-};
+ virtual status_t add(capu::SmartPointer<EtchPoolRunnable> runnable) = 0;
+};
#endif /* __ETCHPOOL_H__ */
Modified: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPoolRunnable.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPoolRunnable.h?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPoolRunnable.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPoolRunnable.h Thu Aug 2 15:13:36 2012
@@ -33,13 +33,42 @@ public:
* Execute the runnable
* @return error core if some exeception occures
*/
- virtual capu::status_t run() = 0;
+ virtual status_t run() = 0;
+
+ /**
+ * Sets an exception
+ * @param exception that occured
+ * @return ETCH_OK if no error
+ */
+ status_t setException(capu::SmartPointer<EtchException> exception) {
+ mException = exception;
+ }
+
+ capu::bool_t hasException() {
+ return (mException.get() != NULL);
+ }
+
+ /**
+ * Gets the exception
+ * @param exception that should be returned
+ * @return ETCH_OK if no error, ETCH_EINVAL if the given params are invalid
+ */
+ status_t getException(capu::SmartPointer<EtchException> *exception) {
+ if(exception == NULL) {
+ return ETCH_EINVAL;
+ }
+ *exception = mException;
+ return ETCH_OK;
+ }
/**
* Reports an exception thrown by the run method.
* @param e exception
*/
- virtual capu::status_t exception(capu::SmartPointer<EtchException> exception) = 0;
+ virtual status_t exception(capu::SmartPointer<EtchException> exception) = 0;
+
+private:
+ capu::SmartPointer<EtchException> mException;
};
#endif
Modified: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchQueuedPool.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchQueuedPool.h?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchQueuedPool.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchQueuedPool.h Thu Aug 2 15:13:36 2012
@@ -22,6 +22,10 @@
#include "support/EtchPool.h"
#include "support/EtchPoolRunnable.h"
+namespace capu {
+ class ThreadPool;
+};
+
/**
* A implementation of the free pool.
*/
@@ -38,7 +42,7 @@ public:
* Creats a new instance of the EtchQueuedPool-Class.
* @param size of the pool
*/
- EtchQueuedPool();
+ EtchQueuedPool(capu::int32_t size = 50);
/**
* Destructure.
@@ -46,10 +50,30 @@ public:
virtual ~EtchQueuedPool();
/**
+ * Closes the pool. This just marks the pool as being closed, it doesn't
+ * actually do anything to the currently running thread. But no more
+ * threads are allowed to start.
+ * @return error if somthings goes wrong
+ */
+ status_t close();
+
+ /**
+ * Joins each of the threads in this pool until there
+ * are none left. The pool will be closed first.
+ * @return error if somthings goes wrong
+ */
+ status_t join();
+
+ /**
* @see EtchPool
*/
- virtual capu::status_t add(capu::SmartPointer<EtchPoolRunnable> runnable);
+ status_t add(capu::SmartPointer<EtchPoolRunnable> runnable);
+private:
+ capu::int32_t mSizeMax;
+ capu::bool_t mIsOpen;
+ capu::ThreadPool* mPool;
};
#endif /*__ETCHQUEUEDPOOL_H__ */
+
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=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubBase.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubBase.h Thu Aug 2 15:13:36 2012
@@ -21,79 +21,167 @@
#include "common/EtchTypes.h"
#include "support/EtchDeliveryService.h"
+#include "support/EtchStubHelper.h"
+#include "support/EtchFreePool.h"
+#include "support/EtchQueuedPool.h"
+#include "support/EtchStubHelperArgs.h"
+#include "transport/EtchWho.h"
+#include "transport/EtchMessage.h"
/**
-* Base class of stub implementations.
-* @param <T> The type of object used to implement stub.
-*/
+ * Base class of stub implementations.
+ * @param <T> The type of object used to implement stub.
+ */
template<typename T>
-class EtchStubBase {
+class EtchStubBase
+ : public EtchSessionMessage {
+public:
+ /**
+ * Constructs the StubBase.
+ * @param svc the message source.
+ * @param obj the target of decoded messages.
+ */
+ EtchStubBase(EtchDeliveryService* svc, T* obj, EtchFreePool* pool, EtchQueuedPool* queue);
+
+ /**
+ * Destructor
+ */
+ virtual ~EtchStubBase();
+
+ /**
+ *@see EtchSessionMessage
+ */
+ status_t sessionMessage(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg);
+
+ /**
+ *@see EtchSessionMessage
+ */
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event);
+
+ /**
+ *@see EtchSessionMessage
+ */
+ status_t sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> result);
+
+ /**
+ *@see EtchSessionMessage
+ */
+ status_t sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value);
protected:
+
/**
* The message source.
*/
- const capu::SmartPointer<EtchDeliveryService> svc;
+ EtchDeliveryService* mSvc;
+ EtchFreePool* mFreePool;
+ EtchQueuedPool* mQueuedPool;
/**
* The object used to implement stub.
*/
- const capu::SmartPointer<T> obj;
+ T* mObj;
+};
+
+template<typename T>
+class EtchStubPoolRunnable : EtchPoolRunnable {
-public:
/**
- * Constructs the StubBase.
- * @param svc the message source.
- * @param obj the target of decoded messages.
+ * Constructs the StubPoolRunnable.
+ * @param stub the stub of this service
+ * @param sender the sender of the message
+ * @param msg the message.
+ * @param helper the StubHelper which will dispatch the message.
*/
- EtchStubBase(capu::SmartPointer<EtchDeliveryService> svc, capu::SmartPointer<T> obj);
-
- status_t sessionMessage(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg, capu::bool_t &result );
+ EtchStubPoolRunnable(EtchStubBase<T>* stub, capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg, EtchStubHelper<T>* helper)
+ : mStub(stub)
+ , mSender(sender)
+ , mMsg(msg)
+ , mHelper(helper) {
+ }
+
+ status_t run() {
+ status_t status = mHelper->run(mStub, mStub->mSvc, mStub->mObj, mSender, mMsg);
+ if(status != ETCH_OK) {
+ // e.g exception
+ // TODO: handel exception
+ }
+ return ETCH_OK;
+ }
+
+ status_t exception(capu::SmartPointer<EtchException> exception) {
+ return ETCH_OK;
+ }
private:
- /**
- * A PoolRunnable used by the stub to dispatch asynchronous
- * receiver methods from messages.
- */
- class EtchStubPoolRunnable //: EtchPoolRunnable
- {
- /**
- * Constructs the StubPoolRunnable.
- * @param sender the sender of the message.
- * @param msg the message.
- * @param helper the StubHelper which will dispatch the message.
- */
- /*public StubPoolRunnable( Who sender, Message msg, StubHelper<T> helper )
- {
- this.sender = sender;
- this.msg = msg;
- this.helper = helper;
- }
-
- private final Who sender;
-
- private final Message msg;
-
- private final StubHelper<T> helper;
-
- public void exception( Exception e )
- {
- try
- {
- sessionNotify( e );
- }
- catch ( Exception e1 )
- {
- e1.printStackTrace();
- }
- }
-
- public void run() throws Exception
- {
- helper.run( svc, obj, sender, msg );
- }*/
- };
+ EtchStubBase<T>* mStub;
+ capu::SmartPointer<EtchWho> mSender;
+ capu::SmartPointer<EtchMessage> mMsg;
+ EtchStubHelper<T>* mHelper;
};
+template<typename T>
+EtchStubBase<T>::EtchStubBase(EtchDeliveryService* svc, T* obj, EtchFreePool* pool, EtchQueuedPool* queue)
+: mSvc(svc), mObj(obj), mFreePool(pool), mQueuedPool(queue) {
+ mSvc->setSession(this);
+}
+
+template<typename T>
+EtchStubBase<T>::~EtchStubBase() {
+ delete mObj;
+ delete mSvc;
+}
+
+template<typename T>
+status_t EtchStubBase<T>::sessionMessage(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg) {
+ EtchType* type = msg->getType();
+
+ EtchStubHelper<T>* helper = (EtchStubHelper<T>*) type->getStubHelper();
+ if (helper == NULL) {
+ return ETCH_ERROR;
+ }
+
+ capu::status_t res;
+ EtchPoolRunnable* runnable = NULL;
+ switch (type->getAsyncMode()) {
+ case QUEUED:
+ runnable = new EtchPoolRunnable<T>(this, helper, mSvc, mObj, sender, msg);
+ res = mQueuedPool->add(runnable);
+ if (res != ETCH_OK)
+ sessionNotify(NULL); //TODO Exception Handling
+ return res;
+ case FREE:
+ runnable = new EtchPoolRunnable<T>(this, helper, mSvc, mObj, sender, msg);
+ res = mFreePool->add(runnable);
+ if (res != ETCH_OK)
+ sessionNotify(NULL); //TODO Exception Handling
+ return res;
+ case NONE:
+ res = helper->run(this, mSvc, mObj, sender, msg);
+ if (res != ETCH_OK)
+ sessionNotify(NULL); //TODO Exception Handling
+ return res;
+ default:
+ // throw new IllegalArgumentException("unknown async mode "+type.getAsyncMode());
+ sessionNotify(NULL); //TODO Exception Handling
+ return ETCH_OK;
+ }
+}
+
+template<typename T>
+status_t EtchStubBase<T>::sessionNotify(capu::SmartPointer<EtchObject> event) {
+ return ETCH_EUNIMPL;
+}
+
+template<typename T>
+status_t EtchStubBase<T>::sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
+ return ETCH_EUNIMPL;
+}
+
+template<class T>
+status_t EtchStubBase<T>::sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> result) {
+ return ETCH_EUNIMPL;
+}
+
#endif
Modified: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubHelper.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubHelper.h?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubHelper.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchStubHelper.h Thu Aug 2 15:13:36 2012
@@ -20,34 +20,49 @@
#ifndef __ETCHSTUBHELPER_H__
#define __ETCHSTUBHELPER_H__
+#include "capu/util/SmartPointer.h"
#include "support/EtchDeliveryService.h"
-/**
-* Generated code to dispatch method from message.
-* @param <T> the service interface type.
-*/
+template<typename T>
+class EtchStubBase;
+/**
+ * Generated code to dispatch method from message.
+ * @param <T> the service interface type.
+ */
template <typename T>
class EtchStubHelper
-{
- /**
- * Constructs a StubHelper which uses synchronous mode to dispatch
- * method from message.
- */
+ : public EtchObject {
public:
+
+ /**
+ * EtchObjectType for EtchStubHelper.
+ */
+ static const EtchObjectType* TYPE();
+
+ /**
+ * Constructs a StubHelper which uses synchronous mode to dispatch
+ * method from message.
+ */
EtchStubHelper()
- {
+ : EtchObject(EtchStubHelper::TYPE()) {
// nothing to do.
}
- /**
- * Dispatches the method from message.
- * @param svc
- * @param obj
- * @param sender
- * @param msg
- */
- virtual status_t run(capu::SmartPointer<EtchDeliveryService> svc, capu::SmartPointer<T> obj, capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg);
+ /**
+ * Dispatches the method from message.
+ * @param svc
+ * @param obj
+ * @param sender
+ * @param msg
+ */
+ virtual status_t run(EtchStubBase<T>* ref, EtchDeliveryService* svc, T* obj, capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg ) = 0;
};
+template<typename T>
+const EtchObjectType* EtchStubHelper<T>::TYPE() {
+ const static EtchObjectType TYPE(EOTID_STUBHELPER, NULL);
+ return &TYPE;
+}
+
#endif
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Thu Aug 2 15:13:36 2012
@@ -114,11 +114,12 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/support/EtchAsyncResultBase.h
${PROJECT_SOURCE_DIR}/include/support/EtchDefaultServerFactory.h
${PROJECT_SOURCE_DIR}/include/support/EtchDeliveryService.h
- ${PROJECT_SOURCE_DIR}/include/support/EtchFreePool.h
${PROJECT_SOURCE_DIR}/include/support/EtchMailbox.h
${PROJECT_SOURCE_DIR}/include/support/EtchObjectSession.h
${PROJECT_SOURCE_DIR}/include/support/EtchPool.h
${PROJECT_SOURCE_DIR}/include/support/EtchPoolRunnable.h
+ ${PROJECT_SOURCE_DIR}/include/support/EtchFreePool.h
+ ${PROJECT_SOURCE_DIR}/include/support/EtchQueuedPool.h
${PROJECT_SOURCE_DIR}/include/support/EtchRemoteBase.h
${PROJECT_SOURCE_DIR}/include/support/EtchServerFactory.h
${PROJECT_SOURCE_DIR}/include/support/EtchStubHelper.h
@@ -202,12 +203,11 @@ SET(MAIN_SOURCES
serialization/EtchBinaryTaggedDataInput.cpp
serialization/EtchBinaryTaggedDataOutput.cpp
support/EtchPlainMailbox.cpp
+ support/EtchPool.cpp
support/EtchFreePool.cpp
+ support/EtchQueuedPool.cpp
support/EtchDefaultServerFactory.cpp
- support/EtchStubBase.cpp
support/EtchRemoteBase.cpp
- transport/EtchTransportFactory.cpp
- transport/EtchTcpTransportFactory.cpp
support/EtchTransportHelper.cpp
support/EtchMonitor.cpp
util/EtchCircularQueue.cpp
@@ -222,9 +222,11 @@ add_library (etch-cpp STATIC
)
IF (UNIX)
- target_link_libraries (etch-cpp ${CAPU/lib/Linux})
+ #TODO: add correct lib here debug / release
+ target_link_libraries (etch-cpp ${CAPU}/lib/Linux_X86_32/libcapu.a)
ELSEIF(WIN32)
- target_link_libraries (etch-cpp ${CAPU/lib/Win32})
+ #TODO: add correct lib here debug / release
+ target_link_libraries (etch-cpp ${CAPU}/lib/windows_x86_32/debug/capu.lib)
ENDIF()
IF (UNIX)
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchType.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchType.cpp?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchType.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchType.cpp Thu Aug 2 15:13:36 2012
@@ -183,3 +183,11 @@ void EtchType::setComponentType(const Et
const EtchObjectType* EtchType::getComponentType() {
return mComponentType;
}
+
+EtchObject* EtchType::getStubHelper() {
+ return mStubHelper;
+}
+
+void EtchType::setStubHelper(EtchObject* stubHelper) {
+ mStubHelper = stubHelper;
+}
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchFreePool.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchFreePool.cpp?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchFreePool.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchFreePool.cpp Thu Aug 2 15:13:36 2012
@@ -17,8 +17,50 @@
*/
#include "support/EtchFreePool.h"
+
+#include "capu/os/Thread.h"
+#include "capu/os/Memory.h"
#include "capu/util/Runnable.h"
+
+class EtchFreePoolRunnable : public capu::Runnable {
+public:
+
+ /**
+ * Create a new instance of EtchFreePoolRunnable class.
+ */
+ EtchFreePoolRunnable(EtchFreePool* pool, capu::SmartPointer<EtchPoolRunnable> runnable)
+ : mPool(pool), mRunnable(runnable) {
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~EtchFreePoolRunnable() {
+ }
+
+ /**
+ * Runnable
+ */
+ void run() {
+ if(mRunnable.get() != NULL) {
+ if(ETCH_OK != mRunnable->run()) {
+ // Log exception
+ if(mRunnable->hasException()) {
+ capu::SmartPointer<EtchException> exception;
+ mRunnable->getException(&exception);
+ mRunnable->exception(exception);
+ }
+ }
+ }
+ delete this;
+ }
+
+private:
+ EtchFreePool* mPool;
+ capu::SmartPointer<EtchPoolRunnable> mRunnable;
+};
+
const EtchObjectType* EtchFreePool::TYPE() {
const static EtchObjectType TYPE(EOTID_FREEPOOL, NULL);
return &TYPE;
@@ -26,21 +68,93 @@ const EtchObjectType* EtchFreePool::TYPE
EtchFreePool::EtchFreePool(capu::int32_t size)
: EtchPool(EtchFreePool::TYPE())
- , mMaxSize(size)
- , mIsOpen(false) {
-}
+ , mSize(0)
+ , mSizeMax(size)
+ , mIsOpen(true) {
-EtchFreePool::~EtchFreePool() {
-}
-
-capu::status_t EtchFreePool::close() {
- return ETCH_EUNIMPL;
+ mThreads = new capu::Thread*[mSizeMax];
+ capu::Memory::Set(mThreads, 0, sizeof(capu::Thread*)*mSizeMax);
}
-capu::status_t EtchFreePool::join() {
- return ETCH_EUNIMPL;
+EtchFreePool::~EtchFreePool() {
+ delete[] mThreads;
}
-capu::status_t EtchFreePool::add(capu::SmartPointer<EtchPoolRunnable> runnable) {
- return ETCH_EUNIMPL;
+status_t EtchFreePool::close() {
+ mIsOpen = false;
+ return ETCH_OK;
+}
+
+capu::int32_t EtchFreePool::getSize() {
+ capu::int32_t size;
+ mMutex.lock();
+ check();
+ size = mSize;
+ mMutex.unlock();
+ return size;
+}
+
+status_t EtchFreePool::join() {
+ mMutex.lock();
+ close();
+ for(capu::int32_t i = 0; i < mSizeMax; i++) {
+ if(mThreads[i] != NULL) {
+ mThreads[i]->join();
+ delete mThreads[i];
+ mThreads[i] = NULL;
+ }
+ }
+ mMutex.unlock();
+ return ETCH_OK;
+}
+
+status_t EtchFreePool::add(capu::SmartPointer<EtchPoolRunnable> runnable) {
+
+ // TODO: improve thread group handling and clean up e.g. with
+ // a free list that could be cleaned if the tread terminated
+
+ if(!mIsOpen) {
+ return ETCH_ERROR;
+ }
+
+ mMutex.lock();
+
+ // clean thread list
+ check();
+
+ if(mSize >= mSizeMax) {
+ mMutex.unlock();
+ return ETCH_ERROR;
+ }
+
+ EtchFreePoolRunnable* tmp = new EtchFreePoolRunnable(this, runnable);
+ capu::Thread* thread = new capu::Thread(tmp);
+ thread->start();
+
+ for(capu::int32_t i = 0; i < mSizeMax; i++) {
+ if(mThreads[i] == NULL) {
+ mThreads[i] = thread;
+ mSize++;
+ mMutex.unlock();
+ return ETCH_OK;
+ }
+ }
+ mMutex.unlock();
+
+ return ETCH_ERROR;
+}
+
+status_t EtchFreePool::check() {
+ for(capu::int32_t i = 0; i < mSizeMax; i++) {
+ if(mThreads[i] != NULL) {
+ capu::ThreadState state = mThreads[i]->getState();
+ // clean old threads
+ if(capu::TS_TERMINATED == state) {
+ delete mThreads[i];
+ mThreads[i] = NULL;
+ mSize--;
+ }
+ }
+ }
+ return ETCH_OK;
}
Copied: incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPool.cpp (from r1368516, incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPool.h)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPool.cpp?p2=incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPool.cpp&p1=incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPool.h&r1=1368516&r2=1368517&rev=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPool.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPool.cpp Thu Aug 2 15:13:36 2012
@@ -17,38 +17,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-#ifndef __ETCHPOOL_H__
-#define __ETCHPOOL_H__
-#include "common/EtchObject.h"
-#include "support/EtchPoolRunnable.h"
+#include "support/EtchPool.h"
-/**
- * Interface to a queued or free thread pool.
- */
-class EtchPool
- : public EtchObject
-{
-public:
-
- /**
- * Creates a new instance of the EtchPool-Class.
- */
- EtchPool(const EtchObjectType* type)
- : EtchObject(type) {}
-
- /**
- * Destructure.
- */
- virtual ~EtchPool() {}
-
- /**
- * scheduling the runnable to run
- * @param runnable the thing to run.
- * @return error if there is a problem scheduling the
- * runnable to run
- */
- virtual capu::status_t add(capu::SmartPointer<EtchPoolRunnable> runnable) = 0;
-};
-
-#endif /* __ETCHPOOL_H__ */
Added: 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=1368517&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchQueuedPool.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchQueuedPool.cpp Thu Aug 2 15:13:36 2012
@@ -0,0 +1,99 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "support/EtchQueuedPool.h"
+
+#include "capu/os/Thread.h"
+#include "capu/util/ThreadPool.h"
+#include "capu/os/Memory.h"
+#include "capu/util/Runnable.h"
+
+class EtchQueuedPoolRunnable : public capu::Runnable {
+public:
+
+ /**
+ * Create a new instance of EtchFreePoolRunnable class.
+ */
+ EtchQueuedPoolRunnable(EtchQueuedPool* pool, capu::SmartPointer<EtchPoolRunnable> runnable)
+ : mPool(pool), mRunnable(runnable) {
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~EtchQueuedPoolRunnable() {
+ }
+
+ /**
+ * Runnable
+ */
+ void run() {
+ if(mRunnable.get() != NULL) {
+ if(ETCH_OK != mRunnable->run()) {
+ // Log exception
+ if(mRunnable->hasException()) {
+ capu::SmartPointer<EtchException> exception;
+ mRunnable->getException(&exception);
+ mRunnable->exception(exception);
+ }
+ }
+ }
+ }
+
+private:
+ EtchQueuedPool* mPool;
+ capu::SmartPointer<EtchPoolRunnable> mRunnable;
+};
+
+const EtchObjectType* EtchQueuedPool::TYPE() {
+ const static EtchObjectType TYPE(EOTID_QUEUEDPOOL, NULL);
+ return &TYPE;
+}
+
+EtchQueuedPool::EtchQueuedPool(capu::int32_t size)
+ : EtchPool(EtchQueuedPool::TYPE())
+ , mSizeMax(size)
+ , mIsOpen(true) {
+ mPool = new capu::ThreadPool(mSizeMax);
+}
+
+EtchQueuedPool::~EtchQueuedPool() {
+ delete mPool;
+}
+
+status_t EtchQueuedPool::close() {
+ mIsOpen = false;
+ return ETCH_OK;
+}
+
+status_t EtchQueuedPool::join() {
+ mPool->join();
+ return ETCH_OK;
+}
+
+status_t EtchQueuedPool::add(capu::SmartPointer<EtchPoolRunnable> runnable) {
+ if(!mIsOpen) {
+ return ETCH_EINVAL;
+ }
+
+ EtchQueuedPoolRunnable* pr = new EtchQueuedPoolRunnable(this, runnable);
+ capu::status_t status = mPool->add(pr);
+ if(status != capu::CAPU_OK) {
+ return ETCH_ERROR;
+ }
+ return ETCH_OK;
+}
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt Thu Aug 2 15:13:36 2012
@@ -85,6 +85,7 @@ add_executable (etch-cpp-test
serialization/EtchValidatorStructValueTest.cpp
serialization/EtchBinaryTaggedDataInputOutputTest.cpp
support/EtchFreePoolTest.cpp
+ support/EtchQueuedPoolTest.cpp
support/EtchPlainMailboxTest.cpp
support/EtchMonitorTest.cpp
support/EtchRemoteBaseTest.cpp
@@ -96,12 +97,6 @@ add_executable (etch-cpp-test
)
IF (UNIX)
- target_link_libraries (etch-cpp-test ${CAPU/lib/Linux_X86_32})
-ELSEIF(WIN32)
- target_link_libraries (etch-cpp-test ${CAPU/lib/Windows_x86_32})
-ENDIF()
-
-IF (UNIX)
target_link_libraries (etch-cpp-test etch-cpp pthread rt)
ELSEIF(WIN32)
target_link_libraries (etch-cpp-test etch-cpp)
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchFreePoolTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchFreePoolTest.cpp?rev=1368517&r1=1368516&r2=1368517&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchFreePoolTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchFreePoolTest.cpp Thu Aug 2 15:13:36 2012
@@ -17,10 +17,114 @@
*/
#include <gtest/gtest.h>
+#include "capu/os/Mutex.h"
+#include "capu/os/CondVar.h"
+#include "capu/os/Thread.h"
#include "support/EtchFreePool.h"
+class EtchFreePooTestRunnable : public EtchPoolRunnable{
+public:
+
+
+ EtchFreePooTestRunnable(capu::Mutex* mutex, capu::CondVar* condVar, capu::int8_t* cond)
+ : mMutex(mutex), mCondVar(condVar), mCond(cond) {
+ }
+
+ /**
+ * @see EtchPoolRunnable
+ */
+ status_t run() {
+ //printf("run\n");
+ mMutex->lock();
+
+ // case 1
+ while(*mCond == 1 || *mCond == 2) {
+ (*mCond)++;
+ //printf("wait\n");
+ mCondVar->wait(mMutex);
+ //printf("wait -> run\n");
+ }
+
+ mMutex->unlock();
+ return ETCH_OK;
+ }
+
+ /**
+ * @see EtchPoolRunnable
+ */
+ status_t exception(capu::SmartPointer<EtchException> exception) {
+ return ETCH_OK;
+ }
+
+private:
+ capu::Mutex* mMutex;
+ capu::CondVar* mCondVar;
+ capu::int8_t* mCond;
+};
+
+
TEST(EtchFreePoolTest, Constructor_Default){
EtchFreePool* pool = new EtchFreePool(20);
delete pool;
+}
+
+TEST(EtchFreePoolTest, add){
+ EtchFreePool* pool = new EtchFreePool(2);
+
+ capu::Mutex mutex;
+ capu::CondVar condVar;
+ capu::int8_t cond;
+
+ capu::SmartPointer<EtchFreePooTestRunnable>* ra = new capu::SmartPointer<EtchFreePooTestRunnable>[10];
+ for(int i = 0; i < 10; i++) {
+ ra[i] = new EtchFreePooTestRunnable(&mutex, &condVar, &cond);
+ }
+
+ mutex.lock();
+ cond = 1;
+ mutex.unlock();
+
+ status_t status;
+ status = pool->add(ra[0]);
+ EXPECT_EQ(ETCH_OK, status);
+ status = pool->add(ra[1]);
+ EXPECT_EQ(ETCH_OK, status);
+
+ // wait if pool is full
+ mutex.lock();
+ while(cond < 3) {
+ condVar.wait(&mutex, 1000);
+ }
+ mutex.unlock();
+
+ // pool is full, so error
+ status = pool->add(ra[2]);
+ EXPECT_EQ(ETCH_ERROR, status);
+
+ // set new cond and signal
+ mutex.lock();
+ cond = 4;
+ condVar.broadcast();
+ mutex.unlock();
+
+ // wait if pool is empty
+ mutex.lock();
+ while(pool->getSize() > 0) {
+ condVar.wait(&mutex, 1000);
+ }
+ mutex.unlock();
+
+ status = pool->add(ra[3]);
+ EXPECT_EQ(ETCH_OK, status);
+
+ pool->join();
+ delete pool;
+ delete[] ra;
+}
+TEST(EtchFreePoolTest, join){
+ EtchFreePool* pool = new EtchFreePool(20);
+ pool->join();
+ delete pool;
}
+
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchQueuedPoolTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchQueuedPoolTest.cpp?rev=1368517&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchQueuedPoolTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchQueuedPoolTest.cpp Thu Aug 2 15:13:36 2012
@@ -0,0 +1,89 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include "capu/os/Mutex.h"
+#include "support/EtchQueuedPool.h"
+
+class EtchQueuedPooTestRunnable : public EtchPoolRunnable{
+public:
+
+
+ EtchQueuedPooTestRunnable()
+ : mCount(0) {
+ }
+
+ /**
+ * @see EtchPoolRunnable
+ */
+ status_t run() {
+ mMutex.lock();
+ mCount++;
+ mMutex.unlock();
+ return ETCH_OK;
+ }
+
+ /**
+ * @see EtchPoolRunnable
+ */
+ status_t exception(capu::SmartPointer<EtchException> exception) {
+ return ETCH_OK;
+ }
+
+ /**
+ * Returns count
+ */
+ capu::int32_t getCount() {
+ return mCount;
+ }
+
+private:
+ capu::Mutex mMutex;
+ capu::int32_t mCount;
+};
+
+TEST(EtchQueuedPoolTest, Constructor_Default){
+ EtchQueuedPool* pool = new EtchQueuedPool(2);
+ delete pool;
+}
+
+TEST(EtchQueuedPoolTest, add){
+ EtchQueuedPool* pool = new EtchQueuedPool();
+
+ capu::SmartPointer<EtchQueuedPooTestRunnable> ra = new EtchQueuedPooTestRunnable();
+
+ for(int i = 0; i < 10000; i++) {
+ status_t status = pool->add(ra);
+ ASSERT_EQ(ETCH_OK, status);
+ }
+ pool->join();
+ ASSERT_EQ(10000, ra->getCount());
+ delete pool;
+}
+
+TEST(EtchQueuedPoolTest, close){
+ EtchQueuedPool* pool = new EtchQueuedPool();
+ delete pool;
+}
+
+TEST(EtchQueuedPoolTest, join){
+ EtchQueuedPool* pool = new EtchQueuedPool();
+ delete pool;
+}
+