hypercast
Class HCastInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--hypercast.HCastInputStream

public class HCastInputStream
extends java.io.InputStream

This is the class used to receive data from other nodes


Constructor Summary
HCastInputStream(hypercast.StreamManager sm, byte[] streamID)
          Constructs the BoundedBuffer with a size.
 
Method Summary
 int available()
          * @return the number of bytes available that can be read without blocking
 void blockingWrite(byte[] payload)
          Writes a message to the BoundedBuffer
 void close()
          Closes this input stream and releases any system resources associated with the stream.
 int getSoTimeout()
          Get the timeout time for a read operation.
 int getStreamID()
          Deprecated. use getStreamIdentifier
 int getStreamIdentifier()
           
 boolean isAssignedToApplication()
           
 boolean markSupported()
          * @ Tests if this input stream supports the mark and reset methods.
 void nonblockingWrite(byte[] payload, int off, int len)
          Writes a message to the DropHeadMessageBuffer
 int read()
          Reads a byte from the BoundedBuffer.
 int read(byte[] b)
          Reads a byte from the BoundedBuffer.
 int read(byte[] b, int off, int len)
          Reads a byte from the BoundedBuffer.
 void setAssignedFlag(boolean a)
          set the flag indicating if the stream has been assigned to the application
 void setSoTimeout(int i)
          Set the timeout time for a read operation.
 long skip(long n)
          Skips over and discards n bytes of data from this input stream.
 
Methods inherited from class java.io.InputStream
mark, reset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HCastInputStream

public HCastInputStream(hypercast.StreamManager sm,
                        byte[] streamID)
Constructs the BoundedBuffer with a size. Simply initializes the parameters

Method Detail

getSoTimeout

public int getSoTimeout()
Get the timeout time for a read operation.


setSoTimeout

public void setSoTimeout(int i)
Set the timeout time for a read operation.


read

public int read()
         throws java.io.IOException
Reads a byte from the BoundedBuffer.

Algorithm:
1. Waits till the buffer is non-empty
2. Copies first byte in the buffer
3. Increments the Start pointer modulo buffer length
4. Decreases size of the buffer
5. Notifies any other process waiting
6. Returns the copied element

Specified by:
read in class java.io.InputStream
Returns:
the first byte in the buffer
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads a byte from the BoundedBuffer.

Algorithm:
1. Waits till the buffer is non-empty
2. Copies first byte in the buffer
3. Increments the Start pointer modulo buffer length
4. Decreases size of the buffer
5. Notifies any other process waiting
6. Returns the copied element

Overrides:
read in class java.io.InputStream
Returns:
the bytes in the buffer
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Reads a byte from the BoundedBuffer.

Overrides:
read in class java.io.InputStream
Returns:
the first bytes in the buffer
java.io.IOException

nonblockingWrite

public void nonblockingWrite(byte[] payload,
                             int off,
                             int len)
Writes a message to the DropHeadMessageBuffer

Algorithm:
1. checks if buffer is full
2. Places New bytes at the end of the buffer
3. Increase number of bytes
4. Notifies all threads waiting

Parameters:
payload - byte array to be added into the buffer

blockingWrite

public void blockingWrite(byte[] payload)
                   throws java.lang.InterruptedException
Writes a message to the BoundedBuffer

Algorithm:
1. checks if buffer is full
2. Places New packet at the end of the buffer
3. Increase number of elements
4. Notifies all threads waiting

Parameters:
payload - byte array to be added into the buffer
java.lang.InterruptedException

close

public void close()
Closes this input stream and releases any system resources associated with the stream.

Overrides:
close in class java.io.InputStream

available

public int available()
              throws java.io.IOException
* @return the number of bytes available that can be read without blocking

Overrides:
available in class java.io.InputStream
java.io.IOException

markSupported

public boolean markSupported()
* @ Tests if this input stream supports the mark and reset methods.

Overrides:
markSupported in class java.io.InputStream

skip

public long skip(long n)
          throws java.io.IOException
Skips over and discards n bytes of data from this input stream. If the bytes of available data in the buffer is less than specified length, clean up the buffer and return -1.

Overrides:
skip in class java.io.InputStream
java.io.IOException

getStreamID

public int getStreamID()
Deprecated. use getStreamIdentifier

Returns:
stream id

getStreamIdentifier

public int getStreamIdentifier()
Returns:
stream id

isAssignedToApplication

public boolean isAssignedToApplication()
Returns:
true if the stream is assigned to the application

setAssignedFlag

public void setAssignedFlag(boolean a)
set the flag indicating if the stream has been assigned to the application