DRCL JavaSim API

drcl.comp.lib.bytestream
Class ByteStreamPeer

java.lang.Object
  |
  +--drcl.DrclObj
        |
        +--drcl.comp.lib.bytestream.ByteStreamPeer
All Implemented Interfaces:
ByteStreamConstants, java.lang.Cloneable, ObjectDuplicable, java.io.Serializable

public class ByteStreamPeer
extends DrclObj
implements ByteStreamConstants

ByteStreamPeer is a helper class to conduct the ByteStreamContract both as an initiator and a reactor. This class provides blocked send() and receive() methods to send/receive byte streams to/from the peer.

Version:
1.0, 6/2001
Author:
Hung-ying Tyan
See Also:
ByteStreamContract, Serialized Form

Fields inherited from interface drcl.comp.lib.bytestream.ByteStreamConstants
ERROR, QUERY, REPORT, SEND
 
Constructor Summary
ByteStreamPeer()
           
ByteStreamPeer(Port down_)
           
 
Method Summary
 java.io.InputStream getInputStream()
           
 java.io.OutputStream getOutputStream()
           
 int getReceiveBufferSize()
           
 void handle(ByteStreamContract.Message msg_)
          Handles a message from the peer.
 void hookup(Port down_)
           
 java.lang.String info()
           
 int receive()
          Receives whatever is currently buffered from the lower layer protocol.
 int receive(byte[] buffer_)
          Receives a buffer of data from the lower layer protocol.
 int receive(byte[] buffer_, int size_)
          Receives a maximun of size_ data from the lower layer protocol.
 int receive(byte[] buffer_, int offset_, int size_)
          Receives a maximun of size_ data from the lower layer protocol.
 int receive(int size_)
          Receives size_ bytes of data from the lower layer protocol.
 void reset()
           
 void send(byte[] buffer_)
          Sends a buffer of data from buffer_ thru the down port.
 void send(byte[] buffer_, int len_)
          Sends len_ bytes of data from buffer_ thru the down port.
 void send(byte[] buffer_, int offset_, int len_)
          Sends len_ bytes of data from buffer_ thru the down port.
 void send(int len_)
          Sends len_ bytes of data thru the down port.
 void setReceiveBufferSize(int size_)
           
 
Methods inherited from class drcl.DrclObj
clone, duplicate, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteStreamPeer

public ByteStreamPeer()

ByteStreamPeer

public ByteStreamPeer(Port down_)
Method Detail

reset

public void reset()

hookup

public void hookup(Port down_)

getInputStream

public java.io.InputStream getInputStream()

getOutputStream

public java.io.OutputStream getOutputStream()

info

public java.lang.String info()

setReceiveBufferSize

public void setReceiveBufferSize(int size_)

getReceiveBufferSize

public int getReceiveBufferSize()

send

public void send(int len_)
          throws java.io.IOException
Sends len_ bytes of data thru the down port. The lower layer protocol is supposed to contruct and send pseudo-packets with no real data in it.
Parameters:
len_ - number of bytes to send.
See Also:
ByteStreamContract

send

public void send(byte[] buffer_)
          throws java.io.IOException
Sends a buffer of data from buffer_ thru the down port.
Parameters:
buffer_ - where is put the data to be sent.
See Also:
ByteStreamContract

send

public void send(byte[] buffer_,
                 int len_)
          throws java.io.IOException
Sends len_ bytes of data from buffer_ thru the down port. The lower layer (transport) is supposed to contruct and send pseudo-packets with no real data in it if buffer_ is null.
Parameters:
buffer_ - where is put the data to be sent.
len_ - number of bytes to send.
See Also:
ByteStreamContract

send

public void send(byte[] buffer_,
                 int offset_,
                 int len_)
          throws java.io.IOException
Sends len_ bytes of data from buffer_ thru the down port. The lower layer (transport) is supposed to contruct and send pseudo-packets with no real data in it if buffer_ is null.
Parameters:
buffer_ - where is put the data to be sent.
offset_ - offset to the buffer where to start sending data.
len_ - number of bytes to send.
See Also:
ByteStreamContract

handle

public void handle(ByteStreamContract.Message msg_)
Handles a message from the peer.

receive

public int receive()
            throws java.io.IOException
Receives whatever is currently buffered from the lower layer protocol. No real data is received.
Returns:
the number of bytes that are really received. 0 if EOF is encountered.
See Also:
ByteStreamContract

receive

public int receive(int size_)
            throws java.io.IOException
Receives size_ bytes of data from the lower layer protocol. No real data is received.
Parameters:
size - of data expected to receive.
Returns:
the number of bytes that are really received. 0 if EOF is encountered.
See Also:
ByteStreamContract

receive

public int receive(byte[] buffer_)
            throws java.io.IOException
Receives a buffer of data from the lower layer protocol. This method will be blocked until some bytes are filled in.
Parameters:
buffer_ - the buffer to store the incoming data.
Returns:
the number of bytes that are really received. 0 if EOF is encountered.
See Also:
ByteStreamContract

receive

public int receive(byte[] buffer_,
                   int size_)
            throws java.io.IOException
Receives a maximun of size_ data from the lower layer protocol. No real data is received if buffer_ is null. If size_ is greater than 0, this method will be blocked until exactly the size of data is filled to the buffer. If size_ is less than 0, then the method will grab all the data available right now till the buffer is full.
Parameters:
buffer_ - the buffer to store the incoming data.
size - of data expected to receive.
Returns:
the number of bytes that are really received. 0 if EOF is encountered.
See Also:
ByteStreamContract

receive

public int receive(byte[] buffer_,
                   int offset_,
                   int size_)
            throws java.io.IOException
Receives a maximun of size_ data from the lower layer protocol. No real data is received if buffer_ is null. If size_ is greater than 0, this method will be blocked until exactly the size of data is filled to the buffer. If size_ is less than 0, then the method will grab all the data available right now till the buffer is full.
Parameters:
buffer_ - the buffer to store the incoming data.
offset_ - offset in the buffer to start storing the incoming data.
size_ - size of data expected to receive.
Returns:
the number of bytes that are really received. 0 if EOF is encountered.
See Also:
ByteStreamContract

DRCL JavaSim API

Copyright © 2001 - DRCL, OSU     ~ Back to JavaSim Home ~