datasource
Class NetSource

java.lang.Object
  extended by datasource.DataSource
      extended by datasource.NetSource

public class NetSource
extends DataSource

A NetSource is a source that reads a file (sequentially).

To allow code that runs more than one trial in a single run, the server changes its port each trial, by successive adding +1, -1, +1, ... to the base port number passed as a constructor argument. (If it doesn't change port number, the client could connect twice to it before it has finished the first request, which it's not prepared to do).

Version:
$Id: NetSource.java,v 1.8 2010/01/06 01:49:31 zahorjan Exp $

Field Summary
private  java.net.Socket clientSocket
           
private  boolean haveConnection
           
private  java.io.InputStream inStream
           
private  int port
           
private  int portIncrement
           
private  java.net.ServerSocket serverSocket
           
 
Fields inherited from class datasource.DataSource
CLOSED, CONNECTED, STARTING, state
 
Constructor Summary
NetSource(int baseport)
           
 
Method Summary
private  void close()
          Closes the socket, and updates the port number to prepare for being reInit()'ed
protected  int readFromSrc(byte[] buf, int len)
          Called by reader thread in DataSource object.
 void reInit()
          (Re)Initialize this object
 
Methods inherited from class datasource.DataSource
read, readyToRead
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

portIncrement

private int portIncrement

port

private int port

serverSocket

private java.net.ServerSocket serverSocket

clientSocket

private java.net.Socket clientSocket

inStream

private java.io.InputStream inStream

haveConnection

private boolean haveConnection
Constructor Detail

NetSource

public NetSource(int baseport)
Method Detail

reInit

public void reInit()
            throws java.io.IOException
(Re)Initialize this object

Specified by:
reInit in class DataSource
Throws:
java.io.IOException

readFromSrc

protected int readFromSrc(byte[] buf,
                          int len)
                   throws java.io.IOException
Called by reader thread in DataSource object.

Specified by:
readFromSrc in class DataSource
Throws:
java.io.IOException

close

private void close()
            throws java.io.IOException
Closes the socket, and updates the port number to prepare for being reInit()'ed

Throws:
java.io.IOException