using System;
using System.Collections.Generic;
using System.Text;
using Spring.Threading.Helpers;

namespace FBPLib
{
    public class SubNet : Network
    {
        /* *
         * Copyright 2007, 2008, J. Paul Morrison.  At your option, you may copy, 
         * distribute, or make derivative works under the terms of the Clarified Artistic License, 
         * based on the Everything Development Company's Artistic License.  A document describing 
         * this License may be found at http://www.jpaulmorrison.com/fbp/artistic2.htm. 
         * THERE IS NO WARRANTY; USE THIS PRODUCT AT YOUR OWN RISK.
         * */

        public SubNet()
        {
            InitBlock();
        }
        public override void Define()
        {
        }

        public override void Execute()
        {
            // network = mother;
            //tracing = mother.tracing;

            //	ps = mother.ps;
            _compLog.Trace(this.Name + ": started");
            _components.Clear();


            try
            {
                CallDefine();
                _cdl = new CountDownLatch(_components.Count);

                Initiate();
                // activateAll();
                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);
                _compLog.Trace(this.Name + ": closed down");
            }
            catch (FlowError e)
            {
                String s = "Flow Error :" + e;
                Console.Out.WriteLine("Network: " + s);
            }

        }

        public override void OpenPorts()
        {
        }

    }

}
