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 [8/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/io/ByteArrayInputStream.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayInputStream.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayInputStream.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayInputStream.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,173 @@
+/*
+ * 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_IO_BYTEARRAYINPUTSTREAM_H_
+#define _ACTIVEMQ_IO_BYTEARRAYINPUTSTREAM_H_
+
+#include <activemq/io/InputStream.h>
+#include <activemq/concurrent/Mutex.h>
+#include <vector>
+#include <algorithm>
+
+namespace activemq{
+namespace io{
+
+ class ByteArrayInputStream : public InputStream
+ {
+ private:
+
+ /**
+ * The Array of Bytes to read from.
+ */
+ std::vector<unsigned char> buffer;
+
+ /**
+ * iterator to current position in buffer.
+ */
+ std::vector<unsigned char>::const_iterator pos;
+
+ /**
+ * Synchronization object.
+ */
+ concurrent::Mutex mutex;
+
+ public:
+
+ /**
+ * Constructor
+ */
+ ByteArrayInputStream(void);
+
+ /**
+ * Constructor
+ * @param initial byte array to use to read from
+ * @param the size of the buffer
+ */
+ ByteArrayInputStream( const unsigned char* buffer,
+ int bufferSize );
+
+ /**
+ * Destructor
+ */
+ virtual ~ByteArrayInputStream(void);
+
+ /**
+ * Sets the data that this reader uses, replaces any existing
+ * data and resets to beginning of the buffer.
+ * @param initial byte array to use to read from
+ * @param the size of the buffer
+ */
+ virtual void setByteArray( const unsigned char* buffer,
+ int bufferSize );
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void lock() throw(exceptions::ActiveMQException){
+ mutex.lock();
+ }
+
+ /**
+ * Unlocks the object.
+ * @throws ActiveMQException
+ */
+ virtual void unlock() throw(exceptions::ActiveMQException){
+ mutex.unlock();
+ }
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void wait() throw(exceptions::ActiveMQException){
+ mutex.wait();
+ }
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling. This wait will timeout after the specified time
+ * interval.
+ * @param time in millisecsonds to wait, or WAIT_INIFINITE
+ * @throws ActiveMQException
+ */
+ virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){
+ mutex.wait(millisecs);
+ }
+
+ /**
+ * Signals a waiter on this object that it can now wake
+ * up and continue. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void notify() throw(exceptions::ActiveMQException){
+ mutex.notify();
+ }
+
+ /**
+ * Signals the waiters on this object that it can now wake
+ * up and continue. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void notifyAll() throw(exceptions::ActiveMQException){
+ mutex.notifyAll();
+ }
+
+ /**
+ * Indcates the number of bytes avaialable.
+ * @return the sum of the amount of data avalable
+ * in the buffer and the data available on the target
+ * input stream.
+ */
+ virtual int available() const{
+ return distance(pos, buffer.end());
+ }
+
+ /**
+ * Reads a single byte from the buffer.
+ * @return The next byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual unsigned char read() throw (IOException);
+
+ /**
+ * Reads an array of bytes from the buffer.
+ * @param buffer (out) the target buffer.
+ * @param bufferSize the size of the output buffer.
+ * @return The number of bytes read.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual int read( unsigned char* buffer, const int bufferSize )
+ throw (IOException);
+
+ /**
+ * Closes the target input stream.
+ */
+ virtual void close() throw(cms::CMSException);
+
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_IO_BYTEARRAYINPUTSTREAM_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayOutputStream.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayOutputStream.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayOutputStream.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayOutputStream.cpp Mon Jul 3 04:51:36 2006
@@ -0,0 +1,62 @@
+/*
+ * 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 "ByteArrayOutputStream.h"
+#include <algorithm>
+
+using namespace activemq::io;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::close() throw(cms::CMSException)
+{
+ // Clear the Buffer
+ flush();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::flush() throw (IOException)
+{
+ // No Op
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::clear() throw (IOException)
+{
+ // Empty the contents of the buffer to the output stream.
+ buffer.clear();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::write( const unsigned char c )
+ throw (IOException)
+{
+ buffer.push_back( c );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::write( const unsigned char* buffer,
+ const int len )
+ throw (IOException)
+{
+ // Iterate until all the data is written.
+ for( int ix = 0; ix < len; ++ix)
+ {
+ this->buffer.push_back( buffer[ix] );
+ }
+}
+
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayOutputStream.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayOutputStream.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayOutputStream.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/ByteArrayOutputStream.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_IO_BYTEARRAYOUTPUTSTREAM_H_
+#define _ACTIVEMQ_IO_BYTEARRAYOUTPUTSTREAM_H_
+
+#include <activemq/io/OutputStream.h>
+#include <activemq/concurrent/Mutex.h>
+#include <vector>
+
+namespace activemq{
+namespace io{
+
+ class ByteArrayOutputStream : public OutputStream
+ {
+ private:
+
+ /**
+ * The Array of Bytes to read from.
+ */
+ std::vector<unsigned char> buffer;
+
+ /**
+ * Synchronization object.
+ */
+ concurrent::Mutex mutex;
+
+ public:
+
+ /**
+ * Constructor
+ */
+ ByteArrayOutputStream(void) {};
+
+ /**
+ * Destructor
+ */
+ virtual ~ByteArrayOutputStream(void) {};
+
+ /**
+ * Get a snapshot of the data
+ * @return pointer to the data
+ */
+ virtual const unsigned char* getByteArray(void) const
+ {
+ return &buffer[0];
+ }
+
+ /**
+ * Get the Size of the Internal Buffer
+ */
+ virtual int getByteArraySize(void) const
+ {
+ return buffer.size();
+ }
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void lock() throw(exceptions::ActiveMQException){
+ mutex.lock();
+ }
+
+ /**
+ * Unlocks the object.
+ * @throws ActiveMQException
+ */
+ virtual void unlock() throw(exceptions::ActiveMQException){
+ mutex.unlock();
+ }
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void wait() throw(exceptions::ActiveMQException){
+ mutex.wait();
+ }
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling. This wait will timeout after the specified time
+ * interval.
+ * @param time in millisecsonds to wait, or WAIT_INIFINITE
+ * @throws ActiveMQException
+ */
+ virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){
+ mutex.wait(millisecs);
+ }
+
+ /**
+ * Signals a waiter on this object that it can now wake
+ * up and continue. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void notify() throw(exceptions::ActiveMQException){
+ mutex.notify();
+ }
+
+ /**
+ * Signals the waiters on this object that it can now wake
+ * up and continue. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void notifyAll() throw(exceptions::ActiveMQException){
+ mutex.notifyAll();
+ }
+
+ /**
+ * Writes a single byte to the output stream.
+ * @param c the byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char c )
+ throw (IOException);
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer, const int len )
+ throw (IOException);
+
+ /**
+ * Invokes flush on the target output stream, has no affect.
+ * @throws IOException
+ */
+ virtual void flush( void ) throw (IOException);
+
+ /**
+ * Clear current Stream contents
+ * @throws IOException
+ */
+ virtual void clear( void ) throw (IOException);
+
+ /**
+ * Invokes close on the target output stream.
+ * @throws CMSException
+ */
+ void close( void ) throw(cms::CMSException);
+
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_IO_BYTEARRAYOUTPUTSTREAM_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianReader.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianReader.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianReader.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianReader.cpp Mon Jul 3 04:51:36 2006
@@ -0,0 +1,129 @@
+/*
+ * 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 "EndianReader.h"
+#include "../util/Endian.h"
+
+using namespace activemq::io;
+using namespace activemq::util;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+EndianReader::EndianReader()
+{
+ inputStream = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+EndianReader::EndianReader( InputStream* is )
+{
+ inputStream = is;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+EndianReader::~EndianReader()
+{
+ // no-op
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char EndianReader::readByte() throw(IOException)
+{
+ unsigned char value ;
+
+ // Read a single byte
+ read(&value, sizeof(unsigned char)) ;
+ return value ;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double EndianReader::readDouble() throw(IOException)
+{
+ double value ;
+
+ // Read a double and convert from big endian to little endian if necessary
+ read((unsigned char*)&value, sizeof(double) ) ;
+ return Endian::byteSwap(value) ;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float EndianReader::readFloat() throw(IOException)
+{
+ float value ;
+
+ // Read a float and convert from big endian to little endian if necessary
+ read((unsigned char*)&value, sizeof(float)) ;
+ return Endian::byteSwap(value) ;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+uint16_t EndianReader::readUInt16() throw(IOException)
+{
+ uint16_t value;
+
+ // Read a short and byteswap
+ read((unsigned char*)&value, sizeof(value) );
+ return Endian::byteSwap(value);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+uint32_t EndianReader::readUInt32() throw(IOException)
+{
+ uint32_t value;
+
+ // Read an int and convert from big endian to little endian if necessary
+ read((unsigned char*)&value, sizeof(value)) ;
+ return Endian::byteSwap(value) ;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+uint64_t EndianReader::readUInt64() throw(IOException)
+{
+ uint64_t value ;
+
+ // Read a long long and convert from big endian to little endian if necessary
+ read((unsigned char*)&value, sizeof(value)) ;
+ return Endian::byteSwap(value) ;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/*string EndianReader::readString() throw(IOException)
+{
+ // Read length of string
+ short length = readShort() ;
+ char* buffer = new char[length+1] ;
+
+ // Read string bytes
+ read((unsigned char*)buffer, length) ;
+ *(buffer+length) = '\0' ;
+
+ // Create string class
+ string value;
+ value.assign(buffer) ;
+
+ return value ;
+}*/
+
+////////////////////////////////////////////////////////////////////////////////
+int EndianReader::read(unsigned char* buffer, int count) throw(IOException){
+
+ if( inputStream == NULL ){
+ throw IOException( __FILE__, __LINE__,
+ "EndianReader::read(char*,int) - input stream is NULL" );
+ }
+
+ return inputStream->read( buffer, count );
+}
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianReader.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianReader.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianReader.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianReader.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,132 @@
+/*
+ * 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_IO_ENDIANREADER_H
+#define ACTIVEMQ_IO_ENDIANREADER_H
+
+#include <activemq/io/Reader.h>
+#include <activemq/util/Endian.h>
+
+namespace activemq{
+namespace io{
+
+ /*
+ * The BinaryReader class reads primitive C++ data types from an
+ * underlying input stream in a Java compatible way. Strings are
+ * read as raw bytes, no character decoding is performed.
+ *
+ * All numeric data types are assumed to be available in big
+ * endian (network byte order) and are converted automatically
+ * to little endian if needed by the platform.
+ *
+ * Should any error occur an IOException will be thrown.
+ */
+ class EndianReader : public Reader
+ {
+ private:
+
+ /**
+ * The target input stream.
+ */
+ InputStream* inputStream;
+
+ public:
+
+ /**
+ * Constructor.
+ */
+ EndianReader();
+
+ /**
+ * Constructor.
+ * @param is the target input stream.
+ */
+ EndianReader( InputStream* is );
+
+ /**
+ * Destructor.
+ */
+ virtual ~EndianReader();
+
+ /**
+ * Sets the target input stream.
+ */
+ virtual void setInputStream( InputStream* is ){
+ inputStream = is;
+ }
+
+ /**
+ * Gets the target input stream.
+ */
+ virtual InputStream* getInputStream(){
+ return inputStream;
+ }
+
+ /**
+ * Attempts to read an array of bytes from the stream.
+ * @param buffer The target byte buffer.
+ * @param count The number of bytes to read.
+ * @return The number of bytes read.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual int read(unsigned char* buffer, int count) throw(IOException);
+
+ /**
+ * Attempts to read a byte from the input stream
+ * @return The byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual unsigned char readByte() throw(IOException);
+
+ /**
+ * Attempts to read a double from the input stream
+ * @return The byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual double readDouble() throw(IOException);
+
+ /**
+ * Attempts to read a float from the input stream
+ * @return The byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual float readFloat() throw(IOException);
+
+ /**
+ * Attempts to read a short from the input stream
+ * @return The byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual uint16_t readUInt16() throw(IOException);
+
+ /**
+ * Attempts to read an int from the input stream
+ * @return The byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual uint32_t readUInt32() throw(IOException);
+
+ /**
+ * Attempts to read a long long from the input stream
+ * @return The byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual uint64_t readUInt64() throw(IOException);
+ };
+
+}}
+
+#endif /*ACTIVEMQ_IO_ENDIANREADER_H*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianWriter.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianWriter.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianWriter.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianWriter.cpp Mon Jul 3 04:51:36 2006
@@ -0,0 +1,114 @@
+/*
+ * 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 "EndianWriter.h"
+#include <activemq/util/Endian.h>
+
+using namespace activemq::io;
+using namespace activemq::util;
+
+////////////////////////////////////////////////////////////////////////////////
+EndianWriter::EndianWriter()
+{
+ outputStream = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+EndianWriter::EndianWriter( OutputStream* os )
+{
+ outputStream = os;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+EndianWriter::~EndianWriter()
+{
+ // no-op
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void EndianWriter::writeByte(unsigned char value) throw(IOException)
+{
+ // Write a single byte
+ write(&value, sizeof(unsigned char));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void EndianWriter::writeDouble(double v) throw(IOException)
+{
+ // Write a double, byteswap if necessary
+ double value = Endian::byteSwap(v);
+ write((unsigned char*)&value, sizeof(value));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void EndianWriter::writeFloat(float v) throw(IOException)
+{
+ // Write a float, byteswap if necessary
+ float value = Endian::byteSwap(v);
+ write((unsigned char*)&value, sizeof(value));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void EndianWriter::writeUInt16(uint16_t v) throw(IOException)
+{
+ // Write a short, byteswap if necessary
+ uint16_t value = Endian::byteSwap(v) ;
+ write((unsigned char*)&value, sizeof(value));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void EndianWriter::writeUInt32(uint32_t v) throw(IOException)
+{
+ // Write an int, byteswap if necessary
+ uint32_t value = Endian::byteSwap(v);
+ write((unsigned char*)&value, sizeof(value));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void EndianWriter::writeUInt64(uint64_t v) throw(IOException)
+{
+ // Write a long long, byteswap if necessary
+ uint64_t value = Endian::byteSwap(v);
+ write((unsigned char*)&value, sizeof(value));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/*void EndianWriter::writeString(const std::string& value) throw(IOException)
+{
+ // Assert argument
+ if( value.length() > USHRT_MAX ){
+ throw IOException("String length exceeds maximum length") ;
+ }
+
+ // Write length of string
+ short length = (short)value.length() ;
+ writeShort( length ) ;
+
+ // Write string contents
+ write((unsigned char*)value.c_str(), length) ;
+}*/
+
+////////////////////////////////////////////////////////////////////////////////
+void EndianWriter::write(const unsigned char* buffer, int count) throw(IOException){
+
+ if( outputStream == NULL ){
+ throw IOException( __FILE__, __LINE__,
+ "EndianWriter::write(char*,int) - input stream is NULL" );
+ }
+
+ outputStream->write( buffer, count );
+}
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianWriter.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianWriter.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianWriter.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/EndianWriter.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,132 @@
+/*
+ * 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_IO_ENDIANWRITER_H
+#define ACTIVEMQ_IO_ENDIANWRITER_H
+
+#include <activemq/io/Writer.h>
+#include <activemq/io/OutputStream.h>
+#include <activemq/util/Endian.h>
+
+namespace activemq{
+namespace io{
+
+ /*
+ * The BinaryWriter class writes primitive C++ data types to an
+ * underlying output stream in a Java compatible way. Strings
+ * are written as raw bytes, no character encoding is performed.
+ *
+ * All numeric data types are written in big endian (network byte
+ * order) and if the platform is little endian they are converted
+ * automatically.
+ *
+ * Should any error occur an IOException will be thrown.
+ */
+ class EndianWriter : public Writer
+ {
+ private:
+
+ /**
+ * Target output stream.
+ */
+ OutputStream* outputStream;
+
+ public:
+
+ /**
+ * Constructor.
+ */
+ EndianWriter();
+
+ /**
+ * Constructor.
+ * @param os the target output stream.
+ */
+ EndianWriter( OutputStream* os );
+
+ /**
+ * Destructor.
+ */
+ virtual ~EndianWriter();
+
+ /**
+ * Sets the target output stream.
+ */
+ virtual void setOutputStream( OutputStream* os ){
+ outputStream = os;
+ }
+
+ /**
+ * Gets the target output stream.
+ */
+ virtual OutputStream* getOutputStream(){
+ return outputStream;
+ }
+
+ /**
+ * Writes a byte array to the target output stream.
+ * @param buffer a byte array.
+ * @param count the number of bytes to write.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write(const unsigned char* buffer, int count) throw(IOException);
+
+ /**
+ * Writes a byte to the target output stream.
+ * @param v the value to be written
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void writeByte(unsigned char v) throw(IOException);
+
+ /**
+ * Writes a double to the target output stream.
+ * @param v the value to be written
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void writeDouble(double v) throw(IOException);
+
+ /**
+ * Writes a float to the target output stream.
+ * @param v the value to be written
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void writeFloat(float v) throw(IOException);
+
+ /**
+ * Writes a short to the target output stream.
+ * @param v the value to be written
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void writeUInt16(uint16_t v) throw(IOException);
+
+ /**
+ * Writes an int to the target output stream.
+ * @param v the value to be written
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void writeUInt32(uint32_t v) throw(IOException);
+
+ /**
+ * Writes a long long to the target output stream.
+ * @param v the value to be written
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void writeUInt64(uint64_t v) throw(IOException);
+ };
+
+}}
+
+#endif /*ACTIVEMQ_IO_ENDIANWRITER_H*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/IOException.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/IOException.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/IOException.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/IOException.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,64 @@
+/*
+ * 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_IO_IOEXCEPTION_H
+#define ACTIVEMQ_IO_IOEXCEPTION_H
+
+#include <activemq/exceptions/ActiveMQException.h>
+
+namespace activemq{
+namespace io{
+
+ /*
+ * Signals that an I/O exception of some sort has occurred.
+ */
+ class IOException : public exceptions::ActiveMQException
+ {
+ public:
+ IOException(){}
+ IOException( const exceptions::ActiveMQException& ex ){
+ *(exceptions::ActiveMQException*)this = ex;
+ }
+ IOException( const IOException& ex ){
+ *(exceptions::ActiveMQException*)this = ex;
+ }
+ IOException(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 exceptions::ActiveMQException* clone() const{
+ return new IOException( *this );
+ }
+
+ virtual ~IOException(){}
+
+ };
+
+}}
+
+#endif /*ACTIVEMQ_IO_IOEXCEPTION_H*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/InputStream.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/InputStream.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/InputStream.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/InputStream.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_IO_INPUTSTREAM_H_
+#define ACTIVEMQ_IO_INPUTSTREAM_H_
+
+#include <activemq/io/IOException.h>
+#include <cms/Closeable.h>
+#include <activemq/concurrent/Synchronizable.h>
+
+namespace activemq{
+namespace io{
+
+ /**
+ * Base interface for an input stream.
+ */
+ class InputStream
+ :
+ public cms::Closeable,
+ public concurrent::Synchronizable
+ {
+
+ public:
+
+ virtual ~InputStream(){}
+
+ /**
+ * Indcates the number of bytes avaialable.
+ * @return the number of bytes available on this input stream.
+ */
+ virtual int available() const = 0;
+
+ /**
+ * Reads a single byte from the buffer.
+ * @return The next byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual unsigned char read() throw (IOException) = 0;
+
+ /**
+ * Reads an array of bytes from the buffer.
+ * @param buffer (out) the target buffer.
+ * @param bufferSize the size of the output buffer.
+ * @return The number of bytes read.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual int read( unsigned char* buffer, const int bufferSize ) throw (IOException) = 0;
+ };
+
+}}
+
+#endif /*ACTIVEMQ_IO_INPUTSTREAM_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/OutputStream.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/OutputStream.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/OutputStream.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/OutputStream.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,63 @@
+/*
+ * 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_IO_OUTPUTSTREAM_H
+#define ACTIVEMQ_IO_OUTPUTSTREAM_H
+
+#include <cms/Closeable.h>
+#include <activemq/io/IOException.h>
+#include <activemq/concurrent/Synchronizable.h>
+
+namespace activemq{
+namespace io{
+
+ /**
+ * Base interface for an output stream.
+ */
+ class OutputStream
+ :
+ public cms::Closeable,
+ public concurrent::Synchronizable
+ {
+ public:
+
+ virtual ~OutputStream(){}
+
+ /**
+ * Writes a single byte to the output stream.
+ * @param c the byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char c ) throw (IOException) = 0;
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer, const int len ) throw (IOException) = 0;
+
+ /**
+ * Flushes any pending writes in this output stream.
+ */
+ virtual void flush() throw (IOException) = 0;
+ };
+
+}}
+
+#endif /*ACTIVEMQ_IO_OUTPUTSTREAM_H*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/Reader.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/Reader.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/Reader.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/Reader.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_IO_READER_H
+#define ACTIVEMQ_IO_READER_H
+
+#include <string>
+#include <activemq/io/IOException.h>
+#include <activemq/io/InputStream.h>
+
+namespace activemq{
+namespace io{
+
+ /*
+ * Reader interface that wraps around an input stream and provides
+ * an interface for extracting the data from the input stream.
+ */
+ class Reader
+ {
+ public:
+
+ virtual ~Reader(){};
+
+ /**
+ * Sets the target input stream.
+ */
+ virtual void setInputStream( InputStream* is ) = 0;
+
+ /**
+ * Gets the target input stream.
+ */
+ virtual InputStream* getInputStream() = 0;
+
+ /**
+ * Attempts to read an array of bytes from the stream.
+ * @param buffer The target byte buffer.
+ * @param count The number of bytes to read.
+ * @return The number of bytes read.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual int read(unsigned char* buffer, int count) throw(IOException) = 0;
+
+ /**
+ * Attempts to read a byte from the input stream
+ * @return The byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual unsigned char readByte() throw(IOException) = 0;
+ } ;
+
+}}
+
+#endif /*ACTIVEMQ_IO_READER_H*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/StandardErrorOutputStream.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/StandardErrorOutputStream.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/StandardErrorOutputStream.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/StandardErrorOutputStream.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,153 @@
+/*
+ * 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_IO_STANDARDERROROUTPUTSTREAM_H_
+#define _ACTIVEMQ_IO_STANDARDERROROUTPUTSTREAM_H_
+
+#include <activemq/io/OutputStream.h>
+#include <activemq/concurrent/Mutex.h>
+
+#include <iostream>
+
+namespace activemq{
+namespace io{
+
+ class StandardErrorOutputStream : public OutputStream
+ {
+ private:
+
+ /**
+ * Synchronization object.
+ */
+ concurrent::Mutex mutex;
+
+ public:
+
+ /**
+ * Constructor
+ */
+ StandardErrorOutputStream(void) {}
+
+ /**
+ * Destructor
+ */
+ virtual ~StandardErrorOutputStream(void) {}
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void lock() throw(exceptions::ActiveMQException){
+ mutex.lock();
+ }
+
+ /**
+ * Unlocks the object.
+ * @throws ActiveMQException
+ */
+ virtual void unlock() throw(exceptions::ActiveMQException){
+ mutex.unlock();
+ }
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void wait() throw(exceptions::ActiveMQException){
+ mutex.wait();
+ }
+
+ /**
+ * Waits on a signal from this object, which is generated
+ * by a call to Notify. Must have this object locked before
+ * calling. This wait will timeout after the specified time
+ * interval.
+ * @param time in millisecsonds to wait, or WAIT_INIFINITE
+ * @throws ActiveMQException
+ */
+ virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){
+ mutex.wait(millisecs);
+ }
+
+ /**
+ * Signals a waiter on this object that it can now wake
+ * up and continue. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void notify() throw(exceptions::ActiveMQException){
+ mutex.notify();
+ }
+
+ /**
+ * Signals the waiters on this object that it can now wake
+ * up and continue. Must have this object locked before
+ * calling.
+ * @throws ActiveMQException
+ */
+ virtual void notifyAll() throw(exceptions::ActiveMQException){
+ mutex.notifyAll();
+ }
+
+ /**
+ * Writes a single byte to the output stream.
+ * @param c the byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char c )
+ throw (IOException)
+ {
+ std::cerr << c;
+ }
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer, const int len )
+ throw (IOException)
+ {
+ for(int i = 0; i < len; ++i)
+ {
+ std::cerr << buffer[i];
+ }
+ }
+
+ /**
+ * Invokes flush on the target output stream.
+ */
+ virtual void flush() throw (IOException){
+ std::cerr.flush();
+ }
+
+ /**
+ * Invokes close on the target output stream.
+ */
+ void close() throw(cms::CMSException){
+ std::cerr.flush();
+ }
+
+ };
+
+}
+
+#endif /*_ACTIVEMQ_IO_STANDARDERROROUTPUTSTREAM_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/Writer.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/Writer.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/Writer.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/io/Writer.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,65 @@
+/*
+ * 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_IO_WRITER_H
+#define ACTIVEMQ_IO_WRITER_H
+
+#include <string>
+#include <activemq/io/IOException.h>
+#include <activemq/io/OutputStream.h>
+
+namespace activemq{
+namespace io{
+
+ /*
+ * Writer interface for an object that wraps around an output
+ * stream
+ */
+ class Writer
+ {
+ public:
+
+ virtual ~Writer(){};
+
+ /**
+ * Sets the target output stream.
+ */
+ virtual void setOutputStream( OutputStream* os ) = 0;
+
+ /**
+ * Gets the target output stream.
+ */
+ virtual OutputStream* getOutputStream() = 0;
+
+ /**
+ * Writes a byte array to the output stream.
+ * @param buffer a byte array
+ * @param count the number of bytes in the array to write.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write(const unsigned char* buffer, int count) throw(IOException) = 0;
+
+ /**
+ * Writes a byte to the output stream.
+ * @param v The value to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void writeByte(unsigned char v) throw(IOException) = 0;
+ };
+
+}}
+
+#endif /*ACTIVEMQ_IO_WRITER_H*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/ConsoleHandler.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/ConsoleHandler.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/ConsoleHandler.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/ConsoleHandler.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_CONSOLEHANDLER_H_
+#define _ACTIVEMQ_LOGGER_CONSOLEHANDLER_H_
+
+#include <activemq/logger/StreamHandler.h>
+#include <activemq/io/StandardErrorOutputStream.h>
+
+namespace activemq{
+namespace logger{
+
+ /**
+ * This Handler publishes log records to System.err. By default the
+ * SimpleFormatter is used to generate brief summaries.
+ *
+ * Configuration: By default each ConsoleHandler is initialized using
+ * the following LogManager configuration properties. If properties are
+ * not defined (or have invalid values) then the specified default
+ * values are used.
+ *
+ * ConsoleHandler.level specifies the default level for the Handler
+ * (defaults to Level.INFO).
+ * ConsoleHandler.filter specifies the name of a Filter class to use
+ * (defaults to no Filter).
+ * ConsoleHandler.formatter specifies the name of a Formatter class to
+ * use (defaults to SimpleFormatter).
+ */
+ class ConsoleHandler
+ {
+ private:
+
+ // The Standard Error Stream to log to
+ io::StandardErrorOutputStream stream;
+
+ // The default Simple Formatter
+ SimpleFormatter formatter;
+
+ public:
+
+ /**
+ * Constructor
+ */
+ ConsoleHandler(void) : StreamHandler(&stream, &formatter)
+ {
+ // Defaults level to Info
+ setLevel(Level.INFO);
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~ConsoleHandler(void) {}
+
+ /**
+ * Close the current output stream.
+ * <p>
+ * Override the StreamHandler close to flush the Std Err stream
+ * but doesn't close.
+ * @throw CMSException
+ */
+ virtual void close(void) throw ( cms::CMSException )
+ {
+ if(getOutputStream())
+ {
+ getOutputStream->flush();
+ }
+ }
+
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_CONSOLEHANDLER_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Filter.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Filter.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Filter.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Filter.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,53 @@
+/*
+ * 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_FILTER_H_
+#define _ACTIVEMQ_LOGGER_FILTER_H_
+
+#include <activemq/logger/LogRecord.h>
+
+namespace activemq{
+namespace logger{
+
+ /**
+ * A Filter can be used to provide fine grain control over what is
+ * logged, beyond the control provided by log levels.
+ *
+ * Each Logger and each Handler can have a filter associated with it.
+ * The Logger or Handler will call the isLoggable method to check if a
+ * given LogRecord should be published. If isLoggable returns false,
+ * the LogRecord will be discarded.
+ */
+ class Filter
+ {
+ public:
+
+ /**
+ * Destructor
+ */
+ virtual ~Filter(void) {}
+
+ /**
+ * Check if a given log record should be published.
+ * @param the <code>LogRecord</code> to check.
+ */
+ virtual bool isLoggable(const LogRecord& record) const = 0;
+
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_FILTER_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Formatter.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Formatter.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Formatter.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Formatter.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,74 @@
+/*
+ * 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_FORMATTER_H_
+#define _ACTIVEMQ_LOGGER_FORMATTER_H_
+
+namespace activemq{
+namespace logger{
+
+ /**
+ * A Formatter provides support for formatting LogRecords.
+ *
+ * Typically each logging Handler will have a Formatter associated with
+ * it. The Formatter takes a LogRecord and converts it to a string.
+ *
+ * Some formatters (such as the XMLFormatter) need to wrap head and
+ * tail strings around a set of formatted records. The getHeader and
+ * getTail methods can be used to obtain these strings.
+ */
+ class Formatter
+ {
+ public:
+
+ /**
+ * Destrcutor
+ */
+ virtual ~Formatter(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 = 0;
+
+ /**
+ * Format the message string from a log record.
+ * @param The Log Record to Format
+ */
+ virtual std::string formatMessage(const LogRecord& record) const = 0;
+
+ /**
+ * 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 the head string
+ */
+ virtual std::string getHead(const Handler* handler) = 0;
+
+ /**
+ * 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 the tail string
+ */
+ virtual std::string getTail(const Handler* handler) = 0;
+
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_FORMATTER_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Handler.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Handler.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Handler.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/Handler.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,125 @@
+/*
+ * 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_HANDLER_H_
+#define _ACTIVEMQ_LOGGER_HANDLER_H_
+
+#include <cms/Closeable.h>
+#include <activemq/logger/LogRecord.h>
+
+namespace activemq{
+namespace logger{
+
+ class Filter;
+ class Formatter;
+
+ /**
+ * A Handler object takes log messages from a Logger and exports them.
+ * It might for example, write them to a console or write them to a file,
+ * or send them to a network logging service, or forward them to an OS
+ * log, or whatever.
+ *
+ * A Handler can be disabled by doing a setLevel(Level.OFF) and can be
+ * re-enabled by doing a setLevel with an appropriate level.
+ *
+ * Handler classes typically use LogManager properties to set default
+ * values for the Handler's Filter, Formatter, and Level. See the
+ * specific documentation for each concrete Handler class.
+ */
+ class Handler : public cms::Closeable
+ {
+ public:
+
+ /**
+ * Destructor
+ */
+ virtual ~Handler(void) {}
+
+ /**
+ * Flush the Handler's output, clears any buffers.
+ */
+ virtual void flush(void) = 0;
+
+ /**
+ * Publish the Log Record to this Handler
+ * @param The Log Record to Publish
+ */
+ virtual void publish(const LogRecord& record) = 0;
+
+ /**
+ * Check if this Handler would actually log a given LogRecord.
+ * <p>
+ * This method checks if the LogRecord has an appropriate Level and
+ * whether it satisfies any Filter. It also may make other Handler
+ * specific checks that might prevent a handler from logging the
+ * LogRecord.
+ * @param <code>LogRecord</code> to check
+ */
+ virtual void isLoggable(const LogRecord& record) = 0;
+
+ /**
+ * Sets the Filter that this Handler uses to filter Log Records
+ * <p>
+ * For each call of publish the Handler will call this Filter (if it
+ * is non-null) to check if the LogRecord should be published or
+ * discarded.
+ * @param <code>Filter</code> derived instance
+ */
+ virtual void setFilter(const Filter* filter) = 0;
+
+ /**
+ * Gets the Filter that this Handler uses to filter Log Records
+ * @param <code>Filter</code> derived instance
+ */
+ virtual const Filter* getFilter(void) = 0;
+
+ /**
+ * 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 value) = 0;
+
+ /**
+ * Get the log level specifying which message levels will be logged
+ * by this Handler.
+ * @param Level enumeration value
+ */
+ virtual Level getLevel(void) = 0;
+
+ /**
+ * Sets the <code>Formatter</code> used by this Handler
+ * <p>
+ * Some Handlers may not use Formatters, in which case the
+ * Formatter will be remembered, but not used.
+ * @param <code>Filter</code> derived instance
+ */
+ virtual void setFormatter(const Formatter* formatter) = 0;
+
+ /**
+ * Gets the <code>Formatter</code> used by this Handler
+ * @param <code>Filter</code> derived instance
+ */
+ virtual const Formatter* getFormatter(void) = 0;
+
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_HANDLER_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogManager.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogManager.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogManager.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogManager.cpp Mon Jul 3 04:51:36 2006
@@ -0,0 +1,129 @@
+/*
+* 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 "LogManager.h"
+
+#include <activemq/logger/PropertiesChangeListener.h>
+#include <activemq/concurrent/Concurrent.h>
+
+#include <algorithm>
+
+using namespace activemq;
+using namespace activemq::logger;
+using namespace activemq::util;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+concurrent::Mutex LogManager::mutex;
+LogManager* LogManager::instance = NULL;
+unsigned int LogManager::refCount = 0;
+
+////////////////////////////////////////////////////////////////////////////////
+LogManager::~LogManager( void )
+{
+ // TODO - Delete all the loggers.
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LogManager::setProperties( const Properties* properties )
+{
+ // Copy the properties
+ this->properties.copy(properties);
+
+ // Update the configuration of the loggers.
+ // TODO
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LogManager::addPropertyChangeListener(
+ PropertyChangeListener* listener )
+{
+ if(find(listeners.begin(), listeners.end(), listener) == listeners.end())
+ {
+ listeners.push_back(listener);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LogManager::removePropertyChangeListener(
+ PropertyChangeListener* listener )
+{
+ listeners.remove(listener);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Logger* LogManager::getLogger( const std::string& name )
+{
+ return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int LogManager::getLoggerNames( const std::vector<std::string>& names )
+{
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LogManager* LogManager::getInstance( void )
+{
+ synchronized( &mutex )
+ {
+ if( instance == NULL )
+ {
+ instance = new LogManager();
+ }
+
+ refCount++;
+
+ return instance;
+ }
+
+ return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LogManager::returnInstance( void )
+{
+ synchronized( &mutex )
+ {
+ if( refCount == 0 )
+ {
+ return ;
+ }
+
+ refCount--;
+
+ if( refCount == 0 )
+ {
+ delete instance;
+ instance = NULL;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LogManager::destroy( void )
+{
+ if( instance != NULL )
+ {
+ synchronized( &mutex )
+ {
+ delete instance;
+ instance = NULL;
+ refCount = 0;
+ }
+ }
+}
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogManager.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogManager.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogManager.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogManager.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,252 @@
+/*
+* 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_LOGMANAGER_H_
+#define _ACTIVEMQ_LOGGER_LOGMANAGER_H_
+
+#include <map>
+#include <list>
+#include <string>
+#include <vector>
+
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/concurrent/Mutex.h>
+
+namespace activemq{
+namespace logger{
+
+ class Logger;
+ class PropertyChangeListener;
+
+ /**
+ * There is a single global LogManager object that is used to maintain
+ * a set of shared state about Loggers and log services.
+ *
+ * This LogManager object:
+ *
+ * * Manages a hierarchical namespace of Logger objects. All named
+ * Loggers are stored in this namespace.
+ * * Manages a set of logging control properties. These are simple
+ * key-value pairs that can be used by Handlers and other logging
+ * objects to configure themselves.
+ *
+ * The global LogManager object can be retrieved using
+ * LogManager.getLogManager(). The LogManager object is created during
+ * class initialization and cannot subsequently be changed.
+ *
+ * ***TODO****
+ * By default, the LogManager reads its initial configuration from a
+ * properties file "lib/logging.properties" in the JRE directory. If
+ * you edit that property file you can change the default logging
+ * configuration for all uses of that JRE.
+ *
+ * In addition, the LogManager uses two optional system properties that
+ * allow more control over reading the initial configuration:
+ *
+ * * "decaf.logger.config.class"
+ * * "decaf.logger.config.file"
+ *
+ * These two properties may be set via the Preferences API, or as
+ * command line property definitions to the "java" command, or as
+ * system property definitions passed to JNI_CreateJavaVM.
+ *
+ * If the "java.util.logging.config.class" property is set, then the
+ * property value is treated as a class name. The given class will be
+ * loaded, an object will be instantiated, and that object's constructor
+ * is responsible for reading in the initial configuration. (That object
+ * may use other system properties to control its configuration.) The
+ * alternate configuration class can use readConfiguration(InputStream)
+ * to define properties in the LogManager.
+ *
+ * If "java.util.logging.config.class" property is not set, then the
+ * "java.util.logging.config.file" system property can be used to specify
+ * a properties file (in java.util.Properties format). The initial
+ * logging configuration will be read from this file.
+ *
+ * If neither of these properties is defined then, as described above,
+ * the LogManager will read its initial configuration from a properties
+ * file "lib/logging.properties" in the JRE directory.
+ *
+ * The properties for loggers and Handlers will have names starting with
+ * the dot-separated name for the handler or logger.
+ * ***TODO****
+ *
+ * The global logging properties may include:
+ *
+ * * A property "handlers". This defines a whitespace separated
+ * list of class names for handler classes to load and register as
+ * handlers on the root Logger (the Logger named ""). Each class
+ * name must be for a Handler class which has a default constructor.
+ * Note that these Handlers may be created lazily, when they are
+ * first used.
+ * * A property "<logger>.handlers". This defines a whitespace or
+ * comma separated list of class names for handlers classes to load
+ * and register as handlers to the specified logger. Each class name
+ * must be for a Handler class which has a default constructor. Note
+ * that these Handlers may be created lazily, when they are first
+ * used.
+ * * A property "<logger>.useParentHandlers". This defines a boolean
+ * value. By default every logger calls its parent in addition to
+ * handling the logging message itself, this often result in
+ * messages being handled by the root logger as well. When setting
+ * this property to false a Handler needs to be configured for this
+ * logger otherwise no logging messages are delivered.
+ * * A property "config". This property is intended to allow arbitrary
+ * configuration code to be run. The property defines a whitespace
+ * separated list of class names. A new instance will be created for
+ * each named class. The default constructor of each class may
+ * execute arbitrary code to update the logging configuration, such
+ * as setting logger levels, adding handlers, adding filters, etc.
+ *
+ * Loggers are organized into a naming hierarchy based on their dot
+ * separated names. Thus "a.b.c" is a child of "a.b", but "a.b1" and
+ * a.b2" are peers.
+ *
+ * All properties whose names end with ".level" are assumed to define
+ * log levels for Loggers. Thus "foo.level" defines a log level for
+ * the logger called "foo" and (recursively) for any of its children
+ * in the naming hierarchy. Log Levels are applied in the order they
+ * are defined in the properties file. Thus level settings for child
+ * nodes in the tree should come after settings for their parents. The
+ * property name ".level" can be used to set the level for the root of
+ * the tree.
+ *
+ * All methods on the LogManager object are multi-thread safe.
+ */
+ class LogManager
+ {
+ private:
+
+ // Change listener on this class's Properties
+ std::list<PropertyChangeListener*> listeners;
+
+ // Properties of the Log Manager
+ util::SimpleProperties properties;
+
+ public:
+
+ /**
+ * Destructor
+ */
+ virtual ~LogManager();
+
+ /**
+ * Sets the Properties this LogManager should use to configure
+ * its loggers. Once set a properties change event is fired.
+ * @param Properties Pointer to read the configuration from
+ */
+ virtual void setProperties( const util::Properties* properties );
+
+ /**
+ * Gets a reference to the Logging Properties used by this
+ * logger.
+ * @returns The Logger Properties Pointer
+ */
+ virtual const util::Properties& getProperties( void ) const {
+ return properties;
+ }
+
+ /**
+ * Gets the value of a named property of this LogManager
+ * @param Name of the Property to retrieve
+ * @return the value of the property
+ */
+ virtual std::string getProperty( const std::string& name ) {
+ return properties.getProperty( name );
+ }
+
+ /**
+ * Adds a change listener for LogManager Properties, adding the same
+ * instance of a change event listener does nothing.
+ * @param PropertyChangeListener
+ */
+ virtual void addPropertyChangeListener(
+ PropertyChangeListener* listener );
+
+ /**
+ * Removes a properties change listener from the LogManager.
+ */
+ virtual void removePropertyChangeListener(
+ PropertyChangeListener* listener );
+
+ /**
+ * Retrieves or creates a new Logger using the name specified
+ * a new logger inherits the configuration of the logger's
+ * parent if there is no configuration data for the logger.
+ * @param The name of the Logger.
+ */
+ virtual Logger* getLogger( const std::string& name );
+
+ /**
+ * Gets a list of known Logger Names from this Manager
+ * @param STL Vector to hold string logger names
+ * @return count of how many loggers were inserted
+ */
+ virtual int getLoggerNames( const std::vector<std::string>& names );
+
+ public: // Static Singleton Methods.
+
+ /**
+ * Get the singleton instance
+ * @return Pointer to an instance of the Log Manager
+ */
+ static LogManager* getInstance( void );
+
+ /**
+ * Returns a Checked out instance of this Manager
+ */
+ static void returnInstance( void );
+
+ /**
+ * Forcefully Delete the Instance of this LogManager
+ * even if there are outstanding references.
+ */
+ static void destroy( void );
+
+ protected:
+
+ /**
+ * Constructor, hidden to protect against direct instantiation
+ */
+ LogManager( void )
+ {}
+
+ /**
+ * Copy Constructo
+ */
+ LogManager( const LogManager& manager );
+
+ /**
+ * Assignment operator
+ */
+ void operator=( const LogManager& manager );
+
+ private:
+
+ // Static mutex to protect the singleton methods
+ static concurrent::Mutex mutex;
+
+ // Static pointer to the one and only instance.
+ static LogManager* instance;
+
+ // Static counter for number of outstanding references
+ static unsigned int refCount;
+
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_LOGMANAGER_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogRecord.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogRecord.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogRecord.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogRecord.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,180 @@
+/*
+ * 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_LOGRECORD_H_
+#define _ACTIVEMQ_LOGGER_LOGRECORD_H_
+
+#include <activemq/logger/LoggerCommon.h>
+
+#include <string>
+
+namespace activemq{
+namespace logger{
+
+ class LogRecord
+ {
+ private:
+
+ // Level of this Record
+ Level level;
+
+ // Name of the source Logger
+ std::string loggerName;
+
+ // Name of the File that originated the Log
+ std::string sourceFile;
+
+ // Line in the source file where log occured
+ unsigned long sourceLine;
+
+ // The message to Log.
+ std::string message;
+
+ // The function Name where the log occured
+ std::string functionName;
+
+ // Time in Mills since UTC that this Record was logged
+ unsigned long timeStamp;
+
+ // Thread Id of the Thread that logged this Record
+ unsigned long threadId;
+
+ public:
+
+ /**
+ * Constructor
+ */
+ LogRecord() {}
+
+ /**
+ * Destructor
+ */
+ virtual ~LogRecord() {}
+
+ /**
+ * Get Level of this log record
+ * @return Level enumeration value.
+ */
+ Level getLevel(void) const { return level; };
+
+ /**
+ * Set the Level of this Log Record
+ * @param Level Enumeration Value
+ */
+ void setLevel(Level value) { level = value; };
+
+ /**
+ * Gets the Source Logger's Name
+ * @return the source loggers name
+ */
+ const std::string& getLoggerName(void) const { return loggerName; };
+
+ /**
+ * Sets the Source Logger's Name
+ * @param the source loggers name
+ */
+ void setLoggerName(const std::string& loggerName) {
+ this->loggerName = loggerName;
+ };
+
+ /**
+ * Gets the Source Log File name
+ * @return the source loggers name
+ */
+ const std::string& getSourceFile(void) const { return sourceFile; };
+
+ /**
+ * Sets the Source Log File Name
+ * @param the source loggers name
+ */
+ void setSourceFile(const std::string& loggerName) {
+ this->sourceFile = sourceFile;
+ };
+
+ /**
+ * Gets the Source Log line number
+ * @return the source loggers line number
+ */
+ unsigned long getSourceLine(void) const { return sourceLine; };
+
+ /**
+ * Sets the Source Log line number
+ * @param the source logger's line number
+ */
+ void setSourceLine(long sourceLine) {
+ this->sourceLine = sourceLine;
+ };
+
+ /**
+ * Gets the Message to be Logged
+ * @return the source logger's message
+ */
+ const std::string& getMessage(void) const { return message; };
+
+ /**
+ * Sets the Message to be Logged
+ * @param the source loggers message
+ */
+ void setMessage(const std::string& message) {
+ this->message = message;
+ };
+
+ /**
+ * Gets the name of the function where this log was logged
+ * @return the source logger's message
+ */
+ const std::string& getSourceFunction(void) const { return functionName; };
+
+ /**
+ * Sets the name of the function where this log was logged
+ * @param the source loggers message
+ */
+ void setSourceFunction(const std::string& functionName) {
+ this->functionName = functionName;
+ };
+
+ /**
+ * Gets the time in mills that this message was logged.
+ * @return UTC time in milliseconds
+ */
+ unsigned long getTimestamp(void) const { return timeStamp; };
+
+ /**
+ * Sets the time in mills that this message was logged.
+ * @param UTC Time in Milliseconds.
+ */
+ void setTimestamp(long timeStamp) {
+ this->timeStamp = timeStamp;
+ };
+
+ /**
+ * Gets the Thread Id where this Log was created
+ * @return the source loggers line number
+ */
+ unsigned long getTreadId(void) const { return threadId; };
+
+ /**
+ * Sets the Thread Id where this Log was created
+ * @param the source logger's line number
+ */
+ void setTreadId(long threadId) {
+ this->threadId = threadId;
+ };
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_LOGRECORD_H_*/
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogWriter.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogWriter.cpp?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogWriter.cpp (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogWriter.cpp Mon Jul 3 04:51:36 2006
@@ -0,0 +1,72 @@
+/*
+ * 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 "LogWriter.h"
+
+#include <iostream>
+#include <activemq/concurrent/Thread.h>
+#include <activemq/concurrent/Concurrent.h>
+#include <activemq/concurrent/Mutex.h>
+
+using namespace activemq;
+using namespace activemq::logger;
+using namespace activemq::concurrent;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+concurrent::Mutex LogWriter::mutex;
+
+////////////////////////////////////////////////////////////////////////////////
+LogWriter::LogWriter(void)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LogWriter::~LogWriter(void)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LogWriter::log(const std::string& file,
+ const int line,
+ const std::string& prefix,
+ const std::string& message)
+{
+ synchronized(&mutex)
+ {
+ cout << prefix << " "
+ << message << " - tid: " << Thread::getId() << endl;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LogWriter::log(const std::string& message)
+{
+ synchronized(&mutex)
+ {
+ cout << message << " - tid: " << Thread::getId() << endl;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LogWriter& LogWriter::getInstance(void)
+{
+ // This one instance
+ static LogWriter instance;
+
+ return instance;
+}
+
Added: incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogWriter.h
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogWriter.h?rev=418749&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogWriter.h (added)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/logger/LogWriter.h Mon Jul 3 04:51:36 2006
@@ -0,0 +1,81 @@
+/*
+ * 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_LOGWRITER_H_
+#define _ACTIVEMQ_LOGGER_LOGWRITER_H_
+
+//#pragma comment(linker,"/include:activemq::logger::LogWriter::mutex")
+
+#include <activemq/concurrent/Mutex.h>
+
+namespace activemq{
+namespace logger{
+
+ class LogWriter
+ {
+ public:
+
+ /**
+ * Constructor
+ */
+ LogWriter(void);
+
+ /**
+ * Destructor
+ */
+ virtual ~LogWriter(void);
+
+ /**
+ * Writes a message to the output destination
+ */
+ virtual void log(const std::string& file,
+ const int line,
+ const std::string& prefix,
+ const std::string& message);
+
+ /**
+ * Writes a message to the output destination
+ */
+ virtual void log(const std::string& message);
+
+ public: // Static methods
+
+ /**
+ * Get the singleton instance
+ */
+ static LogWriter& getInstance(void);
+
+ /**
+ * Returns a Checked out instance of this Writer
+ */
+ static void returnInstance(void);
+
+ /**
+ * Forcefully Delete the Instance of this LogWriter
+ * even if there are outstanding references.
+ */
+ static void destroy(void);
+
+ private:
+
+ // Syncronization mutex
+ static concurrent::Mutex mutex;
+
+ };
+
+}}
+
+#endif /*_ACTIVEMQ_LOGGER_LOGWRITER_H_*/