com.healthmarketscience.rmiio
Class SerialRemoteIteratorServer<DataType>

java.lang.Object
  extended by com.healthmarketscience.rmiio.RemoteIteratorServer<DataType>
      extended by com.healthmarketscience.rmiio.EncodingRemoteIteratorServer<DataType>
          extended by com.healthmarketscience.rmiio.SerialRemoteIteratorServer<DataType>
All Implemented Interfaces:
Closeable

public class SerialRemoteIteratorServer<DataType>
extends EncodingRemoteIteratorServer<DataType>

Implementation of RemoteIteratorServer which uses java serialization to send objects to the RemoteIteratorClient. Objects are grabbed from the localIterator as needed and serialized to the local output stream. Note that a RemoteIterator is accepted for the local iterator so that the iterator may throw IOExceptions.

Note, the objects are written to the ObjectOutputStream using the ObjectOutputStream.writeUnshared(java.lang.Object) method, and the ObjectOutputStream.reset() method is called periodically on the output stream. These measures are taken because memory can build up in the ObjectOutputStream over time and a large data set can run the client and/or server out of memory. In general, the objects being iterated over most likely do not have shared references, so nothing will be lost by this choice. However, if shared references are desired, the serializeObject(java.io.ObjectOutputStream, java.lang.Object) method can be overriden by a custom subclass to change this behavior.

In the event that a RemoteIterator is being used to return low-latency, low-bandwidth update data to the client, the noDelay option can be enabled for the underlying stream which will effectively disable buffering of data on the server side. This can be very useful for implementing remote progress monitors, for example.

Note, since it is a common idiom for the local iterator to implement Closeable in order to close local resources, this implementation will automatically close a Closeable local iterator after the underlying server is shutdown.

Author:
James Ahlborn
See Also:
Usage Notes

Field Summary
static int DEFAULT_RESET_NUM_OBJECTS
          Default value for the setting indicating how often the ObjectOutputStream should be reset
 
Fields inherited from class com.healthmarketscience.rmiio.EncodingRemoteIteratorServer
_localOStream
 
Fields inherited from class com.healthmarketscience.rmiio.RemoteIteratorServer
_localIStream
 
Constructor Summary
SerialRemoteIteratorServer(boolean useCompression, boolean noDelay, IOIterator<DataType> localIterator)
           
SerialRemoteIteratorServer(boolean useCompression, boolean noDelay, Iterator<DataType> localIterator)
           
SerialRemoteIteratorServer(boolean useCompression, boolean noDelay, RemoteStreamMonitor<RemoteInputStreamServer> monitor, int chunkSize, IOIterator<DataType> localIterator)
           
SerialRemoteIteratorServer(boolean useCompression, boolean noDelay, RemoteStreamMonitor<RemoteInputStreamServer> monitor, int chunkSize, IOIterator<DataType> localIterator, int resetNumObjects)
           
SerialRemoteIteratorServer(boolean useCompression, boolean noDelay, RemoteStreamMonitor<RemoteInputStreamServer> monitor, int chunkSize, Iterator<DataType> localIterator)
           
SerialRemoteIteratorServer(boolean useCompression, boolean noDelay, RemoteStreamMonitor<RemoteInputStreamServer> monitor, IOIterator<DataType> localIterator)
           
SerialRemoteIteratorServer(boolean useCompression, boolean noDelay, RemoteStreamMonitor<RemoteInputStreamServer> monitor, Iterator<DataType> localIterator)
           
SerialRemoteIteratorServer(boolean useCompression, IOIterator<DataType> localIterator)
           
SerialRemoteIteratorServer(boolean useCompression, Iterator<DataType> localIterator)
           
SerialRemoteIteratorServer(boolean useCompression, RemoteStreamMonitor<RemoteInputStreamServer> monitor, IOIterator<DataType> localIterator)
           
SerialRemoteIteratorServer(boolean useCompression, RemoteStreamMonitor<RemoteInputStreamServer> monitor, Iterator<DataType> localIterator)
           
SerialRemoteIteratorServer(IOIterator<DataType> localIterator)
           
SerialRemoteIteratorServer(Iterator<DataType> localIterator)
           
 
Method Summary
protected  void closeImpl(boolean readSuccess)
          Cleans up any local resources after the underlying stream server is closed.
protected  void closeIterator()
          Closes any resources held by this iterator.
protected  void serializeObject(ObjectOutputStream ostream, Object obj)
          Writes the given object to the given output stream.
protected  boolean writeNextObject()
          If there are more objects in the iteration, writes an object to the _localOStream and returns true, otherwise returns false.
 
Methods inherited from class com.healthmarketscience.rmiio.RemoteIteratorServer
abort, close, isClosed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RESET_NUM_OBJECTS

public static final int DEFAULT_RESET_NUM_OBJECTS
Default value for the setting indicating how often the ObjectOutputStream should be reset

See Also:
Constant Field Values
Constructor Detail

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(Iterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  Iterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  boolean noDelay,
                                  Iterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  RemoteStreamMonitor<RemoteInputStreamServer> monitor,
                                  Iterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  boolean noDelay,
                                  RemoteStreamMonitor<RemoteInputStreamServer> monitor,
                                  Iterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  boolean noDelay,
                                  RemoteStreamMonitor<RemoteInputStreamServer> monitor,
                                  int chunkSize,
                                  Iterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(IOIterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  IOIterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  boolean noDelay,
                                  IOIterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  RemoteStreamMonitor<RemoteInputStreamServer> monitor,
                                  IOIterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  boolean noDelay,
                                  RemoteStreamMonitor<RemoteInputStreamServer> monitor,
                                  IOIterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  boolean noDelay,
                                  RemoteStreamMonitor<RemoteInputStreamServer> monitor,
                                  int chunkSize,
                                  IOIterator<DataType> localIterator)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorServer

public SerialRemoteIteratorServer(boolean useCompression,
                                  boolean noDelay,
                                  RemoteStreamMonitor<RemoteInputStreamServer> monitor,
                                  int chunkSize,
                                  IOIterator<DataType> localIterator,
                                  int resetNumObjects)
                           throws IOException
Throws:
IOException
Method Detail

writeNextObject

protected boolean writeNextObject()
                           throws IOException
Description copied from class: EncodingRemoteIteratorServer
If there are more objects in the iteration, writes an object to the _localOStream and returns true, otherwise returns false.

Specified by:
writeNextObject in class EncodingRemoteIteratorServer<DataType>
Throws:
IOException

closeIterator

protected void closeIterator()
                      throws IOException
Description copied from class: EncodingRemoteIteratorServer
Closes any resources held by this iterator. Subclasses should flush/close OutputStream during this call.

Overrides:
closeIterator in class EncodingRemoteIteratorServer<DataType>
Throws:
IOException

closeImpl

protected void closeImpl(boolean readSuccess)
                  throws IOException
Description copied from class: RemoteIteratorServer
Cleans up any local resources after the underlying stream server is closed. Since this method is called by the close() method on the underlying remote stream, it will be invoked on a successful remote close.

Overrides:
closeImpl in class RemoteIteratorServer<DataType>
Parameters:
readSuccess - true iff all data was successfully transferred, false otherwise
Throws:
IOException

serializeObject

protected void serializeObject(ObjectOutputStream ostream,
                               Object obj)
                        throws IOException
Writes the given object to the given output stream. The default implementation uses ObjectOutputStream.writeUnshared(java.lang.Object) as well as periodically calls ObjectOutputStream.reset() on the output stream. Subclasses may choose to change this behavior by overriding this method.

Parameters:
ostream - the output stream to which the object should be written
obj - the object to write
Throws:
IOException


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