public override void Execute() { Packet np = _nameport.Receive(); if (np == null) { return; } _nameport.Close(); string pname = np.Content as string; Drop(np); _outport = (_mother._outputPorts)[pname] as OutputPort; _mother.Trace(Name + ": Accessing output port: " + _outport.Name); _outport.SetSender(this); Packet p; while ((p = _inport.Receive()) != null) { _outport.Send(p); } // outport.close(); _mother.Trace(Name + ": Releasing output port: " + _outport.Name); _outport = null; }
public override void OpenPorts() { _inp = OpenInput("IN"); _outp = OpenOutput("OUT"); _outpd = OpenOutput("OUTD"); _outpf = OpenOutput("OUTF"); }
public override void OpenPorts() { _inportArray = OpenInputArray("IN"); _outport = OpenOutput("OUT"); }
/* public override System.Object[] Introspect() { return new Object[] { "generates a set of Packets under control of a counter" , "OUT", "output", Type.GetType("System.String"), "lines read", "COUNT", "parameter", Type.GetType("System.String"), "Count of number of entities to be generated"}; } */ public override void OpenPorts() { _outport = OpenOutput("OUT"); // _outport.SetType(Type.GetType("System.String")); _count = OpenInput("COUNT"); // _count.SetType(Type.GetType("System.String")); }
public override void OpenPorts() { outputPort = OpenOutput("OUT"); // _outport.SetType(Type.GetType("System.String")); }
/* public override object[] Introspect() { return new object[] { "Read from IN, compare to Regex in CONFIG, write to OUT if match else OUTN.", "Looper. N->M+~M" }; } */ public override void OpenPorts() { _cfgp = OpenInput("CONFIG"); _inp = OpenInput("IN"); _outp = OpenOutput("OUT"); _outpn = OpenOutput("OUTN"); }
public override void OpenPorts() { _inportArray = OpenInputArray("IN"); // inport.setType(Type.GetType("Object")); _outport = OpenOutput("OUT"); }
public override void OpenPorts() { _outport = OpenOutput("OUT"); // _outport.SetType(Type.GetType("System.String")); _source = OpenInput("SOURCE"); // _source.SetType(Type.GetType("System.Stream")); _cfgp = OpenInput("CONFIG"); }
/* public override Object[] Introspect() { return new Object[] { "Convert comma-separated text to an array of ints", "IN", "input", Type.GetType("System.Object"), "input stream", "OUT", "output", Type.GetType("System.Int32[]"), "array of ints"}; } */ public override void OpenPorts() { _inport = OpenInput("IN"); // _inport.SetType(Type.GetType("System.Object")); _outport = OpenOutput("OUT"); }
double _timeout = 10.0; // 10 secs public override void OpenPorts() { _inport = OpenInput("IN"); // _inport.SetType(Type.GetType("System.String")); _port = OpenInput("PORT"); // _destination.SetType(Type.GetType("Stream")); _outport = OpenOutput("OUT"); }
public override void OpenPorts() { _inport = OpenInput("IN"); //_inport.SetType(Type.GetType("System.String")); _destination = OpenInput("DESTINATION"); // _destination.SetType(Type.GetType("Stream")); _cfgp = OpenInput("CONFIG"); _outport = OpenOutput("OUT"); }
//public override Object[] Introspect() //{ // return new Object[] { "handles one input substream for subnet", "NAME", // "input", Type.GetType("System.String"), "name of higher level input port", // "OUT", "output", Type.GetType("System.Object"), // "output from external port (into subnet)" }; // } public override void OpenPorts() { _nameport = OpenInput("NAME"); _outport = OpenOutput("OUT"); }
/* Connects */ /// <summary>Connect an output port of one Component to an input port /// of another /// </summary> protected internal Connection Connect(Component sender, Port outP, Component receiver, Port inP, int size, bool IPCount) { int cap = size; if (size == 0) cap = _defaultCapacity; //string outName = outPort.displayName; //string inName = inPort.displayName; if (outP._displayName.Equals("*")) { outP._name = "*OUT"; outP._displayName = "*OUT"; } if (inP._displayName.Equals("*")) { inP._name = "*IN"; inP._displayName = "*IN"; } OutputPort op = null; if (!outP._displayName.Substring(0, 1).Equals("*")) { op = sender._outputPorts[outP._name]; // try to find output port with port name - no index if (op == null) { FlowError.Complain("Output port not defined in metadata: " + sender._name + "." + outP._displayName); } if (op is OutArray && outP._index == -1) { outP._index = 0; outP._displayName = outP._name + "[" + outP._index + "]"; } if (outP._index > -1 && !(op is OutArray)) { FlowError.Complain("Output port not defined as array in metadata: " + sender._name + "." + outP._displayName); } if (!(op is NullOutputPort) && !(op is OutArray) && op._cnxt != null) { FlowError.Complain("Multiple connections to output port:" + sender._name + ' ' + outP._displayName); } } op = new OutputPort(); op.SetSender(sender); op._name = outP._displayName; op._connected = true; op._fullName = sender._name + "." + outP._displayName; op._traceNetwork = sender._mother; sender._outputPorts.Remove(op._name); sender._outputPorts.Add(op._name, op); /* start processing input port */ IInputPort ip = null; if (!inP._displayName.Substring(0, 1).Equals("*")) { ip = receiver._inputPorts[inP._name]; if (ip == null) { FlowError.Complain("Input port not defined in metadata: " + receiver._name + "." + inP._displayName); } if (ip is ConnArray && inP._index == -1) { inP._index = 0; inP._displayName = inP._name + "[" + inP._index + "]"; } if (inP._index > -1 && !(ip is ConnArray)) { FlowError.Complain("Input port not defined as array in metadata: " + receiver._name + "." + inP._displayName); } } Connection c; if (ip is Connection) { if (size != 0 && size != cap) { FlowError.Complain("Connection capacity does not agree with previous specification\n " + receiver._name + "." + inP._displayName); } c = (Connection)ip; } else { if (ip is InitializationConnection) { FlowError.Complain("Mixed connection to input port: " + receiver._name + "." + inP._displayName); } c = new Connection(cap); c.SetReceiver(receiver); c._name = inP._displayName; c._IPCount = IPCount; c._fullName = receiver._name + "." + c._name; receiver._inputPorts.Remove(c._name); receiver._inputPorts.Add(c._name, c); } c.BumpSenderCount(); op._cnxt = c; c._receiver = receiver; c._fullName = receiver.Name + "." + inP._displayName; return c; }
/* Connects */ /// <summary>Connect an output port of one Component to an input port /// of another /// </summary> protected internal Connection Connect(Component sender, Port outP, Component receiver, Port inP, int size, bool IPCount) { int cap = size; if (size == 0) { cap = _defaultCapacity; } //string outName = outPort.displayName; //string inName = inPort.displayName; if (outP._displayName.Equals("*")) { outP._name = "*OUT"; outP._displayName = "*OUT"; } if (inP._displayName.Equals("*")) { inP._name = "*IN"; inP._displayName = "*IN"; } OutputPort op = null; if (!outP._displayName.Substring(0, 1).Equals("*")) { op = sender._outputPorts[outP._name]; // try to find output port with port name - no index if (op == null) { FlowError.Complain("Output port not defined in metadata: " + sender._name + "." + outP._displayName); } if (op is OutArray && outP._index == -1) { outP._index = 0; outP._displayName = outP._name + "[" + outP._index + "]"; } if (outP._index > -1 && !(op is OutArray)) { FlowError.Complain("Output port not defined as array in metadata: " + sender._name + "." + outP._displayName); } if (!(op is NullOutputPort) && !(op is OutArray) && op._cnxt != null) { FlowError.Complain("Multiple connections to output port:" + sender._name + ' ' + outP._displayName); } } op = new OutputPort(); op.SetSender(sender); op._name = outP._displayName; op._connected = true; op._fullName = sender._name + "." + outP._displayName; op._traceNetwork = sender._mother; sender._outputPorts.Remove(op._name); sender._outputPorts.Add(op._name, op); /* start processing input port */ IInputPort ip = null; if (!inP._displayName.Substring(0, 1).Equals("*")) { ip = receiver._inputPorts[inP._name]; if (ip == null) { FlowError.Complain("Input port not defined in metadata: " + receiver._name + "." + inP._displayName); } if (ip is ConnArray && inP._index == -1) { inP._index = 0; inP._displayName = inP._name + "[" + inP._index + "]"; } if (inP._index > -1 && !(ip is ConnArray)) { FlowError.Complain("Input port not defined as array in metadata: " + receiver._name + "." + inP._displayName); } } Connection c; if (ip is Connection) { if (size != 0 && size != cap) { FlowError.Complain("Connection capacity does not agree with previous specification\n " + receiver._name + "." + inP._displayName); } c = (Connection)ip; } else { if (ip is InitializationConnection) { FlowError.Complain("Mixed connection to input port: " + receiver._name + "." + inP._displayName); } c = new Connection(cap); c.SetReceiver(receiver); c._name = inP._displayName; c._IPCount = IPCount; c._fullName = receiver._name + "." + c._name; receiver._inputPorts.Remove(c._name); receiver._inputPorts.Add(c._name, c); } c.BumpSenderCount(); op._cnxt = c; c._receiver = receiver; c._fullName = receiver.Name + "." + inP._displayName; return(c); }
public override void Execute() { OutputPort subEndPort = null; if (_status != States.Error) { //_network.Trace(this.Name + ": started"); _components.Clear(); //_tracing = _mother._tracing; //_traceFileList = _mother._traceFileList; subEndPort = _outputPorts.GetValueOrDefault("*SUBEND", null); try { CallDefine(); bool res = true; foreach (Component comp in _components.Values) { res &= comp.CheckPorts(); } if (!res) { FlowError.Complain("One or more mandatory connections have been left unconnected: " + Name); } _cdl = new CountDownLatch(_components.Count); Initiate(); // activateAll(); // don't do deadlock testing in subnets - you need to consider the whole net! _deadlockTest = false; WaitForAll(); foreach (IInputPort ip in _inputPorts.Values) { if (ip is InitializationConnection) { InitializationConnection ic = (InitializationConnection)ip; ic.Close(); } } /* * Iterator allout = (outputPorts.values()).iterator(); * * while (allout.hasNext()) { * * * OutputPort op = (OutputPort) allout.next(); op.close(); * * } */ // status = Component.StatusValues.TERMINATED; //will not be set if // never activated // mother.indicateTerminated(this); _network.Trace(this.Name + ": closed down"); if (subEndPort != null) { subEndPort.Send(Create(null)); } } catch (FlowError e) { string s = "Flow Error :" + e; Console.Out.WriteLine("Network: " + s); throw e; } } }
/// <summary>The send function. See OutputPort.send. /// </summary> //UPGRADE_NOTE: Synchronized keyword was removed from method 'send'. Lock expression was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1027"' internal bool Send(Packet packet, OutputPort op) { lock (this) { if (packet == null) { throw new System.ArgumentException(); } _sender = op._sender; if (IsClosed()) { return(false); } //_sender._mother.Trace(Name + ": Sending: " + packet); if (IsEmpty()) { System.Threading.Monitor.PulseAll(this); } while (IsFull()) { if (_dropOldest) { Packet p = _buffer.Take(); Interlocked.Increment(ref Network.dropOlds); _sender._mother.Trace("{0}: DropOldest", _sender.Name); } else { _sender.Status = Component.States.SuspSend; _sender._mother.Trace("{0}: Send/susp", _sender.Name); try { System.Threading.Monitor.Wait(this); } catch (System.Threading.ThreadInterruptedException e) { //UPGRADE_NOTE: Exception 'java.lang.ThreadDeath' was converted to ' ' which has different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1100"' // throw new System.ApplicationException(); IndicateOneSenderClosed(); FlowError.Complain(_sender._name + ": interrupted"); // unreachable code return(false); } // if (Component._network._deadlock) //{ // _sender._thread.Interrupt(); // _sender._mother.Trace(_sender._name + ": Send interrupted because of deadlock"); // // unreachable code // return false; // } _sender = op._sender; _sender.Status = Component.States.Active; _sender._mother.Trace("{0}: Send/resume", _sender.Name); } } if (IsClosed()) { _sender._mother.Trace("{0}: Send/close", _sender.Name); //Interlocked.Increment(ref Network.sends); return(false); } //lock ((_receiver._inputPorts as ICollection).SyncRoot) try { Monitor.Enter(_receiver._lockObject); packet.ClearOwner(); _buffer.Put(packet); if (_receiver.Status == Component.States.Dormant || _receiver.Status == Component.States.NotStarted) { _receiver.Activate(); } else { System.Threading.Monitor.PulseAll(this); } _sender._network._active = true; _sender = null; } catch (ThreadInterruptedException e) { return(false); } finally { Monitor.Exit(_receiver._lockObject); } Interlocked.Increment(ref Network.sends); return(true); } }
/// <summary>The send function. See OutputPort.send. /// </summary> //UPGRADE_NOTE: Synchronized keyword was removed from method 'send'. Lock expression was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1027"' internal bool Send(Packet packet, OutputPort op) { lock (this) { if (packet == null) throw new System.ArgumentException(); _sender = op._sender; if (IsClosed()) { return false; } //_sender._mother.Trace(Name + ": Sending: " + packet); if (IsEmpty()) System.Threading.Monitor.PulseAll(this); while (IsFull()) { if (_dropOldest) { Packet p = _buffer.Take(); Interlocked.Increment(ref Network.dropOlds); _sender._mother.Trace("{0}: DropOldest", _sender.Name); } else { _sender.Status = Component.States.SuspSend; _sender._mother.Trace("{0}: Send/susp", _sender.Name); try { System.Threading.Monitor.Wait(this); } catch (System.Threading.ThreadInterruptedException e) { //UPGRADE_NOTE: Exception 'java.lang.ThreadDeath' was converted to ' ' which has different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1100"' // throw new System.ApplicationException(); IndicateOneSenderClosed(); FlowError.Complain(_sender._name + ": interrupted"); // unreachable code return false; } // if (Component._network._deadlock) //{ // _sender._thread.Interrupt(); // _sender._mother.Trace(_sender._name + ": Send interrupted because of deadlock"); // // unreachable code // return false; // } _sender = op._sender; _sender.Status = Component.States.Active; _sender._mother.Trace("{0}: Send/resume", _sender.Name); } } if (IsClosed()) { _sender._mother.Trace("{0}: Send/close", _sender.Name); //Interlocked.Increment(ref Network.sends); return false; } //lock ((_receiver._inputPorts as ICollection).SyncRoot) try { Monitor.Enter(_receiver._lockObject); packet.ClearOwner(); _buffer.Put(packet); if (_receiver.Status == Component.States.Dormant || _receiver.Status == Component.States.NotStarted) _receiver.Activate(); else System.Threading.Monitor.PulseAll(this); _sender._network._active = true; _sender = null; } catch (ThreadInterruptedException e) { return false; } finally { Monitor.Exit(_receiver._lockObject); } Interlocked.Increment(ref Network.sends); return true; } }
//UPGRADE_TODO: The equivalent of method java.lang.Runnable.run is not an override method. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca5065"' // internal void Run() // implement mainline for thread // runs and keeps running as long as there are input ports to read void ThreadMain() { try { if (IsTerminated() || HasError()) { try { Monitor.Exit(_lockObject); } catch (SynchronizationLockException e) { // do nothing - this is OK! } return; } _status = States.Active; _mother.Trace("{0}: Started", Name); if (!_inputPorts.ContainsKey("*IN")) { _autoInput = null; } else { _autoInput = (IInputPort)(_inputPorts["*IN"]); } if (!_outputPorts.ContainsKey("*OUT")) { _autoOutput = null; } else { _autoOutput = (OutputPort)(_outputPorts["*OUT"]); } if (_autoInput != null) { Packet p = _autoInput.Receive(); if (p != null) { Drop(p); } _autoInput.Close(); } InputStates ist = null; if (SelfStarting) { _autoStarting = true; } else { try { ist = new InputStates(_inputPorts, this); } catch (ThreadInterruptedException ex) { if (IsTerminated() || HasError()) { // if we are in the TERMINATED or ERROR state we terminated intentionally return; } // otherwise there was an error throw ex; } } while (_autoStarting || !ist.allDrained || _autoInput != null || ist.allDrained && MustRun || StackSize() > 0) { _autoInput = null; if (_network._deadlock || IsTerminated()) { break; } _packetCount = 0; foreach (IInputPort port in _inputPorts.Values) { if (port is InitializationConnection) { InitializationConnection icx = port as InitializationConnection; icx.Reopen(); } } _mother.Trace("{0}: Activated", Name); try { Execute(); // do one activation! } catch (ComponentException e) { _mother.Trace("Component Exception: " + Name + " - " + e.Message); if (e.Message.StartsWith("*")) { string s = e.Message.Substring(1); FlowError.Complain("Component Exception: " + Name + " - " + s); } else { Console.Out.WriteLine("! Component Exception: " + Name + " - " + e.Message); } } _mother.Trace("{0}: Deactivated", Name); if (_packetCount != 0) { _mother.Trace(Name + " deactivated holding " + _packetCount + " packets"); FlowError.Complain(_packetCount + " packets not disposed of during Component activation of " + Name); } foreach (IInputPort port in _inputPorts.Values) { if (port is InitializationConnection) { InitializationConnection icx = port as InitializationConnection; if (!icx.IsClosed()) { FlowError.Complain("Component deactivated with IIP port not closed: " + icx.Name); } } } MustRun = false; SelfStarting = false; if (_autoStarting) { break; } // lock ((_inputPorts as ICollection).SyncRoot) //{ try { ist = new InputStates(_inputPorts, this); } catch (ThreadInterruptedException ex) { if (IsTerminated() || HasError()) { // if we are in the TERMINATED or ERROR state we terminated intentionally return; } // otherwise there was an error throw ex; } if (ist.allDrained) { break; } //if (_network._deadlock) //{ // break; // } } // while (!ist.allDrained); //_compLog.Trace("{0}: Terminating", Name); //} // catch (System.Exception t) // { //Console.Out.WriteLine("*** Exception detected in " + Name); // System.Diagnostics.Trace.Fail("*** Exception detected in " + Name + ": " + t.Message); // } //_compLog.Trace("{0}: Terminated", Name); if (_autoOutput != null) { //Packet p = Create(""); //_autoOutput.Send(p); _autoOutput.Close(); } _status = States.Terminated; if (_stack.Count > 0) { FlowError.Complain("Stack not empty at component termination: " + Name); } foreach (IInputPort port in _inputPorts.Values) { if (port is Connection) { Connection cx = port as Connection; if (cx.Count() > 0) { Console.Out.WriteLine("{0}: Component terminated with {1} packets in input connection", cx.Name, cx.Count()); } while (cx.Count() > 0) { Packet p = cx._buffer.Take(); Console.Out.WriteLine(p); } } if (port is InitializationConnection) { InitializationConnection iip = port as InitializationConnection; if (!(iip.IsClosed())) { FlowError.Complain("Component terminated with input port not closed: " + iip.Name); } } } foreach (OutputPort port in _outputPorts.Values) { port.Close(); } //_status = States.Terminated; //will not be set if never activated //_network.NotifyTerminated(); _mother.NotifyTerminated(this); } catch (Exception e) { // don't tell the mother if we are already in the ERROR or TERMINATE state // because then the mother told us to terminate if (!HasError() && !IsTerminated()) { // an error occurred in this component _status = States.Error; // tell the mother _mother.SignalError(e); } } }