예제 #1
0
        static void Main(string[] args)
        {
            ModeTracker modeTracker = new ModeTracker();

            IPAddress address, masterAddress;
            int port, masterPort;

            // Set up configuration
            string inputLine = "";
            foreach (string arg in args)
                inputLine += arg + " ";

            InputParser inputParser = new InputParser(inputLine);
            inputParser.ParseInput();

            address = getIPAddress();
            port = inputParser.Port;

            // If address was given 
            if (inputParser.MasterAddress == null)
            {
                primaryMode = true;

                modeTracker.InitiatePrimary(address, port);
            }
            else 
            {
                primaryMode = false;
                masterAddress = inputParser.MasterAddress;
                masterPort = inputParser.MasterPort;

                modeTracker.InitiateBackup(address, port, masterAddress, masterPort);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            /************ Create node object ************/
            RegisterType type = RegisterType.TaskManager;
            byte parallelThreads = 5;
            string[] problems = { "DVRP"};

            NetworkNode node = new NetworkNode(type, parallelThreads, problems);
            //NetworkNode node = new NetworkNode();

            /************ Setup connection ************/
            string inputLine = "";
            foreach (string arg in args)
                inputLine += arg + " ";

            InputParser inputParser = new InputParser(inputLine);
            inputParser.ParseInput();

            IPAddress address = inputParser.Address;
            int port = inputParser.Port;

            SmartConsole.PrintLine("I'm a " + node.Type, SmartConsole.DebugLevel.Advanced);
            NetworkClient client = new NetworkClient(address, port);

            /************ Setup Logic modules ************/

            // system tracker
            SystemTracker systemTracker = new SystemTracker(node);

            MessageHandler messageHandler = new MessageHandler(systemTracker, client);

            MessageProcessor messageProcessor = new MessageProcessor(messageHandler, client, node);

            node.MessageProcessor = messageProcessor;

            /************ Init all threads ************/
            for (int i = 0; i < parallelThreads; i++)
            {
                node.TaskThreads[i] = new TaskThread(i, problems[0], messageProcessor, (int)node.Id);
            }

            /************ Register ************/
            client.Connect();
            SmartConsole.PrintLine("Sending Register message", SmartConsole.DebugLevel.Advanced);
            messageProcessor.Communicate(node.ToRegisterMessage());

            KeepAliveTimer keepAliveTimer = new KeepAliveTimer(messageProcessor, systemTracker);
            /************ Start Logic modules ************/
            keepAliveTimer.Start();

            Object mutex = new Object();
            // TODO Thread pool waiting

            lock (mutex)
            {
                Monitor.Wait(mutex);
            }
            
        }
예제 #3
0
        static void Main(string[] args)
        {
            RegisterType type = RegisterType.ComputationalClient;
            byte parallelThreads = 5;
            string[] problems = { "DVRP" };

            SolveRequestMessage solveRequestMessage = new SolveRequestMessage();

            string inputLine = "";
            foreach (string arg in args)
                inputLine += arg + " ";

            InputParser inputParser = new InputParser(inputLine);
            inputParser.ParseInput();

            IPAddress address = inputParser.Address;
            int port = inputParser.Port;

            NetworkNode node = new NetworkNode(type, parallelThreads, problems) { Timeout = CLIENT_REQUEST_FREQUENCY };



            SmartConsole.PrintLine("ComputationalClient starting work", SmartConsole.DebugLevel.Advanced);

            NetworkClient client = new NetworkClient(address, port);

            for (; ; )
            {
                /*************** Register *****************/

                doWork = true;

                SmartConsole.PrintLine("Type in a file path", SmartConsole.DebugLevel.Advanced);
                String filePath = Console.ReadLine();
                solveRequestMessage = loadDataFromDisc(filePath);

                /******  setup logic modules *****************/
                SystemTracker systemTracker = new SystemTracker(node);
                MessageHandler messageHandler = new MessageHandler(systemTracker, client);
                MessageProcessor messageProcessor = new MessageProcessor(messageHandler, client, node);
                KeepAliveTimer keepAliveTimer = new KeepAliveTimer(messageProcessor, systemTracker);

                messageHandler.keepAliveTimer = keepAliveTimer;

                node.MessageProcessor = messageProcessor;

                /************ send solve request *****************/
                client.Connect();

                messageProcessor.Communicate(solveRequestMessage);
                COMP_TIME = DateTime.Now;

                while (doWork)
                {
                    Thread.Sleep(1000);
                }

                /*Object mutex = new Object();

                lock (mutex)
                {
                    Monitor.Wait(mutex);
                }*/
            }
        }