next up previous contents
Next: The RPC class Up: Communication infra-structure: Channels Previous: Communication infra-structure: Channels   Contents

The Port class

Access to logical channels is provided through a Java class called a Port. The Port dresses up and adds functionality to an internet port, but should not be confused with this lower-level idea. The Port interface does not provide direct access to port numbers or internet addresses.

In the existing prototype the public interface to the Port class is

  public class Port {

    // Constructor.

    public Port() ;

    // Channel creation.

    public static synchronized void channel(Port P, Port Q) ;

    // Public members for communication.

    public synchronized void send(byte data []) ;
    public synchronized int recv(byte data []) ;
    public synchronized byte [] recv() ;

    public synchronized void sendInt(int data) ;
    public synchronized int recvInt() ;

    public synchronized void sendChan(Port S) ;
    public synchronized void recvChan(Port R) ;
  }

The constructor Port.Port() creates an unconnected port.

The static member Port.channel(Port, Port) connects two current unconnected Ports. [These are Ports ``inside the current program'', so to speak. The Port itself is purely a local entity.] Logically, it creates a channel within the local processor, and binds the two ends of the channel to the two ports.

A channel supports bi-directional communication (with unbounded buffering). send(byte []) and recv(byte []) send and receive messages. A message is an atomic entity. If an n-byte vector is output on one end of the channel with send, the recv operation at the other end must be prepared to accept an n-byte vector. revc() is a variant of recv(byte []) which allocates space for the received message internally, and returns it to the caller.

sendInt and recvInt are provided for convenience. They are simply wrappers on send(byte []) and recv(byte []).

The more interesting operations are sendChan(Port) and recvChan(Port). The argument of sendChan should be a connected port--a port with a bound channel-end. The argument of recvChan should be an unconnected port. The effect of a sendChan(P)/recvChan(Q) communication is to transfer the channel-end, leaving P unconnected, and the channel-end bound to Q. This may involve transferring the channel-end between different processors, if the communication channel connects different processors.

In the prototype implementation every Port has an associated ServerSocket and an associated input handler thread. The use of a server socket restricts use of Ports to Java applications. The implementation is fairly straightforward, but requires some care in the protocol for notifying a Port when its peer Port (the Port connected to the other end of its channel) is in motion, and in ensuring that input data currently buffered in a port is physically communicated at the same time as the channel-end is logically transferred.

It should be possible to provide alternate (probably less efficient) implementations that can be used within applets.


next up previous contents
Next: The RPC class Up: Communication infra-structure: Channels Previous: Communication infra-structure: Channels   Contents
Bryan Carpenter 2002-07-12