X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fdatamodel%2Fpn%2FProcessNetwork.java;fp=dol%2Fsrc%2Fdol%2Fdatamodel%2Fpn%2FProcessNetwork.java;h=b41facca98a2f39adddfa6c3f5a98c059ae145f9;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/datamodel/pn/ProcessNetwork.java b/dol/src/dol/datamodel/pn/ProcessNetwork.java new file mode 100644 index 0000000..b41facc --- /dev/null +++ b/dol/src/dol/datamodel/pn/ProcessNetwork.java @@ -0,0 +1,189 @@ +/* $Id: ProcessNetwork.java 1 2010-02-24 13:03:05Z haidw $ */ +package dol.datamodel.pn; + +import java.util.Vector; + +import dol.visitor.PNVisitor; + + +/** + * This class defines a process network. + */ +public class ProcessNetwork extends Resource { + + /** + * Constructor to create a process network with a name, + * empty process list and empty channel list. + */ + public ProcessNetwork(String name) { + super(name); + _processList = new Vector(); + _channelList = new Vector(); + _varList = new Vector(); + _connectionList = new Vector(); + } + + /** + * Accept a visitor + * + * @param x visitor object + */ + public void accept(PNVisitor x) { + x.visitComponent(this); + } + + /** + * Clone this ProcessNetwork. + * + * @return new instance of the ProcessNetwork + */ + @SuppressWarnings("unchecked") + public Object clone() { + ProcessNetwork newObj = (ProcessNetwork) super.clone(); + newObj.setProcessList((Vector)_processList.clone()); + newObj.setChannelList((Vector)_channelList.clone()); + newObj.setVarList((Vector)_varList.clone()); + newObj.setConnectionList((Vector)_connectionList.clone()); + return (newObj); + } + + /** + * Get the process list of a ProcessNetwork. + * + * @return the process list + */ + public Vector getProcessList() { + return _processList; + } + + /** + * Get the process basenames. + * + * @return process basenames + */ + public Vector getProcessBasenames() { + Vector basenames = new Vector(); + for (Process p : _processList) { + String basename = p.getBasename(); + if (!basenames.contains(basename)) { + basenames.add(basename); + } + } + return basenames; + } + + /** + * Set the process list of a ProcessNetwork. + * + * @param processList The new list + */ + public void setProcessList(Vector processList) { + _processList = processList; + } + + /** + * Get the channel list of a ProcessNetwork + * + * @return the channel list + */ + public Vector getChannelList() { + return _channelList; + } + + /** + * Set the channel list of a ProcessNetwork + * + * @param channelList The new list + */ + public void setChannelList(Vector channelList) { + _channelList = channelList; + } + + public Vector getVarList() { return _varList; } + public void setVarList(Vector list) { _varList = list; } + + public void setConnectionList(Vector list) { _connectionList = list; } + public Vector getConnectionList() { return _connectionList; } + + + /** + * Return a description of the ProcessNetwork. + * + * @return a description of the ProcessNetwork. + */ + public String toString() { + return "ProcessNetwork: " + getName(); + } + + /** + * Return a process which has a specific name. Return null if + * process cannot be found. + * + * @param name the name of the process to search for. + * @return the process with the specific name. + */ + public Process getProcess(String name) { + for (Process process : _processList) { + if (process.getName().equals(name)) { + return process; + } + } + return null; + } + + /** + * Return a channel which has a specific name. Return null if + * not found. + * + * @param name the name of the channel to search for. + * @return the channel with the specific name. + */ + public Channel getChannel(String name) { + for (Channel c : _channelList) { + if (c.getName().equals(name)) { + return c; + } + } + return null; + } + + /** + * In this version, we only deal with the flattened process network. + * Connection infomation is filled to each process and channel for fast + * iteration. + */ + public void fillPortPeerInfo() throws Exception { + for (Connection c : getConnectionList()) { + Port originPort = c.getOriginPort(); + Port targetPort = c.getTargetPort(); + originPort.setPeerResource(c.getTarget()); + originPort.setPeerPort(targetPort); + targetPort.setPeerResource(c.getOrigin()); + targetPort.setPeerPort(originPort); + } + + //for each sw channel, determine which processes it connects + for (Connection c : getConnectionList()) { + if (c.getOrigin() instanceof Process) { + Channel channel = (Channel)c.getTarget(); + channel.setOrigin((Process)c.getOrigin()); + } + else if (c.getOrigin() instanceof Channel) { + Channel channel = (Channel)c.getOrigin(); + channel.setTarget((Process)c.getTarget()); + } + } + } + + /** list of the processes in the ProcessNetwork. */ + protected Vector _processList = null; + + /** list of the channels in the ProcessNetwork. */ + protected Vector _channelList = null; + + /** list of variables in the ProcessNetwork */ + protected Vector _varList = null; + + /** list of connections in the ProcessNetwork */ + protected Vector _connectionList = null; +}