net.clackrouter.component.base
Class ClackPort

java.lang.Object
  extended by net.clackrouter.component.base.ClackPort

public class ClackPort
extends java.lang.Object

The ClackPort handles the actual transfer of packets between different components that have been connected.

The direction will be either "in" or "out". two ports can be connected only if their directions are opposite The type will be either "push" or "pull". two ports can be connected only if their types are the same.

The port classes do the actual work of transfering packets between two components. See methods pushOut(VNSPacket), pullIn(), acceptPushRequest(VNSPacket), and acceptPullRequest() for details

Ports are connected using the static connectPorts(ClackPort, ClackPort) method

Ports have a type, which is the Java Class object that represents a type of VNSPacket. A port can accept packets of any class that is a sub-type of its specified type, thus VNSPacket is the most general type and can accept any packet.

For push ports, many output ports can be connected to a single input port, but a single output port can only be connected to a single input port. For pull ports, each input port can only be connected to a single output port, but an output port can be connected to multiple input ports.


Field Summary
static int DIR_IN
           
static int DIR_OUT
           
static int METHOD_PULL
           
static int METHOD_PUSH
           
 
Constructor Summary
ClackPort(ClackComponent owner, int port_num, java.lang.String description, int method, int direction, java.lang.Class type)
           
 
Method Summary
 VNSPacket acceptPullRequest()
          Called by a connected port that is trying to pull a packet from this port.
 void acceptPushRequest(VNSPacket packet)
          Called by a connected port that is pushing a packet to us.
static java.lang.String connectPorts(ClackPort source, ClackPort dest)
          The preferred method for connecting two ports.
static void disconnectPorts(ClackPort source, ClackPort dest)
          Disconnects two ports
 ClackPort getConnectedPort(int index)
           
 int getDirection()
           
 java.lang.String getDirString()
           
 RouterWire getListeningWire()
          Get RouterWire that is connected to this port (used for RouterWire highlighting).
 int getMethod()
           
 java.lang.String getMethodString()
           
 int getNumConnectedPorts()
           
 ClackComponent getOwner()
           
 int getPortNumber()
           
 java.lang.String getTextDescription()
           
 java.lang.Class getType()
           
 boolean isConnectedTo(ClackPort p)
          Determine if this port is already connected to another port.
 VNSPacket pullIn()
          Called by the parent component when it wants to try and pull a packet in through this port.
 void pushOut(VNSPacket packet)
          Called by the parent component when it wants to send (push) a packet out this port.
 void setListeningWire(RouterWire w)
          Set RouterWire that is connected to this port (used for RouterWire highlighting).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

METHOD_PUSH

public static int METHOD_PUSH

METHOD_PULL

public static int METHOD_PULL

DIR_IN

public static int DIR_IN

DIR_OUT

public static int DIR_OUT
Constructor Detail

ClackPort

public ClackPort(ClackComponent owner,
                 int port_num,
                 java.lang.String description,
                 int method,
                 int direction,
                 java.lang.Class type)
Method Detail

connectPorts

public static java.lang.String connectPorts(ClackPort source,
                                            ClackPort dest)

The preferred method for connecting two ports.

Performs checks to assure that the connection is valid, returning an error String if it encounters a problem. We check both basic issues like method, direction and number of connections, and also call the more advanced type checking algorithm to assure that this connection does not allow any type failures Returning null denotes success

Parameters:
source - the output port originating packets in this connection
dest - the input port receiving packet in this connection
Returns:
error message, or null on success

disconnectPorts

public static void disconnectPorts(ClackPort source,
                                   ClackPort dest)
Disconnects two ports


pushOut

public void pushOut(VNSPacket packet)

Called by the parent component when it wants to send (push) a packet out this port.

It simply calls the acceptPushRequest() method on the port it is connected to. Also performs run-time checks to make sure port semantics are not violated.

As a source port, we also take care of enforcing the router speed delay and highlighting the RouterWire


acceptPushRequest

public void acceptPushRequest(VNSPacket packet)
Called by a connected port that is pushing a packet to us. The port just passes the packet on to its parent component after performing error checking.


pullIn

public VNSPacket pullIn()
Called by the parent component when it wants to try and pull a packet in through this port.

This method performs error checking and simply calls acceptPullRequest() on the port it is connected to only valid if this port is a pull port.


acceptPullRequest

public VNSPacket acceptPullRequest()
Called by a connected port that is trying to pull a packet from this port.

This port asks its parent component if it has any packets to be pulled on this port, and then then sends a packet to our connected port if there is a packet.

As a source port, we also take care of enforcing the router speed delay and highlighting the RouterWire


getType

public java.lang.Class getType()

getMethod

public int getMethod()

getDirection

public int getDirection()

getTextDescription

public java.lang.String getTextDescription()

getMethodString

public java.lang.String getMethodString()

getDirString

public java.lang.String getDirString()

getOwner

public ClackComponent getOwner()

getConnectedPort

public ClackPort getConnectedPort(int index)

getNumConnectedPorts

public int getNumConnectedPorts()

getPortNumber

public int getPortNumber()

isConnectedTo

public boolean isConnectedTo(ClackPort p)
Determine if this port is already connected to another port.


setListeningWire

public void setListeningWire(RouterWire w)
Set RouterWire that is connected to this port (used for RouterWire highlighting).


getListeningWire

public RouterWire getListeningWire()
Get RouterWire that is connected to this port (used for RouterWire highlighting).