Nodenet Problem Set Javadocs

nodenet
Class Channel

java.lang.Object
  extended bynodenet.Channel
All Implemented Interfaces:
InputChannel, NodeNetElement, OutputChannel, Resettable, java.lang.Runnable, java.io.Serializable

public class Channel
extends java.lang.Object
implements NodeNetElement, Resettable, InputChannel, OutputChannel, java.io.Serializable

A Channel object is a NodeNetElement that connects two Nodes. A channel implements both the InputChannel and OutputChannel interfaces. Channels have an assocated capacity and latency. The capacity of a channel indicates how many packets may be present before a ChannelFullException is thrown. The latency of a channel is a measure of how long (in ms) a packet takes to travel from the input to the output.

Version:
$Id: Channel.java,v 1.9 2004/01/14 21:43:17 gus Exp $
Author:
Todd C. Parnell, tparnell@ai.mit.edu, Patrick G. Heck, gus.heck@olin.edu
See Also:
Serialized Form

Field Summary
static int MAX_CAPACITY
          the maximum allowable capacity
static int MAX_LATENCY
          the maximum allowable latency
 
Constructor Summary
Channel(Node start, Node end)
          Creates a new Channel with the given start and end nodes.
Channel(Node start, Node end, boolean enabled, int latency, int capacity)
          Build a channel that is fully configured.
 
Method Summary
 void configure()
          Display a configuratin dialog to the user and record changes made to the configuration via this dialog.
 boolean contains(int x, int y)
          Determine if this element contains the specified point.
 boolean contains(java.awt.Point p)
          Determine if this element contains the specified point.
 void destroy()
          Destroy the Channel.
 boolean equals(java.lang.Object o)
          Determines if two Channels are equal.
protected  void finalize()
           
 int getCapacity()
           
 int getLatency()
           
 java.lang.String getName()
          Get the name of this instance.
 boolean isDestroyed()
          Test to see if this element has been destroyed.
 boolean isEditable()
           
 boolean isEnabled()
          Determine if this element is enabled.
 boolean isSelected()
          Determine the selection stae of this element.
 void notifyOfDestruction(NodeNetElement nne)
          Notify this that a NodeNetElement has been destroyed.
 void paint(java.awt.Graphics g)
          Paint ourself to a graphics context.
 java.lang.Object readObject()
          Read an object from the channel.
 void reset()
          Custom de-serialization.
 void run()
           
 void setCapacity(int cap)
           
 void setEnabled(boolean b)
          Set the enabled property.
 void setLatency(int lat)
           
 void setName(java.lang.String n)
          Set the name of this instance.
 void setSelected(boolean b)
          Notify this object that it should render itself as selected or unselected.
 void start()
          begin exhibiting the behavior of this element This method is called when a simulation is started.
 void stop()
          Stop exhibiting the behavior of this element.
 java.lang.String templateXML()
           
 void writeObject(java.lang.Object o)
          Insert an object into the channel.
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_LATENCY

public static final int MAX_LATENCY
the maximum allowable latency

See Also:
Constant Field Values

MAX_CAPACITY

public static final int MAX_CAPACITY
the maximum allowable capacity

See Also:
Constant Field Values
Constructor Detail

Channel

public Channel(Node start,
               Node end)
        throws SameNodeException
Creates a new Channel with the given start and end nodes. If start and end are the same (as determined by equals), throws SameNodeException.


Channel

public Channel(Node start,
               Node end,
               boolean enabled,
               int latency,
               int capacity)
        throws SameNodeException
Build a channel that is fully configured. This is used for recreation of networks from a template file.

Method Detail

writeObject

public void writeObject(java.lang.Object o)
                 throws ChannelFullException,
                        ChannelDisabledException
Insert an object into the channel.

Specified by:
writeObject in interface OutputChannel
Parameters:
o - The object to be inserted.
Throws:
ChannelFullException - if the number of objects in the channel already equals or exceeds the capacity.
ChannelDisabledException - if the channel is currently disabled

readObject

public java.lang.Object readObject()
                            throws ChannelEmptyException,
                                   ChannelDisabledException
Read an object from the channel.

Specified by:
readObject in interface InputChannel
Returns:
the oldest (in terms of insertion time) object in the channel
Throws:
ChannelEmptyException - if no objects are present in the channel or the oldest object has not propigated through the channel yet (due to a non-zero latency).
ChannelDisabledException - if the channel is diabled

getCapacity

public int getCapacity()

setCapacity

public void setCapacity(int cap)

getLatency

public int getLatency()

setLatency

public void setLatency(int lat)

setSelected

public void setSelected(boolean b)
Description copied from interface: NodeNetElement
Notify this object that it should render itself as selected or unselected.

Specified by:
setSelected in interface NodeNetElement
Parameters:
b - the new selection state

isSelected

public boolean isSelected()
Description copied from interface: NodeNetElement
Determine the selection stae of this element.

Specified by:
isSelected in interface NodeNetElement
Returns:
the current selection state

setEnabled

public void setEnabled(boolean b)
Description copied from interface: NodeNetElement
Set the enabled property. This property determines whether or not the element participates in the simulation. Elements that are disabled should never have any behavior beyond the fact that they exist. Enabled elements interact with other elements by generating, absorbing or transmitting packets.

Specified by:
setEnabled in interface NodeNetElement
Parameters:
b - the new state of the enabled property

isEnabled

public boolean isEnabled()
Description copied from interface: NodeNetElement
Determine if this element is enabled.

Specified by:
isEnabled in interface NodeNetElement
Returns:
the current state of the enabled property.
See Also:
NodeNetElement.setEnabled(boolean)

contains

public boolean contains(int x,
                        int y)
Description copied from interface: NodeNetElement
Determine if this element contains the specified point.

Specified by:
contains in interface NodeNetElement
Parameters:
x - the x coordinate of the point to test
y - the y coordinate of the point to test
Returns:
true if the point is contained, false otherwise.

contains

public boolean contains(java.awt.Point p)
Description copied from interface: NodeNetElement
Determine if this element contains the specified point.

Specified by:
contains in interface NodeNetElement
Parameters:
p - the point to test
Returns:
true if the point is contained, false otherwise.

setName

public void setName(java.lang.String n)
Description copied from interface: NodeNetElement
Set the name of this instance. Names may or may not be unique, and may or may not play a role in the functionality of the class.

Specified by:
setName in interface NodeNetElement
Parameters:
n - The name to use for this element.

getName

public java.lang.String getName()
Description copied from interface: NodeNetElement
Get the name of this instance.

Specified by:
getName in interface NodeNetElement
Returns:
then name of this element
See Also:
NodeNetElement.setName(String)

destroy

public void destroy()
Destroy the Channel. destroy() should be called whenever a Channel will no longer be used. When destroyed, Channels notify all connected Nodes of the impending destruction. Note: Channel.finalize() automatically calls destroy().

Specified by:
destroy in interface NodeNetElement

isDestroyed

public boolean isDestroyed()
Description copied from interface: NodeNetElement
Test to see if this element has been destroyed.

Specified by:
isDestroyed in interface NodeNetElement
Returns:
true if the object is destroyed false otherwise.

notifyOfDestruction

public void notifyOfDestruction(NodeNetElement nne)
Notify this that a NodeNetElement has been destroyed. Typically, this method will be called by one of the two connected Nodes. If that is the case, the channel destroys itself.

Specified by:
notifyOfDestruction in interface NodeNetElement
Parameters:
nne - the element that is being destroyed

isEditable

public boolean isEditable()

configure

public void configure()
Description copied from interface: NodeNetElement
Display a configuratin dialog to the user and record changes made to the configuration via this dialog.

Specified by:
configure in interface NodeNetElement

paint

public void paint(java.awt.Graphics g)
Description copied from interface: NodeNetElement
Paint ourself to a graphics context.

Specified by:
paint in interface NodeNetElement
Parameters:
g - The graphics context on which to render ourself

start

public void start()
Description copied from interface: NodeNetElement
begin exhibiting the behavior of this element This method is called when a simulation is started.

Specified by:
start in interface NodeNetElement

stop

public void stop()
Description copied from interface: NodeNetElement
Stop exhibiting the behavior of this element. This method is called on all NodeNetElements withing a simulation pannel when a simulation is stopped.

Specified by:
stop in interface NodeNetElement

run

public void run()
Specified by:
run in interface java.lang.Runnable

equals

public boolean equals(java.lang.Object o)
Determines if two Channels are equal.


templateXML

public java.lang.String templateXML()

finalize

protected void finalize()
                 throws java.io.IOException
Throws:
java.io.IOException

reset

public void reset()
Custom de-serialization. Get NodeBehavior & color, then start Thread. private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); this.channel_objects = new DefaultQueue(); this.timeStamps = new DefaultQueue(); for (int i=0; i
Specified by:
reset in interface Resettable

Nodenet Problem Set Javadocs