Exemplo n.º 1
0
        public override void Execute()
        {
            Packet np = _nameport.Receive();

            if (np == null)
            {
                return;
            }
            _nameport.Close();
            string pname = np.Content as string;

            Drop(np);

            _inport = (_mother._inputPorts)[pname] as IInputPort;
            _mother.Trace(Name + ": Accessing input port: " + _inport.Name);
            Packet p;
            // I think this works!
            Component oldReceiver = _inport.Receiver;

            if (_inport is InitializationConnection)
            {
                InitializationConnection iico = (InitializationConnection)_inport;
                InitializationConnection iic  = new InitializationConnection(
                    iico.Content, this);
                iic.Name = iico.Name;
                // iic.network = iico.network;

                p       = iic.Receive();
                p.Owner = this;
                _outport.Send(p);
                iic.Close();
            }
            else
            {
                Connection cnxt = _inport as Connection;
                cnxt.SetReceiver(this);
                while ((p = cnxt.Receive()) != null)
                {
                    p.Owner = this;
                    _outport.Send(p);
                }
                // cnxt.setReceiver(oldReceiver); // moved down, as per JavaFBP
            }

            // inport.close();

            _mother.Trace(Name + ": Releasing input port: " + _inport.Name);
            _inport.SetReceiver(oldReceiver);
            // inport = null;
        }
Exemplo n.º 2
0
        public override void Execute()
        {

            Packet np = _nameport.Receive();
            if (np == null)
            {
                return;
            }
            _nameport.Close();
            string pname = np.Content as string;
            Drop(np);

            _inport = (_mother._inputPorts)[pname] as IInputPort;
            _mother.Trace(Name + ": Accessing input port: " + _inport.Name);
            Packet p;
            // I think this works!
            Component oldReceiver = _inport.Receiver;
            if (_inport is InitializationConnection)
            {
                InitializationConnection iico = (InitializationConnection)_inport;
                InitializationConnection iic = new InitializationConnection(
                        iico.Content, this);
                iic.Name = iico.Name;
                // iic.network = iico.network;

                p = iic.Receive();
                p.Owner = this;
                _outport.Send(p);
                iic.Close();
            }
            else
            {
                Connection cnxt = _inport as Connection;
                cnxt.SetReceiver(this);
                while ((p = cnxt.Receive()) != null)
                {
                    p.Owner = this;
                    _outport.Send(p);
                }
               // cnxt.setReceiver(oldReceiver); // moved down, as per JavaFBP
            }

            // inport.close();

            _mother.Trace(Name + ": Releasing input port: " + _inport.Name);
            _inport.SetReceiver(oldReceiver);
            // inport = null;
        }
Exemplo n.º 3
0
        /// <summary>Build InitializationConnection object
        /// </summary>

        /// <summary>Build InitializationConnection object
        /// </summary>

        protected internal void Initialize(System.Object content, Component receiver, Port inP)
        {
            IInputPort ip = receiver._inputPorts[inP._displayName];

            if (ip == null)
            {
                FlowError.Complain("Input port not defined in metadata: " + receiver._name + "." + inP._displayName);
            }
            if (ip is Connection || ip is ConnArray)
            {
                FlowError.Complain("IIP port cannot be shared: " + receiver._name + "." + inP._displayName);
            }

            if (ip is InitializationConnection)
            {
                FlowError.Complain("IIP port already used: " + 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);
            }

            InitializationConnection ic = new InitializationConnection(content, receiver);

            ic._name = receiver._name + "." + inP._displayName;
            //ic.network = this;

            receiver._inputPorts.Remove(inP._displayName);
            receiver._inputPorts.Add(inP._displayName, ic);
        }
Exemplo n.º 4
0
        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["*SUBEND"];

                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;
                }
            }
        }
Exemplo n.º 5
0
        //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);
                            icx.Close();
                        }
                    }
                    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);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>Build InitializationConnection object
        /// </summary>
        /// <summary>Build InitializationConnection object
        /// </summary>
        protected internal void Initialize(System.Object content, Component receiver, Port inP)
        {
            IInputPort ip = receiver._inputPorts[inP._displayName];
            if (ip == null)
            {
                FlowError.Complain("Input port not defined in metadata: " + receiver._name + "." + inP._displayName);
            }
            if (ip is Connection || ip is ConnArray)
            {
                FlowError.Complain("IIP port cannot be shared: " + receiver._name + "." + inP._displayName);
            }

            if (ip is InitializationConnection)
            {
                FlowError.Complain("IIP port already used: " + 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);
            }

            InitializationConnection ic = new InitializationConnection(content, receiver);
            ic._name = receiver._name + "." + inP._displayName;
            //ic.network = this;

            receiver._inputPorts.Remove(inP._displayName);
            receiver._inputPorts.Add(inP._displayName, ic);
        }