activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r767916 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main: activemq/library/ decaf/internal/ decaf/lang/ decaf/util/concurrent/
Date Thu, 23 Apr 2009 13:28:34 GMT
Author: tabish
Date: Thu Apr 23 13:28:33 2009
New Revision: 767916

URL: http://svn.apache.org/viewvc?rev=767916&view=rev
Log:
Adds library initialization and shutdown methods to the Decaf library which accept the args
passed to the process in order to later support setting system properties in the Decaf Runtime
and adds an new init method the the AMQCPP library init code to allow this also.  Cleanup
in thread pool to not always allocate a global pool, only do it once one is requested.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runtime.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp?rev=767916&r1=767915&r2=767916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp Thu
Apr 23 13:28:33 2009
@@ -37,21 +37,26 @@
 using namespace activemq::wireformat;
 
 ////////////////////////////////////////////////////////////////////////////////
-void ActiveMQCPP::initializeLibrary() {
+void ActiveMQCPP::initializeLibrary( int argc, char** argv ) {
 
     // Initialize the Decaf Library by requesting its runtime.
-    decaf::lang::Runtime::getRuntime();
+    decaf::lang::Runtime::initializeRuntime( argc, argv );
 
     // Register all WireFormats
     ActiveMQCPP::registerWireFormats();
 
-    // Registr all Transports
+    // Register all Transports
     ActiveMQCPP::registerTransports();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ActiveMQCPP::shutdownLibrary() {
+void ActiveMQCPP::initializeLibrary() {
+    ActiveMQCPP::initializeLibrary( 0, NULL );
+}
 
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQCPP::shutdownLibrary() {
+    decaf::lang::Runtime::shutdownRuntime();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.h?rev=767916&r1=767915&r2=767916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.h Thu Apr
23 13:28:33 2009
@@ -38,10 +38,26 @@
          * Initialize the ActiveMQ-CPP Library constructs, this method will
          * init all the internal Registry objects and initialize the Decaf
          * library.
+         *
+         * @throws runtime_error if an error occurs while initializing this library.
          */
         static void initializeLibrary();
 
         /**
+         * Initialize the ActiveMQ-CPP Library constructs, this method will
+         * initialize all the internal Registry objects and initialize the Decaf
+         * library.  This method takes the args passed to the main method of
+         * process for use is setting system properties and configuring the
+         * ActiveMQ-CPP Library.
+         *
+         * @param argc - the count of arguments passed to this Process.
+         * @param argv - the array of string arguments passed to this process.
+         *
+         * @throws runtime_error if an error occurs while initializing this library.
+         */
+        static void initializeLibrary( int argc, char** argv );
+
+        /**
          * Shutdown the ActiveMQ-CPP Library, freeing any resources
          * that could not be freed up to this point.  All the user created
          * ActiveMQ-CPP objects and Decaf Library objects should have been

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp?rev=767916&r1=767915&r2=767916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/DecafRuntime.cpp Thu
Apr 23 13:28:33 2009
@@ -58,3 +58,21 @@
 
     return &runtime;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void Runtime::initializeRuntime( int argc DECAF_UNUSED, char **argv DECAF_UNUSED ) {
+
+    // Do this for now, once we remove APR we can do this in a way that
+    // makes more sense.
+    Runtime::getRuntime();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Runtime::initializeRuntime() {
+    Runtime::initializeRuntime( 0, NULL );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Runtime::shutdownRuntime() {
+
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runtime.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runtime.h?rev=767916&r1=767915&r2=767916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runtime.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runtime.h Thu Apr 23 13:28:33
2009
@@ -36,6 +36,35 @@
          */
         static Runtime* getRuntime();
 
+        /**
+         * Initialize the Decaf Library passing it the args that were passed
+         * to the application at startup.
+         *
+         * @param argc - The number of args passed
+         * @param args - Array of char* values passed to the Process on start.
+         *
+         * @throws runtime_error if the library is already initialized or an
+         *         error occurs during initialization.
+         */
+        static void initializeRuntime( int argc, char **argv );
+
+        /**
+         * Initialize the Decaf Library
+         *
+         * @throws runtime_error if the library is already initialized or an
+         *         error occurs during initialization.
+         */
+        static void initializeRuntime();
+
+        /**
+         * Shutdown the Decaf Library, this call should take places after all
+         * objects that were created from the Decaf library have been deallocated.
+         *
+         * @throws runtime_error if the library has not already been initialized or an
+         *         error occurs during shutdown.
+         */
+        static void shutdownRuntime();
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.cpp?rev=767916&r1=767915&r2=767916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.cpp
Thu Apr 23 13:28:33 2009
@@ -38,16 +38,12 @@
 LOGDECAF_INITIALIZE(marker, ThreadPool, "com.activemq.concurrent.ThreadPool.Marker")
 
 ////////////////////////////////////////////////////////////////////////////////
-ThreadPool ThreadPool::instance;
+ThreadPool::ThreadPool() {
 
-////////////////////////////////////////////////////////////////////////////////
-ThreadPool::ThreadPool()
-{
-    maxThreads  = DEFAULT_MAX_POOL_SIZE;
-    blockSize   = DEFAULT_MAX_BLOCK_SIZE;
-    freeThreads = 0;
-
-    shutdown = false;
+    this->maxThreads  = DEFAULT_MAX_POOL_SIZE;
+    this->blockSize   = DEFAULT_MAX_BLOCK_SIZE;
+    this->freeThreads = 0;
+    this->shutdown = false;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -86,13 +82,21 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+ThreadPool* ThreadPool::getInstance() {
+
+    static ThreadPool instance;
+
+    return &instance;
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void ThreadPool::queueTask( ThreadPool::Task task )
    throw ( lang::Exception ) {
 
     try{
-        
+
         if( !task.first || !task.second ) {
-            throw exceptions::IllegalArgumentException( 
+            throw exceptions::IllegalArgumentException(
                 __FILE__, __LINE__,
                 "ThreadPool::QueueTask - Invalid args for Task");
         }
@@ -126,7 +130,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 ThreadPool::Task ThreadPool::deQueueTask()
     throw ( lang::Exception ) {
-    
+
     try{
         //LOGCMS_DEBUG(logger, "ThreadPool::DeQueueTask - syncing on queue");
 
@@ -153,7 +157,7 @@
 
             // check size again.
             if( queue.empty() ) {
-               throw lang::Exception( 
+               throw lang::Exception(
                    __FILE__, __LINE__,
                    "ThreadPool::DeQueueUserWorkItem - Empty Taskn, not in shutdown.");
             }
@@ -172,11 +176,11 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void ThreadPool::reserve( std::size_t size ) {
-    
+
     try {
-        
+
         synchronized( &poolLock ) {
-            
+
             if( size < pool.size() || pool.size() == maxThreads ) {
                 return;
             }
@@ -196,9 +200,9 @@
 void ThreadPool::setMaxThreads( std::size_t maxThreads ) {
 
     try{
-        
+
         synchronized( &poolLock ) {
-            
+
             if( maxThreads == 0 ) {
                 // Caller tried to do something stupid, ignore them.
                 return;
@@ -213,7 +217,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void ThreadPool::setBlockSize( std::size_t blockSize ) {
-    
+
     try{
         if( blockSize <= 0 ) {
             // User tried something dumb, protect them from themselves
@@ -259,9 +263,9 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void ThreadPool::onTaskStarted( PooledThread* thread DECAF_UNUSED ) {
-    
+
     try{
-        
+
         synchronized( &poolLock ) {
 
             freeThreads--;
@@ -303,13 +307,13 @@
 void ThreadPool::onTaskException(
    PooledThread* thread,
    lang::Exception& ex DECAF_UNUSED ) {
-    
+
     //LOGCMS_DEBUG(logger, "ThreadPool::onTaskException: ");
 
     try{
-        
+
         synchronized( &poolLock ) {
-            
+
             // Delete the thread that had the exception and start a new
             // one to take its place.
             freeThreads--;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.h?rev=767916&r1=767915&r2=767916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPool.h Thu
Apr 23 13:28:33 2009
@@ -85,11 +85,6 @@
         LOGDECAF_DECLARE(logger)
         LOGDECAF_DECLARE(marker)
 
-    private:   // Statics
-
-        // The singleton instance of this class
-        static ThreadPool instance;
-
     public:
 
         ThreadPool();
@@ -218,9 +213,7 @@
          * Return the one and only Thread Pool instance.
          * @return The Thread Pool Pointer
          */
-        static ThreadPool* getInstance() {
-            return &instance;
-        }
+        static ThreadPool* getInstance();
 
     private:
 



Mime
View raw message