You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by nm...@apache.org on 2006/07/03 13:51:54 UTC

svn commit: r418749 [9/17] - in /incubator/activemq/trunk/activemq-cpp: ./ src/ src/main/ src/main/activemq/ src/main/activemq/concurrent/ src/main/activemq/connector/ src/main/activemq/connector/openwire/ src/main/activemq/connector/stomp/ src/main/ac...

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Logger.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Logger.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Logger.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Logger.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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 "Logger.h"
+
+#include <activemq/logger/Handler.h>
+#include <algorithm>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::logger;
+using namespace activemq::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+Logger::Logger(const std::string& name, Logger* parent)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Logger::~Logger(void)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::addHandler(Handler* handler) throw ( IllegalArgumentException )
+{
+    if(handler == NULL)
+    {
+        IllegalArgumentException(
+            __FILE__, __LINE__, 
+            "Logger::addHandler - HAndler cannot be null");
+    }
+    
+    if(find(handlers.begin(), handlers.end(), handler) != handlers.end())
+    {
+        handlers.push_back(handler);
+    }
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::removeHandler(Handler* handler)
+{
+    list<Handler*>::iterator itr = 
+        find(handlers.begin(), handlers.end(), handler);
+
+    if(itr != handlers.end())
+    {
+        delete *itr;
+        handlers.erase(itr);
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::setFilter(Filter* filter)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Logger::isLoggable(Level level) const
+{
+    return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::entry(const std::string& blockName, 
+                   const std::string& file, 
+                   const int line)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::exit(const std::string& blockName, 
+                  const std::string& file, 
+                  const int line)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::debug(const std::string& file, 
+                   const int line, 
+                   const std::string fnctionName, 
+                   const std::string& message)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::info(const std::string& file, 
+                  const int line, 
+                  const std::string fnctionName, 
+                  const std::string& message)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::error(const std::string& file, 
+                   const int line, 
+                   const std::string fnctionName,
+                   const std::string& message)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::warn(const std::string& file, 
+                  const int line, 
+                  const std::string fnctionName, 
+                  const std::string& message)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::fatal(const std::string& file, 
+                   const int line, 
+                   const std::string fnctionName, 
+                   const std::string& message)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::log(Level level, const std::string& message)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::log(Level level, 
+                 const std::string& file, 
+                 const int line, 
+                 const std::string& message, 
+                 cms::CMSException& ex)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::log(Level level, 
+                 const std::string& file, 
+                 const int line, 
+                 const std::string& message, ...)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Logger::log(LogRecord& record)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Logger* Logger::getLogger(const std::string& name)
+{
+    return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Logger* Logger::getAnonymousLogger(void)
+{
+    return NULL;
+}

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Logger.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Logger.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Logger.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Logger.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,425 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_LOGGER_LOGGER_H_
+#define _ACTIVEMQ_LOGGER_LOGGER_H_
+
+#include <activemq/logger/LoggerCommon.h>
+#include <activemq/logger/LogRecord.h>
+#include <activemq/exceptions/IllegalArgumentException.h>
+
+#include <list>
+#include <string>
+#include <stdarg.h>
+
+namespace activemq{
+namespace logger{
+    
+    class Handler;
+    class Filter;
+
+    class Logger
+    {
+    private:
+    
+        // The name of this Logger
+        std::string name;
+        
+        // The Parent of this Logger
+        Logger* parent;
+        
+        // list of Handlers owned by this logger
+        std::list<Handler*> handlers;
+        
+        // Filter used by this Logger
+        Filter* filter;
+        
+        // The Log Level of this Logger
+        Level level;
+        
+        // Using Parent Handlers?
+        bool useParentHandlers;
+    
+    public:
+    
+        /**
+         * Creates a new instance of the Logger with the given name
+         * and assign it the given parent logger.
+         * <p>
+         * The logger will be initially configured with a null Level 
+         * and with useParentHandlers true.
+         * @param name - A name for the logger. This should be a 
+         * dot-separated name and should normally be based on the package 
+         * name or class name of the subsystem, such as java.net or 
+         * javax.swing. It may be null for anonymous Loggers.
+         */
+        Logger(const std::string& name, Logger* parent);
+        
+        /**
+         * Destructor
+         */
+        virtual ~Logger(void);
+        
+        /**
+         * Gets the name of this Logger
+         * 
+         * @return logger name
+         */
+        virtual const std::string& getName(void) const {
+            return name;
+        }
+
+        /**
+         * Add a log Handler to receive logging messages.
+         * <p>
+         * By default, Loggers also send their output to their parent logger.
+         * Typically the root Logger is configured with a set of Handlers 
+         * that essentially act as default handlers for all loggers.
+         * 
+         * @param A Logging Handler
+         * #throws IllegalArgumentException
+         */
+        virtual void addHandler(Handler* handler) 
+            throw ( exceptions::IllegalArgumentException );
+        
+        /**
+         * Removes the specified Handler and destroys it
+         * <p>
+         * Returns silently if the given Handler is not found.
+         * 
+         * @param The Handler to remove
+         */
+        virtual void removeHandler(Handler* handler);
+
+        /**
+         * Gets a vector containing all the handlers that this class
+         * has been assigned to use.
+         */        
+        virtual const std::list<Handler*>& getHandlers(void) const;
+        
+        /**
+         * Set a filter to control output on this Logger.
+         * <p>
+         * After passing the initial "level" check, the Logger will call 
+         * this Filter to check if a log record should really be published. 
+         * <p>
+         * The caller releases ownership of this filter to this logger
+         * 
+         * @param Filter to use, can be null
+         */
+        virtual void setFilter(Filter* filter); 
+        
+        /**
+         * Gets the Filter object that this class is using.
+         * @return the Filter in use, can be null
+         */
+        virtual const Filter* getFilter(void) const {
+            return filter;
+        }
+        
+        /**
+         * Get the log Level that has been specified for this Logger. The 
+         * result may be the Null level, which means that this logger's 
+         * effective level will be inherited from its parent.
+         */
+        virtual Level getLevel(void) const {
+            return level;
+        }
+        
+        /**
+         * Set the log level specifying which message levels will be logged 
+         * by this logger. Message levels lower than this value will be 
+         * discarded. The level value Level.OFF can be used to turn off 
+         * logging.
+         * <p>
+         * If the new level is the Null Level, it means that this node 
+         * should inherit its level from its nearest ancestor with a 
+         * specific (non-null) level value. 
+         * 
+         * @param new Level value
+         */
+        virtual void setLevel(Level level) {
+            this->level = level;
+        }
+        
+        /**
+         * Discover whether or not this logger is sending its output to 
+         * its parent logger.
+         * 
+         * @return true if using Parent Handlers
+         */
+        virtual bool getUseParentHandlers(void) const {
+            return useParentHandlers;
+        }
+        
+        /**
+         * pecify whether or not this logger should send its output to it's 
+         * parent Logger. This means that any LogRecords will also be 
+         * written to the parent's Handlers, and potentially to its parent, 
+         * recursively up the namespace.
+         * 
+         * @param True is output is to be writen to the parent
+         */
+        virtual void setUseParentHandlers(bool value) {
+            this->useParentHandlers = value;
+        }
+        
+        /**
+         * Logs an Block Enter message
+         * <p>
+         * This is a convenience method that is used to tag a block enter, a
+         * log record with the class name function name and the string 
+         * Entering is logged at the DEBUG log level.
+         * @param source block name
+         * @param source file name
+         * @param source line name
+         */
+        virtual void entry(const std::string& blockName,
+                           const std::string& file,
+                           const int line);
+        
+        /**
+         * Logs an Block Exit message
+         * <p>
+         * This is a convenience method that is used to tag a block exit, a
+         * log record with the class name function name and the string 
+         * Exiting is logged at the DEBUG log level.
+         * @param source block name
+         * @param source file name
+         * @param source line name
+         */
+        virtual void exit(const std::string& blockName,
+                          const std::string& file,
+                          const int line);
+
+        /**
+         * Log a Debug Level Log
+         * <p>
+         * If the logger is currently enabled for the DEBUG message level 
+         * then the given message is forwarded to all the registered output
+         * Handler objects.
+         * 
+         * @param file name where the log was generated
+         * @param line number where the log was generated
+         * @param name of the function that logged this
+         * @param the message to log
+         */
+        virtual void debug(const std::string& file,
+                           const int line,
+                           const std::string fnctionName,
+                           const std::string& message);
+
+        /**
+         * Log a info Level Log
+         * <p>
+         * If the logger is currently enabled for the info message level 
+         * then the given message is forwarded to all the registered output
+         * Handler objects.
+         * 
+         * @param file name where the log was generated
+         * @param line number where the log was generated
+         * @param name of the function that logged this
+         * @param the message to log
+         */
+        virtual void info(const std::string& file,
+                          const int line,
+                          const std::string fnctionName,
+                          const std::string& message);
+
+        /**
+         * Log a warn Level Log
+         * <p>
+         * If the logger is currently enabled for the warn message level 
+         * then the given message is forwarded to all the registered output
+         * Handler objects.
+         * 
+         * @param file name where the log was generated
+         * @param line number where the log was generated
+         * @param name of the function that logged this
+         * @param the message to log
+         */
+        virtual void warn(const std::string& file,
+                          const int line,
+                          const std::string fnctionName,
+                          const std::string& message);
+                        
+        /**
+         * Log a error Level Log
+         * <p>
+         * If the logger is currently enabled for the error message level 
+         * then the given message is forwarded to all the registered output
+         * Handler objects.
+         * 
+         * @param file name where the log was generated
+         * @param line number where the log was generated
+         * @param name of the function that logged this
+         * @param the message to log
+         */
+        virtual void error(const std::string& file,
+                           const int line,
+                           const std::string fnctionName,
+                           const std::string& message);
+
+        /**
+         * Log a fatal Level Log
+         * <p>
+         * If the logger is currently enabled for the fatal message level 
+         * then the given message is forwarded to all the registered output
+         * Handler objects.
+         * 
+         * @param file name where the log was generated
+         * @param line number where the log was generated
+         * @param name of the function that logged this
+         * @param the message to log
+         */
+        virtual void fatal(const std::string& file,
+                           const int line,
+                           const std::string fnctionName,
+                           const std::string& message);
+                         
+        /**
+         * Log a Throw Message
+         * <p>
+         * If the logger is currently enabled for the Throwing message level 
+         * then the given message is forwarded to all the registered output
+         * Handler objects.
+         * 
+         * @param file name where the log was generated
+         * @param line number where the log was generated
+         * @param name of the function that logged this
+         * @param the message to log
+         */
+        virtual void throwing(const std::string& file,
+                              const int line,
+                              const std::string fnctionName,
+                              const std::string& message);
+        
+        /**
+         * Check if a message of the given level would actually be logged 
+         * by this logger. This check is based on the Loggers effective 
+         * level, which may be inherited from its parent.
+         * 
+         * @param level - a message logging level 
+         * returns true if the given message level is currently being logged.
+         */
+        virtual bool isLoggable(Level level) const;
+        
+        /**
+         * Log a LogRecord.
+         *
+         * All the other logging methods in this class call through this 
+         * method to actually perform any logging. Subclasses can override 
+         * this single method to capture all log activity. 
+         * 
+         * @param record - the LogRecord to be published
+         */
+        virtual void log(LogRecord& record);
+         
+        /**
+         * Log a message, with no arguments.
+         * <p>
+         * If the logger is currently enabled for the given message level 
+         * then the given message is forwarded to all the registered output 
+         * Handler objects
+         * 
+         * @param the Level to log at
+         * @param the message to log
+         */
+        virtual void log(Level level, const std::string& message);
+
+        /**
+         * Log a message, with the list of params that is formatted into
+         * the message string.
+         * <p>
+         * If the logger is currently enabled for the given message level 
+         * then the given message is forwarded to all the registered output 
+         * Handler objects
+         * 
+         * @param the Level to log at
+         * @param the message to log
+         * @param variable length arguement to format the message string.
+         */
+        virtual void log(Level level, 
+                         const std::string& file,
+                         const int line,
+                         const std::string& message, ...);
+
+        /**
+         * Log a message, with associated Throwable information.
+         *
+         * If the logger is currently enabled for the given message level 
+         * then the given arguments are stored in a LogRecord which is 
+         * forwarded to all registered output handlers.
+         *
+         * Note that the thrown argument is stored in the LogRecord thrown 
+         * property, rather than the LogRecord parameters property. Thus is 
+         * it processed specially by output Formatters and is not treated 
+         * as a formatting parameter to the LogRecord message property. 
+         * 
+         * @param the Level to log at
+         * @param File that the message was logged in
+         * @param line number where the message was logged at.
+         * @param Exception to log
+         */
+        virtual void log(Level level, 
+                         const std::string& file,
+                         const int line,
+                         const std::string& message, 
+                         cms::CMSException& ex);
+
+    public:
+    
+        /**
+         * Creates an anonymous logger
+         * <p>
+         * The newly created Logger is not registered in the LogManager 
+         * namespace. There will be no access checks on updates to the 
+         * logger.
+         * Even although the new logger is anonymous, it is configured to 
+         * have the root logger ("") as its parent. This means that by 
+         * default it inherits its effective level and handlers from the 
+         * root logger.
+         * <p>
+         * The caller is responsible for destroying the returned logger.
+         * 
+         * @return Newly created anonymous logger
+         */
+        static Logger* getAnonymousLogger(void);
+
+        /**
+         * Find or create a logger for a named subsystem. If a logger has 
+         * already been created with the given name it is returned. 
+         * Otherwise a new logger is created.
+         * <p>
+         * If a new logger is created its log level will be configured based 
+         * on the LogManager and it will configured to also send logging 
+         * output to its parent loggers Handlers. It will be registered in 
+         * the LogManager global namespace. 
+         * 
+         * @param name - A name for the logger. This should be a 
+         * dot-separated name and should normally be based on the package 
+         * name or class name of the subsystem, such as cms or 
+         * activemq.core.ActiveMQConnection
+         * 
+         * @return a suitable logger.
+         */
+        static Logger* getLogger(const std::string& name);
+
+    };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_LOGGER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerCommon.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerCommon.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerCommon.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerCommon.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_LOGGER_LOGGERCOMMON_H_
+#define _ACTIVEMQ_LOGGER_LOGGERCOMMON_H_
+
+namespace activemq{
+namespace logger{
+
+#ifdef DEBUG
+#undef DEBUG
+#endif
+
+   /**
+    * Defines an enumeration for logging levels
+    */
+   enum Level
+   {
+      Off,
+      Null,
+      Markblock,
+      Debug,
+      Info,
+      Warn,
+      Error,
+      Fatal,
+      Throwing
+   };
+   
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_LOGGERCOMMON_H_ */

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerDefines.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerDefines.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerDefines.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerDefines.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_LOGGER_LOGGERDEFINES_H_
+#define _ACTIVEMQ_LOGGER_LOGGERDEFINES_H_
+
+#include <activemq/logger/SimpleLogger.h>
+#include <sstream>
+
+#define LOGCMS_DECLARE(loggerName)                                  \
+   static activemq::logger::SimpleLogger loggerName;
+
+#define LOGCMS_INITIALIZE(loggerName, className, loggerFamily)      \
+   activemq::logger::SimpleLogger className::loggerName(loggerFamily);
+
+#define LOGCMS_DECLARE_LOCAL(loggerName)                            \
+   activemq::logger::Logger loggerName;
+
+#define LOGCMS_DEBUG(logger, message)                               \
+   logger.debug(__FILE__, __LINE__, message);
+
+#define LOGCMS_DEBUG_1(logger, message, value);                     \
+   {                                                                \
+      std::ostringstream ostream;                                   \
+      ostream << message << value;                                  \
+      logger.debug(__FILE__, __LINE__, ostream.str());              \
+   }
+
+#define LOGCMS_INFO(logger, message)                                \
+   logger.info(__FILE__, __LINE__, message);
+
+#define LOGCMS_ERROR(logger, message)                               \
+   logger.error(__FILE__, __LINE__, message);
+
+#define LOGCMS_WARN(logger, message)                                \
+   logger.warn(__FILE__, __LINE__, message);
+
+#define LOGCMS_FATAL(logger, message)                               \
+   logger.fatal(__FILE__, __LINE__, message);
+
+
+#endif

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerHierarchy.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerHierarchy.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerHierarchy.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerHierarchy.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,32 @@
+/*
+* Copyright 2006 The Apache Software Foundation or its licensors, as
+* applicable.
+*
+* Licensed 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 "LoggerHierarchy.h"
+
+using namespace activemq;
+using namespace activemq::logger;
+
+////////////////////////////////////////////////////////////////////////////////
+LoggerHierarchy::LoggerHierarchy(void)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LoggerHierarchy::~LoggerHierarchy(void)
+{
+}
+

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerHierarchy.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerHierarchy.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerHierarchy.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LoggerHierarchy.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,41 @@
+/*
+* Copyright 2006 The Apache Software Foundation or its licensors, as
+* applicable.
+*
+* Licensed 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.
+*/
+#ifndef _ACTIVEMQ_LOGGER_LOGGERHIERARCHY_H_
+#define _ACTIVEMQ_LOGGER_LOGGERHIERARCHY_H_
+
+namespace activemq{
+namespace logger{
+
+    class LoggerHierarchy
+    {
+    public:
+
+        /**
+         * Default Constructor
+         */
+    	LoggerHierarchy(void);
+
+        /**
+         * Destructor
+         */
+    	virtual ~LoggerHierarchy(void);
+
+    };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_LOGGERHIERARCHY_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/MarkBlockLogger.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/MarkBlockLogger.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/MarkBlockLogger.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/MarkBlockLogger.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_LOGGER_MARKBLOCKLOGGER_H_
+#define _ACTIVEMQ_LOGGER_MARKBLOCKLOGGER_H_
+
+#include <activemq/logger/Logger.h>
+
+namespace activemq{
+namespace logger{
+
+   /**
+    * Defines a class that can be used to mark the entry and exit from
+    * scoped blocks.
+    * <p>
+    * Create an instance of this class at the start of a scoped block,
+    * passing it the logger to use and the name of the block.  The block
+    * entry and exit will be marked using the scope name, logger to the
+    * logger at the MARKBLOCK log level.
+    */
+   class MarkBlockLogger
+   {
+   private:
+   
+      // Pointer to the Logger to use for Logging
+      Logger* logger;
+      
+      // Block Name to Log
+      std::string blockName;
+      
+   public:
+
+      /**
+       * Constructor - Marks Block entry
+       * @param Logger to use
+       * @param Block name
+       */
+      MarkBlockLogger(Logger* logger, const std::string& blockName)
+      {
+         this->logger = logger;
+         this->blockName = blockName;
+         
+         logger.mark(blockName + " - Entered");
+      }
+
+      /**
+       * Destructor - Marks Block Exit
+       */
+      virtual ~MarkBlockLogger(void)
+      {
+         logger->mark(blockName + " - Exited");
+      }
+
+   };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_MARKBLOCKLOGGER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/PropertiesChangeListener.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/PropertiesChangeListener.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/PropertiesChangeListener.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/PropertiesChangeListener.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_LOGGER_PROPERTIESCHANGELISTENER_H_
+#define _ACTIVEMQ_LOGGER_PROPERTIESCHANGELISTENER_H_
+
+namespace activemq{
+namespace logger{
+
+   /**
+    * Defines the interface that classes can use to listen for change
+    * events on Properties.
+    */
+   class PropertiesChangeListener
+   {
+   public:
+   
+      /**
+       * Destructor
+       */
+      virtual ~PropertiesChangeListener() {}
+      
+      /**
+       * Change Event, called when a property is changed
+       * @param Name of the Property
+       * @param Old Value of the Property
+       * @param New Value of the Property
+       */
+      virtual void onPropertyChanged(const std::string& name,
+                                     const std::string& oldValue,
+                                     const std::string& newValue) = 0;
+
+   };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_PROPERTIESCHANGELISTENER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleFormatter.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleFormatter.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleFormatter.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleFormatter.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_LOGGER_SIMPLEFORMATTER_H_
+#define _ACTIVEMQ_LOGGER_SIMPLEFORMATTER_H_
+
+#include <activemq/logger/formatter.h>
+
+namespace activemq{
+namespace logger{
+
+   /**
+    * Print a brief summary of the LogRecord in a human readable format. 
+    * The summary will typically be 1 or 2 lines.
+    */
+   class SimpleFormatter : public Formatter
+   {
+   public:
+      
+      /**
+       * Constructor
+       */
+      SimpleFormatter(void) {}
+
+      /** 
+       * Destructor
+       */
+      virtual ~SimpleFormatter(void) {}
+
+      /**
+       * Format the given log record and return the formatted string.
+       * @param The Log Record to Format
+       */
+      virtual std::string format(const LogRecord& record) const
+      {
+         return "";
+      }
+      
+      /**
+       * Format the message string from a log record.
+       * @param The Log Record to Format
+       */
+      virtual std::string formatMessage(const LogRecord& record) const
+      {
+         return record.getMessage();
+      }
+      
+      /**
+       * Return the header string for a set of formatted records.  In the
+       * default implementation this method should return empty string
+       * @param the target handler, can be null
+       * @return empty string
+       */
+      virtual std::string getHead(const Handler* handler)
+      {
+         return "";
+      }
+
+      /**
+       * Return the tail string for a set of formatted records.  In the
+       * default implementation this method should return empty string
+       * @param the target handler, can be null
+       * @return empty string
+       */
+      virtual std::string getTail(const Handler* handler)
+      {
+         return "";
+      }
+
+   };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_SIMPLEFORMATTER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleLogger.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleLogger.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleLogger.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleLogger.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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 "SimpleLogger.h"
+
+#include <iostream>
+#include <activemq/logger/LogWriter.h>
+
+using namespace activemq;
+using namespace activemq::logger;
+using namespace activemq::concurrent;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+SimpleLogger::SimpleLogger(const std::string& name)
+{
+   this->name = name;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SimpleLogger::~SimpleLogger()
+{}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::mark(const std::string& message)
+{
+   LogWriter::getInstance().log("", 0, "", message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::debug(const std::string& file,
+                   const int          line,
+                   const std::string& message)
+{
+   LogWriter::getInstance().log(file, line, "DEBUG:", message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::info(const std::string& file,
+                  const int          line,
+                  const std::string& message)
+{
+   LogWriter::getInstance().log(file, line, "INFO:", message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::warn(const std::string& file,
+                  const int          line,
+                  const std::string& message)
+{
+   LogWriter::getInstance().log(file, line, "WARNING:", message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::error(const std::string& file,
+                   const int          line,
+                   const std::string& message)
+{
+   LogWriter::getInstance().log(file, line, "ERROR:", message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::fatal(const std::string& file,
+                   const int          line,
+                   const std::string& message)
+{
+   LogWriter::getInstance().log(file, line, "FATAL:", message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::log(const std::string& message)
+{
+   LogWriter::getInstance().log(message);
+}
+

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleLogger.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleLogger.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleLogger.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/SimpleLogger.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_LOGGER_SIMPLELOGGER_H_
+#define _ACTIVEMQ_LOGGER_SIMPLELOGGER_H_
+
+#include <string>
+
+namespace activemq{
+namespace logger{
+
+   class SimpleLogger
+   {
+   public:
+
+      /**
+       * Constructor
+       */   
+      SimpleLogger( const std::string& name );
+      
+      /**
+       * Destructor
+       */
+      virtual ~SimpleLogger();
+      
+      /**
+       * Log a Mark Block Level Log
+       */
+      virtual void mark(const std::string& message);
+
+      /**
+       * Log a Debug Level Log
+       */
+      virtual void debug(const std::string& file,
+                         const int          line,
+                         const std::string& message);
+
+      /**
+       * Log a Informational Level Log
+       */
+      virtual void info(const std::string& file,
+                        const int          line,
+                        const std::string& message);
+
+      /**
+       * Log a Warning Level Log
+       */
+      virtual void warn(const std::string& file,
+                        const int          line,
+                        const std::string& message);
+                        
+      /**
+       * Log a Error Level Log
+       */
+      virtual void error(const std::string& file,
+                         const int          line,
+                         const std::string& message);
+
+      /**
+       * Log a Fatal Level Log
+       */
+      virtual void fatal(const std::string& file,
+                         const int          line,
+                         const std::string& message);
+                         
+      /**
+       * No-frills log.
+       */
+      virtual void log(const std::string& message);
+                         
+   private:
+      
+      // Name of this Logger
+      std::string name;
+      
+   };
+   
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_SIMPLELOGGER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/StreamHandler.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/StreamHandler.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/StreamHandler.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/StreamHandler.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,228 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_LOGGER_STREAMHANDLER_H_
+#define _ACTIVEMQ_LOGGER_STREAMHANDLER_H_
+
+#include <activemq/logger/LoggerCommon.h>
+#include <activemq/logger/Handler.h>
+#include <activemq/logger/Formatter.h>
+#include <activemq/logger/Filter.h>
+#include <activemq/io/OutputStream.h>
+#include <activemq/exceptions/NullPointerException.h>
+#include <activemq/exceptions/InvalidStateException.h>
+#include <activemq/concurrent/Concurrent.h>
+
+namespace activemq{
+namespace logger{
+
+   class StreamHandler : public Handler
+   {
+   private:
+   
+      // OutputStream to write to
+      io::OutputStream* stream;
+      
+      // Formats this Handlers output
+      Formatter* formatter;
+      
+      // Filter object for Log Filtering
+      Filter* filter;
+
+   public:
+   
+      /**
+       * Create a StreamHandler, with no current output stream.
+       */
+      StreamHandler(void)
+      {
+         stream = NULL;
+         formatter = NULL;
+         filter = NULL;
+         
+         level = Level::FATAL;  // We take everything by default
+      }
+      
+      /**
+       * Create a StreamHandler, with no current output stream.
+       */
+      StreamHandler(io::OutputStream* stream, Formatter* formatter)
+      {
+         this->stream = stream;
+         this->formatter = formatter;
+         this->filter = NULL;
+         
+         level = Level::Fatal;  // We take everything by default
+      }
+
+      /**
+       * Destructor
+       */
+      virtual ~StreamHandler(void) 
+      {
+         try
+         {
+            close();
+         }
+         AMQ_CATCH_NOTHROW(exceptions::ActiveMQException)
+         AMQ_CATCALL_NOTHROW()
+      }
+
+      /**
+       * Close the current output stream.
+       * <p>
+       * The close method will perform a flush and then close the Handler. 
+       * After close has been called this Handler  should no longer be used. 
+       * Method calls may either be silently ignored or may throw runtime 
+       * exceptions.
+       * @throw CMSException
+       */
+      virtual void close(void) throw ( cms::CMSException )
+      {
+         if(stream)
+         {
+            stream.flush();
+            stream.close();
+         }
+      }
+      
+      /**
+       * Flush the Handler's output, clears any buffers.
+       */
+      virtual void flush(void)
+      {
+         if(stream)
+         {
+            stream->flush();
+         }
+      }
+      
+      /**
+       * Publish the Log Record to this Handler
+       * @param The Log Record to Publish
+       */
+      virtual void publish(const LogRecord& record)
+      {
+         try
+         {
+            if(!stream)
+            {
+               throw exceptions::NullPointerException(
+                  __FILE__, __LINE__,
+                  "StreamHandler::publish - Stream not set.");
+            }
+            
+            // Check if we should log this record
+            if(isLoggable(record))
+            {
+               std::string log = formatter->format(record);
+   
+               synchronized(stream)
+               {
+                  // Write the data to the stream
+                  stream->write(log.c_str(), log.length());
+               }
+            }
+         }
+         AMQ_CATCH_RETHROW( exceptions::ActiveMQException )
+         AMQ_CATCHALL_THROW( exceptions::ActiveMQException )
+      }
+      
+      /**
+       * Check if this Handler would actually log a given LogRecord.
+       * <p>
+       * 
+       * @param <code>LogRecord</code> to check
+       */
+      virtual void isLoggable(const LogRecord& record)
+      {
+         if(filter)
+         {
+            // Allow for some filtering to occurr
+            return filter->isLoggable(record));
+         }
+
+         // By default we want everything that is greater than or
+         // equal to the set level of this Handler.
+         return record.level >= level;
+      }
+      
+      /**
+       * Sets the Filter that this Handler uses to filter Log Records
+       * @param <code>Filter</code> derived instance
+       */
+      virtual void setFilter(const Filter* filter){
+         this->filter = filter;
+      }
+      
+      /**
+       * Gets the Filter that this Handler uses to filter Log Records
+       * @param <code>Filter</code> derived instance
+       */
+      virtual const Filter* getFilter(void){
+         return filter;
+      }
+      
+      /**
+       * Set the log level specifying which message levels will be logged 
+       * by this Handler.
+       * <p>
+       * The intention is to allow developers to turn on voluminous logging, 
+       * but to limit the messages that are sent to certain Handlers.
+       * @param Level enumeration value
+       */
+      virtual void setLevel(Level level){
+         this->level = level;
+      }
+      
+      /**
+       * Get the log level specifying which message levels will be logged 
+       * by this Handler.
+       * @param Level enumeration value
+       */
+      virtual Level getLevel(void){
+         return level;
+      }
+      
+      /**
+       * Sets the <code>Formatter</code> used by this Handler
+       * @param <code>Filter</code> derived instance
+       */
+      virtual void setFormatter(const Formatter* formatter){
+         this->formatter = formatter;
+      }
+      
+      /**
+       * Gets the <code>Formatter</code> used by this Handler
+       * @param <code>Filter</code> derived instance
+       */
+      virtual const Formatter* getFormatter(void){
+         return formatter;
+      }
+      
+      /**
+       * Gets the output Stream that this Handler is using
+       * @return OuputStream pointer
+       */
+      virtual io::OutputStream* getOutputStream(void) const(
+         return stream;
+      }
+
+   };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_STREAMHANDLER_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/BufferedSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/BufferedSocket.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/BufferedSocket.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/BufferedSocket.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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 "BufferedSocket.h"
+
+#include <activemq/exceptions/IllegalArgumentException.h>
+
+using namespace activemq;
+using namespace activemq::network;
+using namespace activemq::io;
+using namespace activemq::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedSocket::BufferedSocket(Socket* socket,
+                               unsigned int inputBufferSize,
+                               unsigned int outputBufferSize,
+                               bool own)
+{
+   if(socket == NULL)
+   {
+      throw IllegalArgumentException(
+         __FILE__, __LINE__,
+         "BufferedSocket::BufferedSocket - Constructed with NULL Socket");
+   }
+   
+   this->socket = socket;
+   this->inputBufferSize = inputBufferSize;
+   this->outputBufferSize = outputBufferSize;
+   this->own = own;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedSocket::~BufferedSocket(void)
+{
+   try
+   {
+      if(outputStream)
+      {
+         // Ensure all data is written
+         outputStream->flush();
+      }
+
+      // Close the socket      
+      socket->close();
+         
+      // if we own it, delete it.
+      if(own)
+      {
+         delete socket;
+      }
+      
+      // Clean up our streams.
+      delete inputStream;
+      delete outputStream;
+   }
+   AMQ_CATCH_NOTHROW( ActiveMQException )
+   AMQ_CATCHALL_NOTHROW( )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedSocket::connect( const char* host, const int port ) 
+   throw( SocketException )
+{
+   try
+   {      
+      if( socket->isConnected() )
+      {
+         throw SocketException( __FILE__, __LINE__, 
+               "BufferedSocket::connect() - socket already connected" );
+      }
+
+      // Connect the socket.
+      socket->connect( host, port );
+
+      // Now create the buffered streams that wrap around the socket.
+      inputStream = new BufferedInputStream( 
+         socket->getInputStream(), inputBufferSize );
+      outputStream = new BufferedOutputStream( 
+         socket->getOutputStream(), outputBufferSize );
+   }
+   AMQ_CATCH_RETHROW( SocketException )
+   AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, SocketException )
+   AMQ_CATCHALL_THROW( SocketException )   
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedSocket::close(void) throw( cms::CMSException )
+{
+   try
+   {
+      // Ensure all data writen
+      outputStream->flush();
+      
+      // Close the Socket
+      socket->close();
+      
+      // Remove old stream, recreate if reconnected
+      delete inputStream;
+      delete outputStream;
+      
+      inputStream = NULL;
+      outputStream = NULL;
+   }
+   AMQ_CATCH_RETHROW( SocketException )
+   AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, SocketException )
+   AMQ_CATCHALL_THROW( SocketException )   
+}

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/BufferedSocket.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/BufferedSocket.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/BufferedSocket.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/BufferedSocket.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_NETWORK_BUFFEREDSOCKET_H_
+#define _ACTIVEMQ_NETWORK_BUFFEREDSOCKET_H_
+
+#include <activemq/network/Socket.h>
+#include <activemq/network/SocketException.h>
+#include <activemq/io/BufferedInputStream.h>
+#include <activemq/io/BufferedOutputStream.h>
+
+namespace activemq{
+namespace network{
+
+   /**
+    * Buffered Socket class that wraps a <code>Socket</code> derived
+    * object and provides Buffered input and Output Streams to improce
+    * the efficiency of the reads and writes.
+    */
+   class BufferedSocket : public Socket
+   {
+   private:
+   
+      // Socket that this class wraps to provide buffering
+      Socket* socket;
+      
+      // Indicates if the lifetime of the Socket is controlled by this 
+      // class.  If true Socket is deleted at destruction.
+      bool own;
+      
+      // Buffered Input stream to wrap the Socket input stream
+      io::BufferedInputStream* inputStream;
+      
+      // Buffered Output stream to wrap the Socket input stream
+      io::BufferedOutputStream* outputStream;
+      
+      // Sizes for the Buffered Streams
+      unsigned int inputBufferSize;
+      unsigned int outputBufferSize;
+
+   public:
+
+      /**
+       * Constructor
+       */
+   	BufferedSocket(Socket* socket, 
+                     unsigned int inputBufferSize = 1000,
+                     unsigned int outputBufferSize = 1000,
+                     bool own = true);
+
+      /**
+       * Destructor
+       */
+   	virtual ~BufferedSocket(void);
+
+       /**
+       * Connects to the specified destination. Closes this socket if 
+       * connected to another destination.
+       * @param host The host of the server to connect to.
+       * @param port The port of the server to connect to.
+       * @throws IOException Thrown if a failure occurred in the connect.
+       */
+      virtual void connect( const char* host, const int port ) 
+         throw(SocketException);
+      
+      /**
+       * Closes this object and deallocates the appropriate resources.
+       * @throws CMSException
+       */
+      virtual void close() throw( cms::CMSException );
+
+      /**
+       * Indicates whether or not this socket is connected to a destination.
+       */
+      virtual bool isConnected() const{
+         return socket->isConnected();
+      }
+
+      /**
+       * Gets the InputStream for this socket.
+       * @return The InputStream for this socket. NULL if not connected.
+       */
+      virtual io::InputStream* getInputStream(){
+         return inputStream;
+      }
+      
+      /**
+       * Gets the OutputStream for this socket.
+       * @return the OutputStream for this socket.  NULL if not connected.
+       */
+      virtual io::OutputStream* getOutputStream(){
+         return outputStream;
+      }
+
+      /**
+       * Gets the linger time.
+       * @return The linger time in seconds.
+       * @throws SocketException if the operation fails.
+       */
+      virtual int getSoLinger() const throw(SocketException){
+         return socket->getSoLinger();
+      }
+      
+      /**
+       * Sets the linger time.
+       * @param linger The linger time in seconds.  If 0, linger is off.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setSoLinger( const int linger ) throw(SocketException){
+         socket->setSoLinger(linger);
+      }
+      
+      /**
+       * Gets the keep alive flag.
+       * @return True if keep alive is enabled.
+       * @throws SocketException if the operation fails.
+       */
+      virtual bool getKeepAlive() const throw(SocketException){
+         return socket->getKeepAlive();
+      }
+      
+      /**
+       * Enables/disables the keep alive flag.
+       * @param keepAlive If true, enables the flag.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setKeepAlive( const bool keepAlive ) throw(SocketException){
+         socket->setKeepAlive(keepAlive);
+      }
+      
+      /**
+       * Gets the receive buffer size.
+       * @return the receive buffer size in bytes.
+       * @throws SocketException if the operation fails.
+       */
+      virtual int getReceiveBufferSize() const throw(SocketException){
+         return socket->getReceiveBufferSize();
+      }
+      
+      /**
+       * Sets the recieve buffer size.
+       * @param size Number of bytes to set the receive buffer to.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setReceiveBufferSize( const int size ) throw(SocketException){
+         socket->setReceiveBufferSize(size);
+      }
+      
+      /**
+       * Gets the reuse address flag.
+       * @return True if the address can be reused.
+       * @throws SocketException if the operation fails.
+       */
+      virtual bool getReuseAddress() const throw(SocketException){
+         return socket->getReuseAddress();
+      }
+      
+      /**
+       * Sets the reuse address flag.
+       * @param reuse If true, sets the flag.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setReuseAddress( const bool reuse ) throw(SocketException){
+         socket->setReuseAddress(reuse);
+      }
+      
+      /**
+       * Gets the send buffer size.
+       * @return the size in bytes of the send buffer.
+       * @throws SocketException if the operation fails.
+       */
+      virtual int getSendBufferSize() const throw(SocketException){
+         return socket->getSendBufferSize();
+      }
+      
+      /**
+       * Sets the send buffer size.
+       * @param size The number of bytes to set the send buffer to.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setSendBufferSize( const int size ) throw(SocketException){
+         socket->setSendBufferSize(size);
+      }
+      
+      /**
+       * Gets the timeout for socket operations.
+       * @return The timeout in milliseconds for socket operations.
+       * @throws SocketException Thrown if unable to retrieve the information.
+       */
+      virtual int getSoTimeout() const throw(SocketException){
+         return socket->getSoTimeout();
+      }
+      
+      /**
+       * Sets the timeout for socket operations.
+       * @param timeout The timeout in milliseconds for socket operations.<p>
+       * @throws SocketException Thrown if unable to set the information.
+       */
+      virtual void setSoTimeout( const int timeout ) throw(SocketException){
+         socket->setSoTimeout(timeout);
+      }
+
+   };
+
+}}
+
+#endif /*_ACTIVEMQ_NETWORK_BUFFEREDSOCKET_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.cpp Mon Jul  3 04:51:36 2006
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#if defined(unix) && !defined(__CYGWIN__)
+   #include <unistd.h>
+   #include <netdb.h>
+   #include <fcntl.h>
+   #include <sys/file.h>
+   #include <sys/socket.h>
+   #include <netinet/in.h>
+   #include <arpa/inet.h>
+   extern int errno;
+#else
+   #include <Winsock2.h>
+   #include <Ws2tcpip.h> 
+   #include <sys/stat.h>
+   #define stat _stat
+   #ifdef errno
+   #undef errno
+   #endif
+   int errno;
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <assert.h>
+#include "ServerSocket.h"
+#include <errno.h>
+#include <string>
+
+using namespace activemq::network;
+
+#if !defined( unix ) || defined( __CYGWIN__ )
+
+   // Static socket initializer needed for winsock
+
+   ServerSocket::StaticServerSocketInitializer::StaticServerSocketInitializer () {
+       socketInitError = NULL;
+       const WORD version_needed = MAKEWORD(2,2); // lo-order byte: major version
+       WSAData temp;
+       if (WSAStartup(version_needed, &temp)){
+         clear();
+           socketInitError = new SocketException ( __FILE__, __LINE__,
+                "winsock.dll was not found");
+       }
+   }
+   ServerSocket::StaticServerSocketInitializer::~StaticServerSocketInitializer () {
+      clear();
+      WSACleanup();
+   }
+   
+   // Create static instance of the socket initializer.
+   ServerSocket::StaticServerSocketInitializer 
+      ServerSocket::staticSocketInitializer;
+   
+#endif
+
+
+////////////////////////////////////////////////////////////////////////////////
+ServerSocket::ServerSocket()
+{
+   socketHandle = Socket::INVALID_SOCKET_HANDLE;
+   
+#if !defined( unix ) || defined( __CYGWIN__ )
+   if (ServerSocket::staticSocketInitializer.getSocketInitError() != NULL) {
+      throw *ServerSocket::staticSocketInitializer.getSocketInitError();
+   }
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ServerSocket::~ServerSocket()
+{
+   // No shutdown, just close - dont want blocking destructor.
+   close();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServerSocket::bind (const char* host, int port) throw (SocketException)
+{
+   bind (host, port, SOMAXCONN);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServerSocket::bind (const char* host, int port, int backlog) throw (SocketException)
+{
+   if (isBound()) {
+      throw SocketException ( __FILE__, __LINE__, 
+         "ServerSocket::bind - Socket already bound" );
+   }
+    
+    // Create the socket.
+   socketHandle = ::socket(AF_INET, SOCK_STREAM, 0);
+   if (socketHandle < 0) {
+      socketHandle = Socket::INVALID_SOCKET_HANDLE;
+        throw SocketException( __FILE__, __LINE__, ::strerror( errno ));
+   }
+   
+   // Verify the port value.
+   if (port <= 0 || port > 65535) {
+      throw SocketException( __FILE__, __LINE__, 
+         "ServerSocket::bind - Port out of range: %d", port );
+   }
+    
+    
+   sockaddr_in bind_addr;
+   bind_addr.sin_family = AF_INET;
+   bind_addr.sin_port = htons((short)port);
+   bind_addr.sin_addr.s_addr = 0; // To be set later down...
+   memset(&bind_addr.sin_zero, 0, sizeof(bind_addr.sin_zero));
+
+   // Resolve name
+   ::addrinfo hints;
+   memset(&hints, 0, sizeof(addrinfo));
+   hints.ai_family = PF_INET;
+   struct addrinfo *res_ptr = NULL;
+   int status = ::getaddrinfo(host, NULL, &hints, &res_ptr);
+   if( status != 0 || res_ptr == NULL) {
+       throw SocketException( __FILE__, __LINE__, ::strerror( errno ) );
+   }
+   assert(res_ptr->ai_addr->sa_family == AF_INET);
+   // Porting: On both 32bit and 64 bit systems that we compile to soo far, sin_addr is a 32 bit value, not an unsigned long.
+   assert(sizeof(((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr) == 4);
+   bind_addr.sin_addr.s_addr = ((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr;
+   freeaddrinfo(res_ptr);
+
+   // Set the socket to reuse the address.
+   int value = 1;
+   ::setsockopt(socketHandle, SOL_SOCKET, SO_REUSEADDR, (char*)&value, sizeof(int) );
+      
+   status = ::bind(socketHandle,
+             (sockaddr *)&bind_addr, sizeof(bind_addr));
+
+   if( status < 0 ){
+        close();
+      throw SocketException ( __FILE__, __LINE__, 
+            "ServerSocket::bind - %s", ::strerror( errno ) );
+   }
+   status = ::listen(socketHandle, backlog);
+   if (status < 0) {
+       close();
+       throw SocketException( __FILE__, __LINE__, ::strerror( errno ) );
+   }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServerSocket::close() throw (cms::CMSException){
+   
+   if (isBound()) {
+        
+      #if defined(unix) && !defined(__CYGWIN__)
+         ::close(socketHandle);
+      #else
+         ::closesocket(socketHandle);
+      #endif
+
+      socketHandle = Socket::INVALID_SOCKET_HANDLE;
+   }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ServerSocket::isBound() const {
+   return this->socketHandle != Socket::INVALID_SOCKET_HANDLE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* ServerSocket::accept () throw (SocketException)
+{
+   struct sockaddr_in temp;
+
+#if defined( unix ) && !defined( __CYGWIN__ )
+   socklen_t temp_len = sizeof (sockaddr_in);
+#else
+   int temp_len = sizeof (sockaddr_in);
+#endif
+
+   SocketHandle ss_socket_handle = 
+      ::accept(socketHandle, (struct sockaddr*)&temp, &temp_len);
+   if (ss_socket_handle < 0) {
+      throw SocketException( __FILE__, __LINE__, 
+         "ServerSocket::accept- %s", ::strerror( errno ) );
+   }
+    
+   return new TcpSocket(ss_socket_handle);
+}
+

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef ACTIVEMQ_NETWORK_SERVERSOCKETIMPL_H
+#define ACTIVEMQ_NETWORK_SERVERSOCKETIMPL_H
+
+#include <activemq/network/TcpSocket.h>
+#include <activemq/network/SocketException.h>
+
+namespace activemq{
+namespace network{
+
+	/**
+	 * A server socket class (for testing purposes).
+	 */
+	class ServerSocket
+	{
+	public:
+	
+	    typedef Socket::SocketHandle SocketHandle;
+	    
+	private:
+	
+	    SocketHandle socketHandle;
+	    
+	public:
+	
+	    /** 
+	     * Constructor.
+	     * Creates a non-bound server socket.
+	     */
+	    ServerSocket();
+	
+	    /**
+	     * Destructor.
+	     * Releases socket handle if close() hasn't been called.
+	     */
+	    virtual ~ServerSocket();
+	    
+	public:
+	
+	    /**
+	     * Bind and listen to given IP/dns and port.
+	     * @param host IP address or host name.
+	     * @param port TCP port between 1..655535
+	     */
+	    virtual void bind (const char* host, int port) throw (SocketException);
+	
+	    /**
+	     * Bind and listen to given IP/dns and port.
+	     * @param host IP address or host name.
+	     * @param port TCP port between 1..655535
+	     * @param backlog Size of listen backlog.
+	     */
+	    virtual void bind (const char* host, int port, int backlog) throw (SocketException);
+	
+	    /**
+	     * Blocks until a client connects to the bound socket.
+	     * @return new socket. Never returns NULL.
+	     */
+	    virtual Socket* accept () throw (SocketException);
+	
+	    /**
+	     * Closes the server socket.
+	     */
+	    virtual void close() throw(cms::CMSException);
+	
+	    /**
+	     * @return true of the server socket is bound.
+	     */ 
+	    virtual bool isBound() const;
+       
+   protected:
+
+      #if !defined( unix ) || defined( __CYGWIN__ )
+      
+          // WINDOWS needs initialization of winsock
+          class StaticServerSocketInitializer {
+          private:
+          
+              SocketException* socketInitError;
+              
+              void clear(){
+               if( socketInitError != NULL ){
+                  delete socketInitError;
+               }
+               socketInitError = NULL;
+              }
+              
+          public:
+              SocketException* getSocketInitError () {
+                  return socketInitError;
+              }
+              StaticServerSocketInitializer();
+              virtual ~StaticServerSocketInitializer ();
+                      
+          };
+          static StaticServerSocketInitializer staticSocketInitializer;
+      #endif
+      
+   };
+
+}}
+
+#endif // ACTIVEMQ_NETWORK_SERVERSOCKETIMPL_H
+

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/Socket.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/Socket.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/Socket.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/Socket.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef _ACTIVEMQ_NETWORK_SOCKET_H_
+#define _ACTIVEMQ_NETWORK_SOCKET_H_
+
+#include <activemq/network/SocketException.h>
+#include <activemq/io/InputStream.h>
+#include <activemq/io/OutputStream.h>
+#include <cms/Closeable.h>
+
+#if !defined( unix ) || defined( __CYGWIN__ )
+#include <Winsock2.h> // SOCKET
+#endif
+
+namespace activemq{
+namespace network{
+
+   class Socket : public cms::Closeable
+   {
+   public:
+   
+      // Define the SocketHandle type.
+      #if defined( unix ) && !defined( __CYGWIN__ )
+          typedef int SocketHandle;
+      #else
+          typedef SOCKET SocketHandle;
+      #endif
+
+      /**
+       * Defines a constant for an invalid socket handle.
+       */   
+       static const SocketHandle INVALID_SOCKET_HANDLE = (SocketHandle) -1;
+
+   public:
+
+      /**
+       * Destructor
+       */
+   	virtual ~Socket(void) {}
+
+       /**
+       * Connects to the specified destination. Closes this socket if 
+       * connected to another destination.
+       * @param host The host of the server to connect to.
+       * @param port The port of the server to connect to.
+       * @throws IOException Thrown if a failure occurred in the connect.
+       */
+      virtual void connect( const char* host, const int port ) 
+         throw(SocketException) = 0;
+      
+      /**
+       * Indicates whether or not this socket is connected to a destination.
+       */
+      virtual bool isConnected() const = 0;      
+
+      /**
+       * Gets the InputStream for this socket.
+       * @return The InputStream for this socket. NULL if not connected.
+       */
+      virtual io::InputStream* getInputStream() = 0;
+      
+      /**
+       * Gets the OutputStream for this socket.
+       * @return the OutputStream for this socket.  NULL if not connected.
+       */
+      virtual io::OutputStream* getOutputStream() = 0;
+
+      /**
+       * Gets the linger time.
+       * @return The linger time in seconds.
+       * @throws SocketException if the operation fails.
+       */
+      virtual int getSoLinger() const throw(SocketException) = 0;
+      
+      /**
+       * Sets the linger time.
+       * @param linger The linger time in seconds.  If 0, linger is off.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setSoLinger( const int linger ) throw(SocketException) = 0;
+      
+      /**
+       * Gets the keep alive flag.
+       * @return True if keep alive is enabled.
+       * @throws SocketException if the operation fails.
+       */
+      virtual bool getKeepAlive() const throw(SocketException) = 0;
+      
+      /**
+       * Enables/disables the keep alive flag.
+       * @param keepAlive If true, enables the flag.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setKeepAlive( const bool keepAlive ) throw(SocketException) = 0;
+      
+      /**
+       * Gets the receive buffer size.
+       * @return the receive buffer size in bytes.
+       * @throws SocketException if the operation fails.
+       */
+      virtual int getReceiveBufferSize() const throw(SocketException) = 0;
+      
+      /**
+       * Sets the recieve buffer size.
+       * @param size Number of bytes to set the receive buffer to.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setReceiveBufferSize( const int size ) throw(SocketException) = 0;
+      
+      /**
+       * Gets the reuse address flag.
+       * @return True if the address can be reused.
+       * @throws SocketException if the operation fails.
+       */
+      virtual bool getReuseAddress() const throw(SocketException) = 0;
+      
+      /**
+       * Sets the reuse address flag.
+       * @param reuse If true, sets the flag.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setReuseAddress( const bool reuse ) throw(SocketException) = 0;
+      
+      /**
+       * Gets the send buffer size.
+       * @return the size in bytes of the send buffer.
+       * @throws SocketException if the operation fails.
+       */
+      virtual int getSendBufferSize() const throw(SocketException) = 0;
+      
+      /**
+       * Sets the send buffer size.
+       * @param size The number of bytes to set the send buffer to.
+       * @throws SocketException if the operation fails.
+       */
+      virtual void setSendBufferSize( const int size ) throw(SocketException) = 0;
+      
+      /**
+       * Gets the timeout for socket operations.
+       * @return The timeout in milliseconds for socket operations.
+       * @throws SocketException Thrown if unable to retrieve the information.
+       */
+      virtual int getSoTimeout() const throw(SocketException) = 0;
+      
+      /**
+       * Sets the timeout for socket operations.
+       * @param timeout The timeout in milliseconds for socket operations.<p>
+       * @throws SocketException Thrown if unable to set the information.
+       */
+      virtual void setSoTimeout( const int timeout ) throw(SocketException) = 0;
+
+   };
+
+}}
+
+#endif /*_ACTIVEMQ_NETWORK_BASESOCKET_H_*/

Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/SocketException.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/SocketException.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/SocketException.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/network/SocketException.h Mon Jul  3 04:51:36 2006
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+#ifndef ACTIVEMQ_NETWORK_SOCKETEXCEPTION_H
+#define ACTIVEMQ_NETWORK_SOCKETEXCEPTION_H
+
+#include <activemq/io/IOException.h>
+
+namespace activemq{
+namespace network{
+
+	/**
+	 * Exception for errors when manipulating sockets.
+	 */
+	class SocketException : public io::IOException
+	{
+	public:
+	
+		SocketException(){}
+        SocketException( const ActiveMQException& ex ){
+            *(ActiveMQException*)this = ex;
+        }
+        SocketException( const SocketException& ex ){
+            *(ActiveMQException*)this = ex;
+        }
+	    SocketException(const char* file, const int lineNumber, 
+            const char* msg, ...)
+	    {
+	        va_list vargs ;
+            va_start(vargs, msg) ;
+            buildMessage(msg, vargs) ;
+            
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+	    }
+        
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         */
+        virtual ActiveMQException* clone() const{
+            return new SocketException( *this );
+        }
+        
+	    virtual ~SocketException(){}
+	} ;
+
+}}
+
+
+#endif // ACTIVEMQ_NETWORK_SOCKETEXCEPTION_H
+