|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.clackrouter.component.base.ClackComponent
public abstract class ClackComponent
ClackComponent is the abstract base class for all component blocks that comprise router functionality.
Each ClackComponent has a collection of ClackPort
objects, each of which represents either a packet input or
output for the packet processing block. ClackPort objects handle the actual passing of packets between ClackComponents.
There are two main methods of transfering packets:
The first is "pushing" packets, where components receive packets via the acceptPacket(VNSPacket, int)
method. Packets are pushed out ports using the ClackPort.pushOut(VNSPacket)
method of ClackPort objects.
The second mechanism is "pulling" packets, in which a component uses the ClackPort.pullIn()
to ask a connected
component if it has a packet available for processing. ClackComponents respond to these queries using the
handlePullRequest(int)
method.
The ClackComponentListener
class can be used to keep track of component events by registering as a listener
to any class extending ClackComponent.
Nested Class Summary | |
---|---|
protected class |
ClackComponent.Waiter
|
Field Summary | |
---|---|
protected ComponentCell |
componentCell
The JGraph component cell representing this ClackComponent |
protected boolean |
m_has_error
|
protected javax.swing.JTextArea |
m_log
Text log console visible from the components properties view Text is added by both the log() and error() methods |
protected java.lang.String |
m_name
Component's name, unique within a single router |
protected int |
m_num_ports
Number of ports used by this component |
int |
m_packetcount_in
Total number of packets that have arrived at component input ports (modified by ClackPort object) |
int |
m_packetcount_out
Total number of packets that have exited component output ports (modified by ClackPort object) |
protected ClackPort[] |
m_ports
Contains all ports used by this components |
protected java.util.ArrayList |
mListeners
List of components implementing the |
protected Router |
mRouter
Router containing this component |
protected boolean |
pendingError
|
static int |
SIGNAL_ERROR_LEN_MSEC
|
static int |
UNIQUE_COUNT
Unique counter |
protected ClackPaintable |
view
|
Constructor Summary | |
---|---|
ClackComponent(Router r,
java.lang.String name)
Constructor, should be called by all sub-classes to set-up the component |
Method Summary | |
---|---|
void |
acceptPacket(VNSPacket packet,
int port_number)
The starting point for packet-processing when packets are "pushed" to this component. |
ClackComponent |
createCopy()
Clones the component using reflection to create a deep copy. |
void |
createInputPullPort(int port_num,
java.lang.String descr,
java.lang.Class type)
|
void |
createInputPushPort(int port_num,
java.lang.String descr,
java.lang.Class type)
|
void |
createOutputPullPort(int port_num,
java.lang.String descr,
java.lang.Class type)
|
void |
createOutputPushPort(int port_num,
java.lang.String descr,
java.lang.Class type)
|
void |
error(java.lang.String s)
Writes an error message to the component console log and prints it to Standard Error |
void |
fireListeners(ClackComponentEvent e)
for each reportable event, this calls the ClackComponentListener.componentEvent(ClackComponentEvent) method of each listener |
java.awt.Color |
getColor()
The color this component should be rendered in, assuming a standard component rendering by the ComponentView.ComponentRenderer class. |
ComponentCell |
getComponentCell()
Retrieve the ComponentCell object representing this component in the Router Graph |
ClackView |
getHierarchicalView()
Supplies hierarchical view that implements ClackView if isHierarchical() is true |
javax.swing.JTextArea |
getLog()
Get a reference to the console log of this component |
java.lang.String |
getName()
Get component name, which is unique within a single router |
int |
getNumPorts()
Get the total number of ports (input + output) for this component |
int |
getPacketCountIn()
The total number of packets to have entered this component |
int |
getPacketCountOut()
The total number of packets to leave this component |
boolean |
getPendingError()
|
ClackPort |
getPort(int port_num)
Get a reference to a specific port, by number |
javax.swing.JPanel |
getPropertiesView()
Method for getting the properties view associated with this component Property views are used to display more detailed information about internal component state. |
Router |
getRouter()
Get the router that contains this component |
java.util.Properties |
getSerializableProperties(boolean isTransient)
Used to get all values the component would like to serialize to file. |
long |
getTime()
|
java.lang.String |
getTypeName()
The simple name that identifies this type of component. |
static int |
getUniqueCount()
Get an integer identifier unique for this type of component |
VertexView |
getView(JGraph graph,
CellMapper mapper)
Returns the View object used to render this component in the Router Graph. |
VNSPacket |
handlePullRequest(int port_number)
Called when a neighboring component wishes to "pull" a packet from this component. |
boolean |
hasError()
Tells GUI is this component recently experienced an error |
void |
initializeProperties(java.util.Properties props)
Method used to initialize a component based on serialized properties values saved to a file. |
boolean |
isHierarchical()
Tells whether this component is hierarchical, that is, capable of being zoomed into within a Clack Router. |
boolean |
isModifying()
Reports whether this component modifies packets passed through it This value is used by the static checking algorithm used to make sure port connections are valid. |
void |
log(java.lang.String s)
Writes a message to the log console |
void |
notifyAlarm()
call-back method implemented by the code setting the alarm. |
void |
poll()
Callback method to implement component functionality that is not initiated by a packet push. |
void |
registerListener(ClackComponentListener listener)
Classes that want to be updated on component events implement the ClackComponentListener
interface and send a reference of themselves to this method. |
protected void |
sendOutPort(VNSPacket p,
int port_num)
Conveniance method to push a packet out a particular port |
void |
setAlarm(long msecs_from_now)
Sets a timer |
void |
setComponentCell(ComponentCell cell)
Used to set the ComponentCell object representing this component in the Router Graph |
void |
setName(java.lang.String name)
set component's name |
void |
setPendingError(boolean e)
|
protected void |
setupPorts(int num_ports)
Allocates an array of ClackPort objects to be used by this component |
void |
setView(ClackPaintable v)
Set the view associate with this ClackComponent |
void |
showErrorDialog(java.lang.String e)
|
protected void |
signalError()
|
void |
try_repaint()
|
void |
unregisterListener(ClackComponentListener listener)
Removes component from list of objects receiving notifications about this component |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int UNIQUE_COUNT
public static final int SIGNAL_ERROR_LEN_MSEC
protected ClackPort[] m_ports
protected int m_num_ports
protected java.lang.String m_name
protected ClackPaintable view
public int m_packetcount_in
public int m_packetcount_out
protected javax.swing.JTextArea m_log
protected Router mRouter
protected ComponentCell componentCell
protected java.util.ArrayList mListeners
method
protected boolean m_has_error
protected boolean pendingError
Constructor Detail |
---|
public ClackComponent(Router r, java.lang.String name)
r
- the router hosting this componentname
- of the component, unique within the routerMethod Detail |
---|
protected void setupPorts(int num_ports)
num_ports
- the number of ports to createpublic VNSPacket handlePullRequest(int port_number)
Called when a neighboring component wishes to "pull" a packet from this component.
This function should only be valid for port numbers that are defined as pull ports.
This is enforced by the ClackPort
class. By default, we return nothing.
port_number
- The port that a packet is being requested on
public void acceptPacket(VNSPacket packet, int port_number)
The starting point for packet-processing when packets are "pushed" to this component.
The default implementation warns that the packet is being ignored.
packet
- The pushed packetport_number
- The number of the port that this packet is arriving onpublic void poll()
Callback method to implement component functionality that is not initiated by a packet push.
The pull method is often used to implement a "pull" component, or to serve as a packet source.
The Router calls poll() once per processing loop if the component has been registered using the
Router.registerForPoll(ClackComponent)
method.
public void setAlarm(long msecs_from_now)
Alarm
setAlarm
in interface Alarm
msecs_from_now
- milliseconds later in "clack time" that the alarm will fire.public void notifyAlarm()
Alarm
notifyAlarm
in interface Alarm
public java.util.Properties getSerializableProperties(boolean isTransient)
Used to get all values the component would like to serialize to file.
These values are stored as String -> String pairs in a Properties
object. These
properties will be passed to initializeProperties(Properties)
when the Component is recreated.
Serialization can be transient or not, which determines whether all or just some of the internal component state is saved. Transient serialization means that some properties will be saved which may make this serialized file invalid for use on different network or router set-ups. For example, saving info specific to the IP addresses of a certain topology would only happen if transient serialization was used. However, it can be desireable to save these properties when setting up exact demonstrations.
By default we have no properties to serialize, so we return an empty object
isTransient
- flag indicating if serialization is transient
public void initializeProperties(java.util.Properties props)
Method used to initialize a component based on serialized properties values saved to a file.
By default, no action is performed
props
- all property values serialized for this componentpublic javax.swing.JPanel getPropertiesView()
public void registerListener(ClackComponentListener listener)
ClackComponentListener
interface and send a reference of themselves to this method.
listener
- listener to be addedpublic void unregisterListener(ClackComponentListener listener)
listener
- listener to be removedpublic void fireListeners(ClackComponentEvent e)
ClackComponentListener.componentEvent(ClackComponentEvent)
method of each listener
e
- describing what kind of an event occured, which is passed to each listenerpublic int getNumPorts()
public ClackPort getPort(int port_num)
port_num
- public boolean isHierarchical()
public ClackView getHierarchicalView()
ClackView
if isHierarchical()
is true
public void setComponentCell(ComponentCell cell)
ComponentCell
object representing this component in the Router Graph
cell
- - the corresponding ComponentCellpublic ComponentCell getComponentCell()
ComponentCell
object representing this component in the Router Graph
public VertexView getView(JGraph graph, CellMapper mapper)
graph
- the Router Graphmapper
- the CellMapper associated with this Router Graph
public ClackComponent createCopy()
public void error(java.lang.String s)
s
- the error message to printpublic void log(java.lang.String s)
s
- the log messagepublic boolean isModifying()
public void setName(java.lang.String name)
public static int getUniqueCount()
public java.lang.String getName()
public Router getRouter()
getRouter
in interface Alarm
public int getPacketCountIn()
public int getPacketCountOut()
public javax.swing.JTextArea getLog()
public java.awt.Color getColor()
The color this component should be rendered in, assuming a standard component rendering by the
ComponentView.ComponentRenderer
class.
Other renderers may ignore this value.
public java.lang.String getTypeName()
default implementation is simply the class name with no package information
public boolean hasError()
protected void signalError()
public void try_repaint()
public void setView(ClackPaintable v)
public void createInputPushPort(int port_num, java.lang.String descr, java.lang.Class type)
public void createInputPullPort(int port_num, java.lang.String descr, java.lang.Class type)
public void createOutputPushPort(int port_num, java.lang.String descr, java.lang.Class type)
public void createOutputPullPort(int port_num, java.lang.String descr, java.lang.Class type)
public void showErrorDialog(java.lang.String e)
public long getTime()
public boolean getPendingError()
public void setPendingError(boolean e)
protected void sendOutPort(VNSPacket p, int port_num)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |