com.healthmarketscience.rmiio
Class RemoteStreamServer<StreamServerType,StreamType>

java.lang.Object
  extended by com.healthmarketscience.rmiio.RemoteStreamServer<StreamServerType,StreamType>
All Implemented Interfaces:
Closeable, Serializable, Remote, Unreferenced
Direct Known Subclasses:
RemoteInputStreamServer, RemoteOutputStreamServer

public abstract class RemoteStreamServer<StreamServerType,StreamType>
extends Object
implements Remote, Unreferenced, Closeable, Serializable

Common base class for remote stream implementations which handles the basic status of the stream (whether or not it is exported, closed).

Author:
James Ahlborn
See Also:
Serialized Form

Field Summary
protected  RemoteStreamMonitor<StreamServerType> _monitor
          the monitor which is following our progress
protected static int INITIAL_INVALID_SEQUENCE_ID
          the initial sequence id for server methods which have not yet been invoked
protected static int INITIAL_VALID_SEQUENCE_ID
          the initial sequence id for client code which has not yet invoked any remote methods
protected static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
RemoteStreamServer(RemoteStreamMonitor<StreamServerType> monitor)
           
 
Method Summary
 void abort()
          Aborts the current transfer without closing this RemoteStreamServer.
protected  void checkAborted()
          Throws an IOException if the stream has been aborted.
 void close()
          Forces this stream server to close (if not already closed), will break any outstanding client interactions.
protected abstract  void closeImpl(boolean transferSuccess)
          Closes (possibly flushes) the underlying streams and cleans up any resources.
 StreamType export()
          Convenience method which exports this object for use using the exporter retrieved from RemoteStreamExporter.getInstance().
 void exported(RemoteStreamExporter exporter)
          Indicates to this object that it was exported remotely.
protected  void finish(boolean remoteClose, boolean transferSuccess)
          Cleans up after this stream.
protected abstract  StreamServerType getAsSub()
          Returns a handle to this object as a subclass instance.
protected abstract  Object getLock()
          Returns a handle to the object used to lock the underlying stream operations for this remote stream.
abstract  Class<StreamType> getRemoteClass()
           
 boolean isClosed()
           
 void unreferenced()
           
protected  Object writeReplace()
          Manages serialization for all remote stream instances by returning the result of a call to export() on this instance as a Serializable replacement for an instance of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG

INITIAL_INVALID_SEQUENCE_ID

protected static final int INITIAL_INVALID_SEQUENCE_ID
the initial sequence id for server methods which have not yet been invoked

See Also:
Constant Field Values

INITIAL_VALID_SEQUENCE_ID

protected static final int INITIAL_VALID_SEQUENCE_ID
the initial sequence id for client code which has not yet invoked any remote methods

See Also:
Constant Field Values

_monitor

protected transient RemoteStreamMonitor<StreamServerType> _monitor
the monitor which is following our progress

Constructor Detail

RemoteStreamServer

public RemoteStreamServer(RemoteStreamMonitor<StreamServerType> monitor)
Method Detail

export

public StreamType export()
                  throws RemoteException
Convenience method which exports this object for use using the exporter retrieved from RemoteStreamExporter.getInstance().

Throws:
RemoteException

exported

public void exported(RemoteStreamExporter exporter)
              throws RemoteException
Indicates to this object that it was exported remotely. Should be called by the RemoteStreamExporter after this object has been exported.

Parameters:
exporter - the exporter that exported this object
Throws:
RemoteException

unreferenced

public void unreferenced()
Specified by:
unreferenced in interface Unreferenced

isClosed

public final boolean isClosed()
Returns:
true iff this stream server has been closed (one way or another), false otherwise.

close

public final void close()
Forces this stream server to close (if not already closed), will break any outstanding client interactions. Should be called one way or another on the server object (may be left to the unreferenced method if the server object must live beyond the creation method call).

Specified by:
close in interface Closeable

finish

protected final void finish(boolean remoteClose,
                            boolean transferSuccess)
                     throws IOException
Cleans up after this stream. Unexports the Remote object, closes the underlying stream, and makes the final call(s) to the stream monitor.

Parameters:
remoteClose - indicates whether this was a remote close() call or a local cleanup close after a failed transfer.
transferSuccess - true iff all data was successfully transferred, false otherwise
Throws:
IOException

abort

public final void abort()
                 throws IOException
Aborts the current transfer without closing this RemoteStreamServer. This method is thread safe. This will usually shutdown a currently working transfer faster than just closing the RemoteStreamServer directly (because this will cause the client to get an IOException instead of a RemoteException, which may cause retries, etc.). This RemoteStreamServer should still be closed as normal.

Throws:
IOException

checkAborted

protected final void checkAborted()
                           throws IOException
Throws an IOException if the stream has been aborted. Should be called at the beginning of any method which accesses the underlying stream, except for the close method.

Throws:
IOException

writeReplace

protected final Object writeReplace()
                             throws ObjectStreamException
Manages serialization for all remote stream instances by returning the result of a call to export() on this instance as a Serializable replacement for an instance of this class. While generally the developer should be managing the call to export, implementing this method in a useful way makes the simple things simple (passing a reference to a server implementation in a remote method call will "do the right thing", replacing the actual reference to this instance with a reference to an automagically generated remote reference to this server instance).

Returns:
an exported remote stub for this instance
Throws:
NotSerializableException - if the export attempt fails
ObjectStreamException

closeImpl

protected abstract void closeImpl(boolean transferSuccess)
                           throws IOException
Closes (possibly flushes) the underlying streams and cleans up any resources. Called by the finish() method.

Parameters:
transferSuccess - true iff all data was successfully transferred, false otherwise
Throws:
IOException

getLock

protected abstract Object getLock()
Returns a handle to the object used to lock the underlying stream operations for this remote stream.


getRemoteClass

public abstract Class<StreamType> getRemoteClass()
Returns:
the class of the remote stream interface for this server

getAsSub

protected abstract StreamServerType getAsSub()
Returns a handle to this object as a subclass instance.



Copyright © 2006-2009 Health Market Science. All Rights Reserved.