com.healthmarketscience.rmiio
Class RemoteOutputStreamServer

java.lang.Object
  extended by com.healthmarketscience.rmiio.RemoteStreamServer<RemoteOutputStreamServer,RemoteOutputStream>
      extended by com.healthmarketscience.rmiio.RemoteOutputStreamServer
All Implemented Interfaces:
RemoteOutputStream, Closeable, Flushable, Serializable, Remote, Unreferenced
Direct Known Subclasses:
GZIPRemoteOutputStream, SimpleRemoteOutputStream

public abstract class RemoteOutputStreamServer
extends RemoteStreamServer<RemoteOutputStreamServer,RemoteOutputStream>
implements RemoteOutputStream

Server implementation base class for a RemoteOutputStream. Handles the retry logic (the sequence ids) and the RemoteStreamMonitor updates for the server. Subclasses must implement the actual data handling methods.

Author:
James Ahlborn
See Also:
RemoteStreamServer.writeReplace(), Serialized Form

Field Summary
protected  OutputStream _out
          the real output stream to which we are writing data
static RemoteStreamMonitor<RemoteOutputStreamServer> DUMMY_MONITOR
          Default monitor for operations done by RemoteOutputStreamServer which does nothing.
 
Fields inherited from class com.healthmarketscience.rmiio.RemoteStreamServer
_monitor, INITIAL_INVALID_SEQUENCE_ID, INITIAL_VALID_SEQUENCE_ID, LOG
 
Constructor Summary
RemoteOutputStreamServer(OutputStream out)
           
RemoteOutputStreamServer(OutputStream out, RemoteStreamMonitor<RemoteOutputStreamServer> monitor)
           
 
Method Summary
 void close(boolean writeSuccess)
          Closes the output stream and releases the resources for this server object.
protected  void closeImpl(boolean writeSuccess)
          Closes (possibly flushes) the underlying streams and cleans up any resources.
 void flush()
          Flushes the output stream and forces as much as possible of any buffered bytes to be written out.
protected abstract  void flushImpl()
          Flushes the underlying stream.
protected  RemoteOutputStreamServer getAsSub()
          Returns a handle to this object as a subclass instance.
protected  Object getLock()
          Returns a handle to the object used to lock the underlying stream operations for this remote stream.
 OutputStream getOutputStream()
          Returns the real OutputStream to which this stream is writing data
 Class<RemoteOutputStream> getRemoteClass()
           
protected abstract  void writePacket(byte[] packet)
          Writes the given packet to the underlying stream.
 void writePacket(byte[] packet, int packetId)
          Writes the next chunk of data to this stream.
 
Methods inherited from class com.healthmarketscience.rmiio.RemoteStreamServer
abort, checkAborted, close, export, exported, finish, isClosed, unreferenced, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.healthmarketscience.rmiio.RemoteOutputStream
usingGZIPCompression
 

Field Detail

DUMMY_MONITOR

public static final RemoteStreamMonitor<RemoteOutputStreamServer> DUMMY_MONITOR
Default monitor for operations done by RemoteOutputStreamServer which does nothing.


_out

protected final transient OutputStream _out
the real output stream to which we are writing data

Constructor Detail

RemoteOutputStreamServer

public RemoteOutputStreamServer(OutputStream out)

RemoteOutputStreamServer

public RemoteOutputStreamServer(OutputStream out,
                                RemoteStreamMonitor<RemoteOutputStreamServer> monitor)
Parameters:
out - the real output stream from which the data will be read
monitor - monitor for tracking the progress of the stream usage
Method Detail

getOutputStream

public OutputStream getOutputStream()
Returns the real OutputStream to which this stream is writing data


getLock

protected final Object getLock()
Description copied from class: RemoteStreamServer
Returns a handle to the object used to lock the underlying stream operations for this remote stream.

Specified by:
getLock in class RemoteStreamServer<RemoteOutputStreamServer,RemoteOutputStream>

getAsSub

protected RemoteOutputStreamServer getAsSub()
Description copied from class: RemoteStreamServer
Returns a handle to this object as a subclass instance.

Specified by:
getAsSub in class RemoteStreamServer<RemoteOutputStreamServer,RemoteOutputStream>

getRemoteClass

public Class<RemoteOutputStream> getRemoteClass()
Specified by:
getRemoteClass in class RemoteStreamServer<RemoteOutputStreamServer,RemoteOutputStream>
Returns:
the class of the remote stream interface for this server

closeImpl

protected void closeImpl(boolean writeSuccess)
                  throws IOException
Description copied from class: RemoteStreamServer
Closes (possibly flushes) the underlying streams and cleans up any resources. Called by the finish() method.

Specified by:
closeImpl in class RemoteStreamServer<RemoteOutputStreamServer,RemoteOutputStream>
Parameters:
writeSuccess - true iff all data was successfully transferred, false otherwise
Throws:
IOException

close

public final void close(boolean writeSuccess)
                 throws IOException
Description copied from interface: RemoteOutputStream
Closes the output stream and releases the resources for this server object. Note that the remote object may no longer be accessible after this call (depending on the implementation), so clients should not attempt to use this stream after making this call.

Specified by:
close in interface RemoteOutputStream
Parameters:
writeSuccess - true iff all data was sent successfully from the client, false otherwise
Throws:
IOException

flush

public final void flush()
                 throws IOException
Description copied from interface: RemoteOutputStream
Flushes the output stream and forces as much as possible of any buffered bytes to be written out. Some of the layers of buffering may not be able to be flushed, so this method should not be depended upon to do much. The close() method will do any final flushing necessary (and can be depended upon).

Specified by:
flush in interface RemoteOutputStream
Specified by:
flush in interface Flushable
Throws:
IOException

writePacket

public final void writePacket(byte[] packet,
                              int packetId)
                       throws IOException
Description copied from interface: RemoteOutputStream
Writes the next chunk of data to this stream. The given packetId parameter (if used correctly) allows this operation to be idempotent. This parameter must be a monotonically increasing, positive integer. If the client fails to write a given packet, it may reattempt to write the same packet by giving the same packetId as from the failed call. However, only the current packet may be reattempted (the client cannot attempt to write any other previous packets). When writing a new packet, the caller does not need to give a sequential id, just a greater one (hence the term monotonically increasing).

Specified by:
writePacket in interface RemoteOutputStream
Parameters:
packet - iff the packetId was the same one from the last read call, this chunk of data is ignored. Otherwise, writes this new chunk of data to the stream.
packetId - client specified id for this packet
Throws:
IOException

flushImpl

protected abstract void flushImpl()
                           throws IOException
Flushes the underlying stream.

Throws:
IOException

writePacket

protected abstract void writePacket(byte[] packet)
                             throws IOException
Writes the given packet to the underlying stream. If this stream is using compression, this packet should contain compressed data.

Throws:
IOException


Copyright © 2006–2016 Health Market Science. All rights reserved.