com.healthmarketscience.rmiio
Class SerialRemoteIteratorClient<DataType>

java.lang.Object
  extended by com.healthmarketscience.rmiio.RemoteIteratorClient<DataType>
      extended by com.healthmarketscience.rmiio.SerialRemoteIteratorClient<DataType>
All Implemented Interfaces:
CloseableIOIterator<DataType>, IOIterator<DataType>, RemoteClient, RemoteIterator<DataType>, Closeable, Serializable

public class SerialRemoteIteratorClient<DataType>
extends RemoteIteratorClient<DataType>
implements Serializable

Implementation of RemoteIteratorClient which uses java serialization to receive objects from the RemoteIteratorServer. Objects are deserialized from the underlying remote input stream as needed and returned to the ultimate consumer of the objects.

Note, the objects are read from the ObjectInputStream using the ObjectInputStream.readUnshared() method. This is because memory can build up in the ObjectInputStream 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 deserializeObject(java.io.ObjectInputStream) method can be overriden by a custom subclass to change this behavior.

Author:
James Ahlborn
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.healthmarketscience.rmiio.CloseableIOIterator
CloseableIOIterator.Adapter<DataType>
 
Field Summary
 
Fields inherited from interface com.healthmarketscience.rmiio.RemoteClient
DEFAULT_RETRY
 
Constructor Summary
SerialRemoteIteratorClient(RemoteIteratorServer<DataType> server)
           
SerialRemoteIteratorClient(RemoteIteratorServer<DataType> server, RemoteStreamExporter exporter)
           
 
Method Summary
protected  void closeIterator()
          Closes any resources held by this iterator.
protected  Object deserializeObject(ObjectInputStream istream)
          Reads the next object from the given input stream.
protected  void initialize(InputStream istream)
          Initializes the subclass with a handle to the underlying remote input stream.
protected  DataType readNextObject()
          Reads the next object from the underlying input stream and returns it.
 
Methods inherited from class com.healthmarketscience.rmiio.RemoteIteratorClient
close, hasNext, next, setRemoteRetry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerialRemoteIteratorClient

public SerialRemoteIteratorClient(RemoteIteratorServer<DataType> server)
                           throws IOException
Throws:
IOException

SerialRemoteIteratorClient

public SerialRemoteIteratorClient(RemoteIteratorServer<DataType> server,
                                  RemoteStreamExporter exporter)
                           throws IOException
Throws:
IOException
Method Detail

initialize

protected void initialize(InputStream istream)
                   throws IOException
Description copied from class: RemoteIteratorClient
Initializes the subclass with a handle to the underlying remote input stream. Will be called before any call to readNextObject().

Specified by:
initialize in class RemoteIteratorClient<DataType>
Throws:
IOException

readNextObject

protected DataType readNextObject()
                           throws IOException
Description copied from class: RemoteIteratorClient
Reads the next object from the underlying input stream and returns it.

Specified by:
readNextObject in class RemoteIteratorClient<DataType>
Throws:
IOException

closeIterator

protected void closeIterator()
                      throws IOException
Description copied from class: RemoteIteratorClient
Closes any resources held by this iterator.

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

deserializeObject

protected Object deserializeObject(ObjectInputStream istream)
                            throws IOException,
                                   ClassNotFoundException
Reads the next object from the given input stream. The default implementation uses ObjectInputStream.readUnshared(). Subclasses may choose to change this behavior by overriding this method.

Parameters:
istream - the input stream from which to read the next object
Returns:
the next object read
Throws:
IOException
ClassNotFoundException


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