// Path: src/main/java/com/healthmarketscience/rmiio/socket/RMISocket.java
// public class RMISocket implements Closeable
// {
//   /** local InputStream for receiving data from local Source which has been
//       passed to remote system */
//   private final PipedInputStream _in;
//   /** the local source for this socket which must be passed to the remote
//       system */
//   private final Source _source;
//   /** optional source for the remote system allowing bi-directional
//       communication */
//   private Source _remoteSource;
// 
//   public RMISocket() throws IOException {
//     this(null);
//   }
// 
//   public RMISocket(Source remoteSource) throws IOException {
//     _in = new PipedInputStream(RemoteInputStreamServer.DEFAULT_CHUNK_SIZE);
//     PipedOutputStream out = new PipedOutputStream(_in);
//     _source = new Source(new SimpleRemoteOutputStream(out));
//     _remoteSource = remoteSource;
//   }
// 
//   /**
//    * Returns the InputStream which can be used to read data sent through the
//    * socket via the local Source which has been passed to the remote system.
//    */
//   public InputStream getInputStream() throws IOException {
//     return _in;
//   }
// 
//   /**
//    * Returns the OutputStream of the remote Source, if one has been associated
//    * with this socket (thus allowing bi-directional communication).
//    *
//    * @return the OutputStream for the remote Source
//    */
//   public OutputStream getOutputStream() throws IOException {
//     if(_remoteSource == null) {
//       throw new IllegalStateException("no remote source has been associated with this socket");
//     }
//     return _remoteSource.getOutputStream();
//   }
// 
//   /**
//    * Returns the local Source for this socket.  This must be passed to the
//    * remote system so that it can send data through this socket.
//    */
//   public Source getSource() {
//     return _source;
//   }
// 
//   /**
//    * Closes the local InputStream and the remote Source if one has been
//    * associated with this socket.
//    */
//   @Override
//   public void close() throws IOException {
//     try {
//       if(_remoteSource != null) {
//         _remoteSource.close();
//       }
//     } finally {
//       RmiioUtil.closeQuietly(_in);
//     }
//   }
// 
//   /**
//    * Returns the remote Source associated with this socket, if any.  This must
//    * be passed to the remote system in order for this socket to function.
//    */
//   public Source getRemoteSource() {
//     return _remoteSource;
//   }
// 
//   /**
//    * Associates a remote Source with this socket, allowing it to be
//    * bi-directional (at which point the {@link #getOutputStream} method may be
//    * called).
//    */
//   public void setRemoteSource(Source newRemoteSource) {
//     _remoteSource = newRemoteSource;
//   }
// 
//   /**
//    * Serializable stub which must be passed to the remote system in order to
//    * enable it to send data through this socket.
//    */
//   public static class Source implements Serializable, RemoteClient, Closeable
//   {
//     private static final long serialVersionUID = 20120625L;
// 
//     /** the handle to the actual remote interface */
//     private final RemoteOutputStream _remoteOut;
//     /** optional client-side RemoteRetry policy */
//     private transient RemoteRetry _retry;
//     /** the actual client-side OutputStream implementation, initialized on
//         demand by a call to getOutputStream */
//     private transient OutputStream _localOut;
//     /** optional client-side target value for the byte size of the packets of
//         data sent over the wire */
//     private transient Integer _chunkSize;
// 
//     private Source(RemoteOutputStream out) {
//       _remoteOut = out;
//     }
// 
//     public OutputStream getOutputStream() throws IOException {
//       if(_localOut == null) {
//         _localOut = RemoteOutputStreamClient.wrap(_remoteOut, _retry,
//                                                   _chunkSize);
//       }
//       return _localOut;
//     }
// 
//     @Override
//     public void setRemoteRetry(RemoteRetry retry) {
//       _retry = retry;
//     }
// 
//     /**
//      * May be called on the client-side in order to set the target chunk size
//      * used by the underlying implementation.  <b>Must</b> be called prior to
//      * the first call to {@link #getOutputStream}, as once the underlying
//      * stream is initialized, the chunk size cannot be changed.
//      * @param chunkSize target value for the byte size of the packets of data
//      *                  sent over the wire.  note that this is a suggestion,
//      *                  actual packet sizes may vary.  if <code>null</code>,
//      *                  {@link RemoteOutputStreamClient#DEFAULT_CHUNK_SIZE}
//      *                  will be used.
//      */
//     public void setChunkSize(Integer chunkSize) {
//       _chunkSize = chunkSize;
//     }
// 
//     @Override
//     public void close() throws IOException {
//       getOutputStream().close();
//     }
//   }
// }


import java.io.IOException;
import java.rmi.Remote;
import com.healthmarketscience.rmiio.socket.RMISocket;
/*
Copyright (c) 2012 James Ahlborn

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package examples.socket;



/**
 * A simple Remote interface for an RMI server which enables the creation of a
 * socket-like connection over RMI.
 *
 * @author James Ahlborn
 */
public interface RemoteSocketServer extends Remote
{
// Path: src/main/java/com/healthmarketscience/rmiio/socket/RMISocket.java
// public class RMISocket implements Closeable
// {
//   /** local InputStream for receiving data from local Source which has been
//       passed to remote system */
//   private final PipedInputStream _in;
//   /** the local source for this socket which must be passed to the remote
//       system */
//   private final Source _source;
//   /** optional source for the remote system allowing bi-directional
//       communication */
//   private Source _remoteSource;
// 
//   public RMISocket() throws IOException {
//     this(null);
//   }
// 
//   public RMISocket(Source remoteSource) throws IOException {
//     _in = new PipedInputStream(RemoteInputStreamServer.DEFAULT_CHUNK_SIZE);
//     PipedOutputStream out = new PipedOutputStream(_in);
//     _source = new Source(new SimpleRemoteOutputStream(out));
//     _remoteSource = remoteSource;
//   }
// 
//   /**
//    * Returns the InputStream which can be used to read data sent through the
//    * socket via the local Source which has been passed to the remote system.
//    */
//   public InputStream getInputStream() throws IOException {
//     return _in;
//   }
// 
//   /**
//    * Returns the OutputStream of the remote Source, if one has been associated
//    * with this socket (thus allowing bi-directional communication).
//    *
//    * @return the OutputStream for the remote Source
//    */
//   public OutputStream getOutputStream() throws IOException {
//     if(_remoteSource == null) {
//       throw new IllegalStateException("no remote source has been associated with this socket");
//     }
//     return _remoteSource.getOutputStream();
//   }
// 
//   /**
//    * Returns the local Source for this socket.  This must be passed to the
//    * remote system so that it can send data through this socket.
//    */
//   public Source getSource() {
//     return _source;
//   }
// 
//   /**
//    * Closes the local InputStream and the remote Source if one has been
//    * associated with this socket.
//    */
//   @Override
//   public void close() throws IOException {
//     try {
//       if(_remoteSource != null) {
//         _remoteSource.close();
//       }
//     } finally {
//       RmiioUtil.closeQuietly(_in);
//     }
//   }
// 
//   /**
//    * Returns the remote Source associated with this socket, if any.  This must
//    * be passed to the remote system in order for this socket to function.
//    */
//   public Source getRemoteSource() {
//     return _remoteSource;
//   }
// 
//   /**
//    * Associates a remote Source with this socket, allowing it to be
//    * bi-directional (at which point the {@link #getOutputStream} method may be
//    * called).
//    */
//   public void setRemoteSource(Source newRemoteSource) {
//     _remoteSource = newRemoteSource;
//   }
// 
//   /**
//    * Serializable stub which must be passed to the remote system in order to
//    * enable it to send data through this socket.
//    */
//   public static class Source implements Serializable, RemoteClient, Closeable
//   {
//     private static final long serialVersionUID = 20120625L;
// 
//     /** the handle to the actual remote interface */
//     private final RemoteOutputStream _remoteOut;
//     /** optional client-side RemoteRetry policy */
//     private transient RemoteRetry _retry;
//     /** the actual client-side OutputStream implementation, initialized on
//         demand by a call to getOutputStream */
//     private transient OutputStream _localOut;
//     /** optional client-side target value for the byte size of the packets of
//         data sent over the wire */
//     private transient Integer _chunkSize;
// 
//     private Source(RemoteOutputStream out) {
//       _remoteOut = out;
//     }
// 
//     public OutputStream getOutputStream() throws IOException {
//       if(_localOut == null) {
//         _localOut = RemoteOutputStreamClient.wrap(_remoteOut, _retry,
//                                                   _chunkSize);
//       }
//       return _localOut;
//     }
// 
//     @Override
//     public void setRemoteRetry(RemoteRetry retry) {
//       _retry = retry;
//     }
// 
//     /**
//      * May be called on the client-side in order to set the target chunk size
//      * used by the underlying implementation.  <b>Must</b> be called prior to
//      * the first call to {@link #getOutputStream}, as once the underlying
//      * stream is initialized, the chunk size cannot be changed.
//      * @param chunkSize target value for the byte size of the packets of data
//      *                  sent over the wire.  note that this is a suggestion,
//      *                  actual packet sizes may vary.  if <code>null</code>,
//      *                  {@link RemoteOutputStreamClient#DEFAULT_CHUNK_SIZE}
//      *                  will be used.
//      */
//     public void setChunkSize(Integer chunkSize) {
//       _chunkSize = chunkSize;
//     }
// 
//     @Override
//     public void close() throws IOException {
//       getOutputStream().close();
//     }
//   }
// }


// Path: src/test/java/examples/socket/RemoteSocketServer.java
import java.io.IOException;
import java.rmi.Remote;
import com.healthmarketscience.rmiio.socket.RMISocket;

/*
Copyright (c) 2012 James Ahlborn

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package examples.socket;



/**
 * A simple Remote interface for an RMI server which enables the creation of a
 * socket-like connection over RMI.
 *
 * @author James Ahlborn
 */
public interface RemoteSocketServer extends Remote
{
  public RMISocket.Source connect(RMISocket.Source remoteSource) 