Jive reference manual
List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
jem::mt::ThreadSafeWriter Class Reference

#include <jem/mt/ThreadSafeWriter.h>

Inheritance diagram for jem::mt::ThreadSafeWriter:
Inheritance graph

Public Types

typedef ThreadSafeWriter Self
 
typedef Writer Super
 

Public Member Functions

 ThreadSafeWriter (const Ref< Writer > &out)
 
 ThreadSafeWriter (const Ref< Writer > &out, const Ref< IOMutex > &mutex)
 
 ThreadSafeWriter (const Self &rhs)
 
virtual Ref< Writerdup ()
 
void lock ()
 Locks this output stream. More...
 
void unlock ()
 Unlocks this output stream. More...
 
virtual void close ()
 Closes this output stream. More...
 
virtual void flush ()
 Writes any buffered data to this output stream. More...
 
virtual void write (int c)
 Writes a single character to this output stream. More...
 
virtual void write (int c, idx_t n)
 
virtual void write (const char *buf, idx_t n)
 
virtual void writeNoThrow (const char *buf, idx_t n)
 
- Public Member Functions inherited from jem::io::Writer
virtual int poll ()
 Returns the number of characters that can be written without blocking. More...
 
virtual void write (int c, int n)
 Writes multiple copies of a character to this output stream. More...
 
virtual void write (const char *buf, int n)
 Writes an array of characters to this output stream. More...
 
virtual void writeNoThrow (const char *buf, int n)
 Writes a character array without throwing an exception. More...
 
virtual void printByte (byte b)
 Prints a formatted byte to this output stream. More...
 
virtual void printBool (bool b)
 Prints a formatted bool to this output stream. More...
 
virtual void printInt (long i)
 Prints a formatted integer to this output stream. More...
 
virtual void printFloat (double d)
 Prints a formatted double to this output stream. More...
 
- Public Member Functions inherited from jem::Object
virtual ClassgetClass () const
 Returns the Class instance representing the runtime class of this object. More...
 
virtual String toString () const
 Returns a short textual description of this object. More...
 
virtual long hashValue () const
 Returns a hash value for this object. More...
 
virtual bool equals (const Ref< Object > &obj) const
 Tests whether two objects are equal. More...
 
Ref< Objectclone () const
 Returns a copy of this object. More...
 

Protected Member Functions

 ThreadSafeWriter ()
 
virtual ~ThreadSafeWriter ()
 
- Protected Member Functions inherited from jem::Collectable
 Collectable ()
 Creates an empty Collectable. More...
 
 ~Collectable ()
 Frees resources. More...
 
- Protected Member Functions inherited from jem::Interface
virtual ~Interface ()
 Empty destructor. More...
 

Protected Attributes

Ref< Writeroutput_
 
Ref< IOMutexmutex_
 

Additional Inherited Members

- Static Public Member Functions inherited from jem::Object
static ClassgetType ()
 Returns the Class instance representing the Object class. More...
 

Member Typedef Documentation

Constructor & Destructor Documentation

jem::mt::ThreadSafeWriter::ThreadSafeWriter ( const Ref< Writer > &  out)
explicit
jem::mt::ThreadSafeWriter::ThreadSafeWriter ( const Ref< Writer > &  out,
const Ref< IOMutex > &  mutex 
)
jem::mt::ThreadSafeWriter::ThreadSafeWriter ( const Self rhs)
jem::mt::ThreadSafeWriter::ThreadSafeWriter ( )
protected
virtual jem::mt::ThreadSafeWriter::~ThreadSafeWriter ( )
protectedvirtual

Member Function Documentation

virtual Ref<Writer> jem::mt::ThreadSafeWriter::dup ( )
virtual
void jem::mt::ThreadSafeWriter::lock ( )
virtual

This function locks this Writer object so that only the current thread can write to the output stream. All other threads calling this function will be blocked until the current thread calls the unlock() member function.

The lock() and unlock() member functions are guaranteed to be recursive. This means that a thread may call lock() multiple times without creating a deadlock situation. Each call to lock() must be balanced by a call to unlock() to ensure that this Writer instance does not become permanently inaccessible to other threads.

The lock() function does not have to lock this object. In fact, the default implementation provided by the Writer class does nothing. It is up to you to instantiate a class derived from the Writer class that implements an appropriate locking scheme.

See also
Lock, IOMutex, ThreadSafeWriter.

Reimplemented from jem::io::Writer.

void jem::mt::ThreadSafeWriter::unlock ( )
virtual

Unlocks this Writer object so that it can be accessed by other threads.

The default implementation provided by the Writer class does nothing.

Precondition
This object has been locked by a call to the lock() member function.

Reimplemented from jem::io::Writer.

virtual void jem::mt::ThreadSafeWriter::close ( )
virtual

Closes this output stream. After calling this function, one should not attempt to write any more characters to the stream.

The default implementation provided by the Writer class does nothing.

Exceptions
IOException- if an I/O error occurs.

Reimplemented from jem::io::Writer.

virtual void jem::mt::ThreadSafeWriter::flush ( )
virtual

Writes any buffered characters to this output stream.

The default implementation provided by the Writer class does nothing.

Exceptions
IOException- if an I/O error occurs.

Reimplemented from jem::io::Writer.

virtual void jem::mt::ThreadSafeWriter::write ( int  c)
virtual

Writes the integer c, cast to an unsigned char, to this output stream.

Parameters
c- the character to be written.
Exceptions
IOException- if an I/O error occurs.

Implements jem::io::TextOutput.

virtual void jem::mt::ThreadSafeWriter::write ( int  c,
idx_t  n 
)
virtual
virtual void jem::mt::ThreadSafeWriter::write ( const char *  buf,
idx_t  n 
)
virtual
virtual void jem::mt::ThreadSafeWriter::writeNoThrow ( const char *  buf,
idx_t  n 
)
virtual

Member Data Documentation

Ref<Writer> jem::mt::ThreadSafeWriter::output_
protected
Ref<IOMutex> jem::mt::ThreadSafeWriter::mutex_
protected