You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/05/31 13:56:03 UTC
svn commit: r543121 [3/6] - in /activemq/activemq-cpp/trunk/src/decaf: io/
lang/ lang/exceptions/ net/ util/ util/concurrent/ util/logging/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Exception.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Exception.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Exception.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Exception.h Thu May 31 04:55:59 2007
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTION_EXCEPTION_H_
+#define _DECAF_LANG_EXCEPTION_EXCEPTION_H_
+
+#include <decaf/lang/Throwable.h>
+#include <decaf/lang/exceptions/ExceptionDefines.h>
+#include <stdarg.h>
+#include <sstream>
+
+namespace decaf{
+namespace lang{
+
+ /*
+ * Base class for all exceptions.
+ */
+ class Exception : public Throwable
+ {
+ private:
+
+ /**
+ * The cause of this exception.
+ */
+ std::string message;
+
+ /**
+ * The stack trace.
+ */
+ std::vector< std::pair< std::string, int> > stackTrace;
+
+ public:
+
+ /**
+ * Default Constructor
+ */
+ Exception() throw();
+
+ /**
+ * Copy Constructor
+ */
+ Exception( const Exception& ex ) throw();
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ Exception( const char* file, const int lineNumber,
+ const char* msg, ... ) throw();
+
+ virtual ~Exception() throw();
+
+ /**
+ * Gets the message for this exception.
+ * @return Text formatted error message
+ */
+ virtual std::string getMessage() const{
+ return message;
+ }
+
+ /**
+ * Implement method from std::exception
+ * @return the const char* of <code>getMessage()</code>.
+ */
+ virtual const char* what() const throw (){
+ return message.c_str();
+ }
+
+ /**
+ * Sets the cause for this exception.
+ * @param msg the format string for the msg.
+ * @param variable - params to format into the string
+ */
+ virtual void setMessage( const char* msg, ... );
+
+ /**
+ * Adds a file/line number to the stack trace.
+ * @param file The name of the file calling this method (use __FILE__).
+ * @param lineNumber The line number in the calling file (use __LINE__).
+ */
+ virtual void setMark( const char* file, const int 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.
+ * @return Copy of this Exception object
+ */
+ virtual Exception* clone() const;
+
+ /**
+ * Provides the stack trace for every point where
+ * this exception was caught, marked, and rethrown. The first
+ * item in the returned vector is the first point where the mark
+ * was set (e.g. where the exception was created).
+ * @return the stack trace.
+ */
+ virtual std::vector< std::pair< std::string, int> > getStackTrace() const;
+
+ /**
+ * Prints the stack trace to std::err
+ */
+ virtual void printStackTrace() const;
+
+ /**
+ * Prints the stack trace to the given output stream.
+ * @param stream the target output stream.
+ */
+ virtual void printStackTrace( std::ostream& stream ) const;
+
+ /**
+ * Gets the stack trace as one contiguous string.
+ * @return string with formatted stack trace data
+ */
+ virtual std::string getStackTraceString() const;
+
+ /**
+ * Assignment operator.
+ * @param const reference to another Exception
+ */
+ virtual Exception& operator =( const Exception& ex );
+
+ protected:
+
+ virtual void buildMessage( const char* format, va_list& vargs );
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_EXCEPTION_EXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Integer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Integer.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Integer.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Integer.h Thu May 31 04:55:59 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_INTEGER_H_
+#define _DECAF_LANG_INTEGER_H_
+
+#include <decaf/lang/Number.h>
+
+namespace decaf{
+namespace lang{
+
+ class Integer : public Number
+ {
+ public:
+
+ Integer() {}
+ virtual ~Integer() {}
+
+ /**
+ * Parses the String passed and extracts an int.
+ * @param String to parse
+ * @return int value
+ */
+ static int parseInt( const std::string& value ){
+ int ret = 0;
+ std::istringstream istream(value);
+ istream.clear();
+ istream >> ret;
+ return ret;
+ }
+
+ /**
+ * Converts the int to a String representation
+ * @param int to convert
+ * @return string representation
+ */
+ static std::string toString( int value ){
+ std::ostringstream ostream;
+ ostream << value;
+ return ostream.str();
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_INTEGER_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Long.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Long.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Long.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Long.h Thu May 31 04:55:59 2007
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_LONG_H_
+#define _DECAF_LANG_LONG_H_
+
+#include <decaf/lang/Number.h>
+
+namespace decaf{
+namespace lang{
+
+ class Long : public Number{
+ public:
+
+ Long() {}
+ virtual ~Long() {}
+
+ /**
+ * Parses the String passed and extracts an long.
+ * @param String to parse
+ * @return long value
+ */
+ static long long parseLong( const std::string& value ){
+ long long ret = 0;
+ std::istringstream istream(value);
+ istream.clear();
+ istream >> ret;
+ return ret;
+ }
+
+ /**
+ * Converts the long to a String representation
+ * @param long to convert
+ * @return string representation
+ */
+ static std::string toString( long long value ){
+ std::ostringstream ostream;
+ ostream << value;
+ return ostream.str();
+ }
+ };
+
+}}
+
+#endif /*_DECAF_LANG_LONG_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Math.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Math.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Math.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Math.h Thu May 31 04:55:59 2007
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_MATH_H_
+#define _DECAF_LANG_MATH_H_
+
+#undef min
+#undef max
+
+namespace decaf{
+namespace lang{
+
+ /**
+ * The class <code>Math</code> contains methods for performing basic
+ * numeric operations such as the elementary exponential, logarithm,
+ * square root, and trigonometric functions.
+ */
+ class Math
+ {
+ public:
+
+ Math();
+ virtual ~Math();
+
+ public:
+
+ /**
+ * Returns the smaller of two <code>short</code> values. That is,
+ * the result the argument closer to the value of
+ * <code>Short::MIN_VALUE</code>. If the arguments have the same
+ * value, the result is that same value.
+ * @param a - an argument.
+ * @param b - another argument.
+ * @return the smaller of <code>a</code> and <code>b</code>.
+ */
+ static short min( short a, short b ) {
+ return ( a <= b ? a : b );
+ }
+
+ /**
+ * Returns the smaller of two <code>int</code> values. That is,
+ * the result the argument closer to the value of
+ * <code>Integer::MIN_VALUE</code>. If the arguments have the same
+ * value, the result is that same value.
+ * @param a - an argument.
+ * @param b - another argument.
+ * @return the smaller of <code>a</code> and <code>b</code>.
+ */
+ static int min( int a, int b ) {
+ return ( a <= b ? a : b );
+ }
+
+ /**
+ * Returns the larger of two <code>short</code> values. That is,
+ * the result the argument closer to the value of
+ * <code>Short::MAX_VALUE</code>. If the arguments have the same
+ * value, the result is that same value.
+ * @param a - an argument.
+ * @param b - another argument.
+ * @return the larger of <code>a</code> and <code>b</code>.
+ */
+ static short max( short a, short b ) {
+ return ( a >= b ? a : b );
+ }
+
+ /**
+ * Returns the larger of two <code>int</code> values. That is,
+ * the result the argument closer to the value of
+ * <code>Integer::MAX_VALUE</code>. If the arguments have the same
+ * value, the result is that same value.
+ * @param a - an argument.
+ * @param b - another argument.
+ * @return the larger of <code>a</code> and <code>b</code>.
+ */
+ static int max( int a, int b ) {
+ return ( a >= b ? a : b );
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_MATH_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Number.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Number.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Number.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Number.h Thu May 31 04:55:59 2007
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_NUMBER_H_
+#define _DECAF_LANG_NUMBER_H_
+
+#include <sstream>
+
+namespace decaf{
+namespace lang{
+
+ /**
+ * The abstract class Number is the superclass of classes Byte, Double,
+ * Float, Integer, Long, and Short.
+ *
+ * Subclasses of Number must provide methods to convert the represented
+ * numeric value to byte, double, float, int, long, and short.
+ */
+ class Number {
+ public:
+
+ virtual ~Number() {}
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_NUMBER_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Runnable.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Runnable.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Runnable.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Runnable.h Thu May 31 04:55:59 2007
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_RUNNABLE_H_
+#define _DECAF_LANG_RUNNABLE_H_
+
+namespace decaf{
+namespace lang{
+
+ /**
+ * Interface for a runnable object - defines a task
+ * that can be run by a thread.
+ */
+ class Runnable{
+ public:
+
+ virtual ~Runnable(){}
+
+ /**
+ * Run method - called by the Thread class in the context
+ * of the thread.
+ */
+ virtual void run() = 0;
+ };
+
+}}
+
+#endif /*_DECAF_LANG_RUNNABLE_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Thread.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Thread.cpp?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Thread.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Thread.cpp Thu May 31 04:55:59 2007
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Thread.h"
+
+#ifdef HAVE_PTHREAD_H
+ #include <errno.h>
+#else
+ #include <process.h> // _endthreadex
+#endif
+
+#include <decaf/lang/Exception.h>
+#include <decaf/lang/exceptions/RuntimeException.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+Thread::Thread()
+{
+ task = this;
+ started = false;
+ joined = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Thread::Thread( Runnable* task )
+{
+ this->task = task;
+ started = false;
+ joined = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Thread::~Thread()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Thread::start() throw ( Exception )
+{
+ if (this->started) {
+ throw Exception( __FILE__, __LINE__,
+ "Thread already started");
+ }
+
+#ifdef HAVE_PTHREAD_H
+
+ ::pthread_attr_init (&attributes);
+ ::pthread_attr_setdetachstate (&attributes, PTHREAD_CREATE_JOINABLE);
+ int err = ::pthread_create (
+ &this->threadHandle,
+ &attributes,
+ runCallback,
+ this);
+ if (err != 0) {
+ throw Exception( __FILE__, __LINE__,
+ "Coud not start thread");
+ }
+
+#else
+
+ unsigned int threadId = 0;
+ this->threadHandle =
+ (HANDLE)::_beginthreadex(NULL, 0, runCallback, this, 0, &threadId);
+ if (this->threadHandle == NULL) {
+ throw Exception( __FILE__, __LINE__,
+ "Coud not start thread");
+ }
+
+#endif
+
+ // Mark the thread as started.
+ started = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Thread::join() throw( Exception )
+{
+ if (!this->started) {
+ throw Exception( __FILE__, __LINE__,
+ "Thread::join() called without having called Thread::start()");
+ }
+ if (!this->joined) {
+
+#ifdef HAVE_PTHREAD_H
+ ::pthread_join(this->threadHandle, NULL);
+#else
+ ::WaitForSingleObject (this->threadHandle, INFINITE);
+#endif
+
+ }
+ this->joined = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Thread::sleep( int millisecs )
+{
+#ifdef HAVE_PTHREAD_H
+ struct timespec rec, rem;
+ rec.tv_sec = millisecs / 1000;
+ rec.tv_nsec = (millisecs % 1000) * 1000000;
+ while( nanosleep( &rec, &rem ) == -1 ){
+ if( errno != EINTR ){
+ break;
+ }
+ }
+
+#else
+ ::Sleep (millisecs);
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned long Thread::getId(void)
+{
+ #ifdef HAVE_PTHREAD_H
+ return (long)(pthread_self());
+ #else
+ return GetCurrentThreadId();
+ #endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+#ifdef HAVE_PTHREAD_H
+ void*
+#else
+ unsigned int WINAPI
+#endif
+Thread::runCallback( void* param )
+{
+ // Get the instance.
+ Thread* thread = (Thread*)param;
+
+ // Invoke run on the task.
+ try{
+ thread->task->run();
+ } catch( ... ){
+ RuntimeException ex(__FILE__, __LINE__, "unhandled exception bubbled up to Thread::run");
+ ex.printStackTrace();
+ }
+
+#ifdef HAVE_PTHREAD_H
+ ::pthread_attr_destroy( &thread->attributes );
+ return NULL;
+#else
+
+ // Needed when using threads and CRT in Windows. Otherwise memleak can appear.
+ ::_endthreadex(0);
+
+ // _endthreadex (unlike _endthread) does not automatically close the thread handle
+ // so we need to do this manually.
+ ::CloseHandle(thread->threadHandle);
+
+ return 0;
+#endif
+}
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Thread.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Thread.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Thread.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Thread.h Thu May 31 04:55:59 2007
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_THREAD_H_
+#define _DECAF_LANG_THREAD_H_
+
+#include <decaf/lang/Exception.h>
+#include <decaf/lang/Runnable.h>
+#include <decaf/util/Config.h>
+#include <stdexcept>
+#include <assert.h>
+
+#ifdef HAVE_PTHREAD_H
+ #include <pthread.h>
+#else
+ #include <windows.h>
+#endif
+
+namespace decaf{
+namespace lang{
+
+ /**
+ * Basic thread class - mimics the Java Thread. Derived classes may
+ * implement the run method, or this class can be used as is with
+ * a provided Runnable delegate.
+ */
+ class Thread : public Runnable
+ {
+ private:
+
+ /**
+ * The task to be run by this thread, defaults to
+ * this thread object.
+ */
+ Runnable* task;
+
+ #ifdef HAVE_PTHREAD_H
+ pthread_attr_t attributes;
+ pthread_t threadHandle;
+ #else
+ HANDLE threadHandle;
+ #endif
+
+ /**
+ * Started state of this thread.
+ */
+ bool started;
+
+ /**
+ * Indicates whether the thread has already been
+ * joined.
+ */
+ bool joined;
+
+ public:
+
+ /**
+ * default Constructor
+ */
+ Thread();
+
+ /**
+ * Constructor
+ * @param task the Runnable that this thread manages
+ */
+ Thread( Runnable* task );
+
+ virtual ~Thread();
+
+ /**
+ * Creates a system thread and starts it in a joinable mode.
+ * Upon creation, the
+ * run() method of either this object or the provided Runnable
+ * object will be invoked in the context of this thread.
+ * @exception runtime_error is thrown if the system could
+ * not start the thread.
+ */
+ virtual void start() throw ( Exception );
+
+ /**
+ * Wait til the thread exits. This is when the run()
+ * method has returned or has thrown an exception.
+ */
+ virtual void join() throw ( Exception );
+
+ /**
+ * Default implementation of the run method - does nothing.
+ */
+ virtual void run(){};
+
+ public:
+
+ /**
+ * Halts execution of the calling thread for a specified no of millisec.
+ *
+ * Note that this method is a static method that applies to the
+ * calling thread and not to the thread object.
+ * @param millisecs time in milliseconds to sleep
+ */
+ static void sleep( int millisecs );
+
+ /**
+ * Obtains the Thread Id of the current thread
+ * @return Thread Id
+ */
+ static unsigned long getId(void);
+
+ private:
+
+ // Internal thread handling
+ #ifdef HAVE_PTHREAD_H
+ static void* runCallback (void* param);
+ #else
+ static unsigned int WINAPI runCallback (void* param);
+ #endif
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_THREAD_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Throwable.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Throwable.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Throwable.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Throwable.h Thu May 31 04:55:59 2007
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_THROWABLE_H_
+#define _DECAF_LANG_THROWABLE_H_
+
+// Includes
+#include <string>
+#include <vector>
+#include <iostream>
+#include <exception>
+
+namespace decaf{
+namespace lang{
+
+ /**
+ * This class represents an error that has occurred.
+ */
+ class Throwable : public std::exception {
+
+ public:
+
+ Throwable() throw() {}
+
+ virtual ~Throwable() throw() {}
+
+ /**
+ * Gets the cause of the error.
+ * @return string errors message
+ */
+ virtual std::string getMessage() const = 0;
+
+ /**
+ * Adds a file/line number to the stack trace.
+ * @param file The name of the file calling this method (use __FILE__).
+ * @param lineNumber The line number in the calling file (use __LINE__).
+ */
+ virtual void setMark( const char* file, const int lineNumber ) = 0;
+
+ /**
+ * 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.
+ * @return Copy of this Exception object
+ */
+ virtual Throwable* clone() const = 0;
+
+ /**
+ * Provides the stack trace for every point where
+ * this exception was caught, marked, and rethrown.
+ * @return vector containing stack trace strings
+ */
+ virtual std::vector< std::pair< std::string, int> > getStackTrace() const = 0;
+
+ /**
+ * Prints the stack trace to std::err
+ */
+ virtual void printStackTrace() const = 0;
+
+ /**
+ * Prints the stack trace to the given output stream.
+ * @param stream the target output stream.
+ */
+ virtual void printStackTrace( std::ostream& stream ) const = 0;
+
+ /**
+ * Gets the stack trace as one contiguous string.
+ * @return string with formatted stack trace data
+ */
+ virtual std::string getStackTraceString() const = 0;
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_THROWABLE_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/ExceptionDefines.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/ExceptionDefines.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/ExceptionDefines.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/ExceptionDefines.h Thu May 31 04:55:59 2007
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_EXCEPTIONS_EXCEPTIONDEFINES_H_
+#define _DECAF_LANG_EXCEPTIONS_EXCEPTIONDEFINES_H_
+
+/**
+ * Macro for catching and rethrowing an exception of
+ * a given type.
+ * @param type The type of the exception to throw
+ * (e.g. Exception ).
+ */
+#define DECAF_CATCH_RETHROW( type ) \
+ catch( type& ex ){ \
+ ex.setMark( __FILE__, __LINE__ ); \
+ throw ex; \
+ }
+
+/**
+ * Macro for catching an exception of one type and then rethrowing
+ * as another type.
+ * @param sourceType the type of the exception to be caught.
+ * @param targetType the type of the exception to be thrown.
+ */
+#define DECAF_CATCH_EXCEPTION_CONVERT( sourceType, targetType ) \
+ catch( sourceType& ex ){ \
+ targetType target( ex ); \
+ target.setMark( __FILE__, __LINE__ ); \
+ throw target; \
+ }
+
+/**
+ * A catch-all that throws a known exception.
+ * @param type the type of exception to be thrown.
+ */
+#define DECAF_CATCHALL_THROW( type ) \
+ catch( ... ){ \
+ type ex( __FILE__, __LINE__, \
+ "caught unknown exception" ); \
+ throw ex; \
+ }
+
+/**
+ * A catch-all that does not throw an exception, one use would
+ * be to catch any exception in a destructor and mark it, but not
+ * throw so that cleanup would continue as normal.
+ */
+#define DECAF_CATCHALL_NOTHROW( ) \
+ catch( ... ){ \
+ lang::Exception ex( __FILE__, __LINE__, \
+ "caught unknown exception, not rethrowing" ); \
+ }
+
+/**
+ * Macro for catching and rethrowing an exception of
+ * a given type.
+ * @param type The type of the exception to throw
+ * (e.g. Exception ).
+ */
+#define DECAF_CATCH_NOTHROW( type ) \
+ catch( type& ex ){ \
+ ex.setMark( __FILE__, __LINE__ ); \
+ }
+
+#endif /*_DECAF_LANG_EXCEPTIONS_EXCEPTIONDEFINES_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalArgumentException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalArgumentException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalArgumentException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalArgumentException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_ILLEGALARGUMENTEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_ILLEGALARGUMENTEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown when an illegal argument was passed into a method.
+ */
+ class IllegalArgumentException : public Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ IllegalArgumentException() throw() {}
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ IllegalArgumentException( const Exception& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ IllegalArgumentException( const IllegalArgumentException& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ IllegalArgumentException(const char* file, const int lineNumber,
+ const char* msg, ...) throw()
+ : Exception()
+ {
+ 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 Exception* clone() const{
+ return new IllegalArgumentException( *this );
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~IllegalArgumentException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_ILLEGALARGUMENTEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalMonitorStateException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalMonitorStateException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalMonitorStateException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalMonitorStateException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_ILLEGALMONITORSTATEEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_ILLEGALMONITORSTATEEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown when an error occurs from calling a method from syncronizable
+ * and the caller doesn't hold a lock on the object.
+ */
+ class IllegalMonitorStateException : public Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ IllegalMonitorStateException() throw() {};
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ IllegalMonitorStateException(const Exception& ex) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ IllegalMonitorStateException(const IllegalMonitorStateException& ex) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ IllegalMonitorStateException( const char* file,
+ const int lineNumber,
+ const char* msg, ...) throw()
+ {
+ 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 IllegalMonitorStateException* clone() const{
+ return new IllegalMonitorStateException(*this);
+ }
+
+ virtual ~IllegalMonitorStateException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_ILLEGALMONITORSTATEEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalStateException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalStateException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalStateException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IllegalStateException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_ILLEGALSTATEEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_ILLEGALSTATEEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown when an error occurs from calling a method from syncronizable
+ * and the caller doesn't hold a lock on the object.
+ */
+ class IllegalStateException : public Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ IllegalStateException() throw() {};
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ IllegalStateException(const Exception& ex) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ IllegalStateException(const IllegalStateException& ex) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ IllegalStateException( const char* file,
+ const int lineNumber,
+ const char* msg, ...) throw()
+ : Exception()
+ {
+ 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 IllegalStateException* clone() const{
+ return new IllegalStateException(*this);
+ }
+
+ virtual ~IllegalStateException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_ILLEGALSTATEEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IndexOutOfBoundsException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IndexOutOfBoundsException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IndexOutOfBoundsException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/IndexOutOfBoundsException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_INDEXOUTOFBOUNDSEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_INDEXOUTOFBOUNDSEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown when an illegal argument was passed into a method.
+ */
+ class IndexOutOfBoundsException : public Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ IndexOutOfBoundsException() throw() {}
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ IndexOutOfBoundsException( const Exception& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ IndexOutOfBoundsException( const IndexOutOfBoundsException& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ IndexOutOfBoundsException(const char* file, const int lineNumber,
+ const char* msg, ...) throw()
+ : Exception()
+ {
+ 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 IndexOutOfBoundsException* clone() const{
+ return new IndexOutOfBoundsException( *this );
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~IndexOutOfBoundsException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_INDEXOUTOFBOUNDSEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/InterruptedException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/InterruptedException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/InterruptedException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/InterruptedException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_INTERRUPTEDENTEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_INTERRUPTEDENTEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown when an Thread is interrupted during a wait.
+ */
+ class InterruptedException : public Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ InterruptedException() throw() {};
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ InterruptedException(const Exception& ex) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ InterruptedException(const InterruptedException& ex) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ InterruptedException( const char* file,
+ const int lineNumber,
+ const char* msg, ... ) throw()
+ : Exception()
+ {
+ 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 InterruptedException* clone() const{
+ return new InterruptedException(*this);
+ }
+
+ virtual ~InterruptedException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_INTERRUPTEDENTEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/InvalidStateException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/InvalidStateException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/InvalidStateException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/InvalidStateException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_INVALIDSTATEEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_INVALIDSTATEEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown when an operation is requested, but the state of the object
+ * servicing the request is not correct for that request.
+ */
+ class InvalidStateException : public Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ InvalidStateException() throw() {}
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ InvalidStateException(const Exception& ex) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ InvalidStateException( const InvalidStateException& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ InvalidStateException( const char* file,
+ const int lineNumber,
+ const char* msg, ... ) throw()
+ : Exception()
+ {
+ 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 InvalidStateException* clone() const{
+ return new InvalidStateException(*this);
+ }
+
+ virtual ~InvalidStateException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_INVALIDSTATEEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/NoSuchElementException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/NoSuchElementException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/NoSuchElementException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/NoSuchElementException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_NOSUCHELEMENTEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_NOSUCHELEMENTEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown from an operation that attempts to access some element that does
+ * not exist.
+ */
+ class NoSuchElementException : public Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ NoSuchElementException() throw() {};
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ NoSuchElementException( const Exception& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ NoSuchElementException( const NoSuchElementException& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ NoSuchElementException( const char* file,
+ const int lineNumber,
+ const char* msg, ... ) throw()
+ : Exception()
+ {
+ 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 NoSuchElementException* clone() const{
+ return new NoSuchElementException(*this);
+ }
+
+ virtual ~NoSuchElementException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_NOSUCHELEMENTEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/NullPointerException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/NullPointerException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/NullPointerException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/NullPointerException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_NULLPOINTERENTEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_NULLPOINTERENTEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown when an error occurs that involves a pointer being NULL
+ */
+ class NullPointerException : public Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ NullPointerException() throw() {};
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ NullPointerException( const Exception& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ NullPointerException(const NullPointerException& ex) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ NullPointerException( const char* file,
+ const int lineNumber,
+ const char* msg, ... ) throw()
+ : Exception()
+ {
+ 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 NullPointerException* clone() const{
+ return new NullPointerException( *this );
+ }
+
+ virtual ~NullPointerException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_NULLPOINTERENTEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/RuntimeException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/RuntimeException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/RuntimeException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/RuntimeException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_RUNTIMEENTEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_RUNTIMEENTEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown when an error occurs that involves something in the run time
+ * This could be a memory allocation exception or some other generally
+ * unrecoverable exception.
+ */
+ class RuntimeException : public Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ RuntimeException() throw() {};
+
+ /**
+ * Conversion Constructor from some other ActiveMQException
+ * @param An exception that should become this type of Exception
+ */
+ RuntimeException( const Exception& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ RuntimeException( const RuntimeException& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ RuntimeException( const char* file,
+ const int lineNumber,
+ const char* msg, ... ) throw()
+ : Exception()
+ {
+ 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 RuntimeException* clone() const{
+ return new RuntimeException( *this );
+ }
+
+ virtual ~RuntimeException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_RUNTIMEENTEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/UnsupportedOperationException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/UnsupportedOperationException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/UnsupportedOperationException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/exceptions/UnsupportedOperationException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_LANG_EXCEPTIONS_UNSUPPORTEDOPERATIONEXCEPTION_H_
+#define _DECAF_LANG_EXCEPTIONS_UNSUPPORTEDOPERATIONEXCEPTION_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace lang{
+namespace exceptions{
+
+ /*
+ * Thrown when an unsupported method is called.
+ */
+ class UnsupportedOperationException : public lang::Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ UnsupportedOperationException() throw() {};
+
+ /**
+ * Conversion Constructor from some other Exception
+ * @param An exception that should become this type of Exception
+ */
+ UnsupportedOperationException( const Exception& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ */
+ UnsupportedOperationException( const UnsupportedOperationException& ex ) throw()
+ : Exception()
+ {
+ *(Exception*)this = ex;
+ }
+
+ /**
+ * Constructor - Initializes the file name and line number where
+ * this message occured. Sets the message to report, using an
+ * optional list of arguments to parse into the message
+ * @param file name where exception occurs
+ * @param line number where the exception occurred.
+ * @param message to report
+ * @param list of primitives that are formatted into the message
+ */
+ UnsupportedOperationException( const char* file,
+ const int lineNumber,
+ const char* msg, ... ) throw()
+ : Exception()
+ {
+ 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 UnsupportedOperationException* clone() const{
+ return new UnsupportedOperationException( *this );
+ }
+
+ virtual ~UnsupportedOperationException() throw() {}
+
+ };
+
+}}}
+
+#endif /*_DECAF_LANG_EXCEPTIONS_UNSUPPORTEDOPERATIONEXCEPTION_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/net/BufferedSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/net/BufferedSocket.cpp?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/net/BufferedSocket.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/net/BufferedSocket.cpp Thu May 31 04:55:59 2007
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "BufferedSocket.h"
+
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedSocket::BufferedSocket( Socket* socket,
+ int inputBufferSize,
+ int outputBufferSize,
+ bool own ) :
+ socket(NULL),
+ own(false),
+ inputStream(NULL),
+ outputStream(NULL),
+ inputBufferSize(0),
+ outputBufferSize(0)
+{
+ if(inputBufferSize < 0 || outputBufferSize < 0 )
+ {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__,
+ "BufferedSocket::BufferedSocket - buffer sizes must be >=0! "
+ "Given input buffer size: %d, Given output buffer size: %d",
+ inputBufferSize,
+ outputBufferSize );
+ }
+
+ 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()
+{
+ try
+ {
+ close();
+ }
+ DECAF_CATCH_NOTHROW( Exception )
+ DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedSocket::connect( const char* host, 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(), (std::size_t)inputBufferSize );
+ outputStream = new BufferedOutputStream(
+ socket->getOutputStream(), (std::size_t)outputBufferSize );
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedSocket::close() throw( lang::Exception )
+{
+ try
+ {
+ if( outputStream != NULL )
+ {
+ // Ensure all data is written
+ outputStream->flush();
+
+ delete outputStream;
+ outputStream = NULL;
+ }
+
+ if( inputStream != NULL ){
+ delete inputStream;
+ inputStream = NULL;
+ }
+
+ if( socket != NULL ){
+ // Close the socket
+ try{
+ socket->close();
+ } catch( lang::Exception& ex ){ /* Absorb */ }
+
+ // if we own it, delete it.
+ if( own ) {
+ delete socket;
+ }
+ socket = NULL;
+ }
+ }
+ DECAF_CATCH_RETHROW( SocketException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, SocketException )
+ DECAF_CATCHALL_THROW( SocketException )
+}
Added: activemq/activemq-cpp/trunk/src/decaf/net/BufferedSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/net/BufferedSocket.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/net/BufferedSocket.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/net/BufferedSocket.h Thu May 31 04:55:59 2007
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_NET_BUFFEREDSOCKET_H_
+#define _DECAF_NET_BUFFEREDSOCKET_H_
+
+#include <decaf/net/Socket.h>
+#include <decaf/net/SocketException.h>
+#include <decaf/io/BufferedInputStream.h>
+#include <decaf/io/BufferedOutputStream.h>
+
+namespace decaf{
+namespace net{
+
+ /**
+ * 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
+ int inputBufferSize;
+ int outputBufferSize;
+
+ public:
+
+ /**
+ * Constructs a new Buffered socket object
+ * @param socket the socket to buffer
+ * @param inputBufferSize size of the input buffer
+ * @param outputBufferSize size of the output buffer
+ * @param own does this object own the passed socket
+ */
+ BufferedSocket( Socket* socket,
+ int inputBufferSize = 1000,
+ int outputBufferSize = 1000,
+ bool own = true );
+
+ virtual ~BufferedSocket();
+
+ /**
+ * 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, int port )
+ throw( SocketException );
+
+ /**
+ * Closes this object and deallocates the appropriate resources.
+ * @throws CMSException
+ */
+ virtual void close() throw( lang::Exception );
+
+ /**
+ * Indicates whether or not this socket is connected to a destination.
+ * @return true if connected
+ */
+ virtual bool isConnected() const{
+ if( socket == NULL ){
+ return false;
+ }
+
+ 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 ){
+ checkSocket();
+ 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( int linger ) throw( SocketException ){
+ checkSocket();
+ 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 ){
+ checkSocket();
+ 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( bool keepAlive ) throw( SocketException ){
+ checkSocket();
+ 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 ){
+ checkSocket();
+ 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( int size ) throw( SocketException ){
+ checkSocket();
+ 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 ){
+ checkSocket();
+ return socket->getReuseAddress();
+ }
+
+ /**
+ * Sets the reuse address flag.
+ * @param reuse If true, sets the flag.
+ * @throws SocketException if the operation fails.
+ */
+ virtual void setReuseAddress( bool reuse ) throw( SocketException ){
+ checkSocket();
+ 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 ){
+ checkSocket();
+ 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( int size ) throw( SocketException ){
+ checkSocket();
+ 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 ){
+ checkSocket();
+ 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( int timeout ) throw( SocketException ){
+ checkSocket();
+ socket->setSoTimeout( timeout );
+ }
+
+ private:
+
+ void checkSocket() const throw ( SocketException ) {
+ if( socket == NULL ) {
+ throw SocketException( __FILE__, __LINE__, "socket is NULL" );
+ }
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_BUFFEREDSOCKET_H_*/