Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var connectionAdapter = new ConnectionAdapter();

            var operatorService = new OperatorServices(connectionAdapter);

            Console.WriteLine(" [x] Awaiting RPC requests");
            Console.WriteLine("Press [enter] to exit.");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
 private static void sendAddressesToPreviousOP()
 {
     foreach (string address in _operator.previousAddresses)
     {
         operatorServices = (OperatorServices)Activator.GetObject(
             typeof(OperatorServices),
             address);
         string replica = _operator.id + "-" + _operator.repID;
         operatorServices.setSendAddresses(replica, _operator.myAddress);
     }
 }
Ejemplo n.º 3
0
 public void destroyTupleInAllReplicas(int id)
 {
     foreach (string address in _operator.myReplicaAddresses)
     {
         if (address != null)
         {
             operatorServices = (OperatorServices)Activator.GetObject(
                 typeof(OperatorServices),
                 address);
             operatorServices.destroyTuple(id);
         }
     }
 }
Ejemplo n.º 4
0
 public void addProcessingNumberToAllReplicas()
 {
     _operator.processingNumber++;
     foreach (string address in _operator.myReplicaAddresses)
     {
         if (address != null)
         {
             operatorServices = (OperatorServices)Activator.GetObject(
                 typeof(OperatorServices),
                 address);
             operatorServices.addProcessingNumber();
         }
     }
 }
Ejemplo n.º 5
0
        private static void doRemoteCommand(string address, string command)
        {
            try
            {
                OperatorServices opServicesRemote = (OperatorServices)Activator.GetObject(
                    typeof(OperatorServices),
                    address);
                int time = 0;
                if (command.Contains("INTERVAL"))
                {
                    string[] infos = command.Split('-');
                    command = infos[0];
                    time    = Int32.Parse(infos[1]);
                }
                switch (command)
                {
                case "START":
                    opServicesRemote.startToProcess();
                    break;

                case "INTERVAL":
                    opServicesRemote.intervalOperator(time);
                    break;

                case "FREEZE":
                    opServicesRemote.freezeOperator();
                    break;

                case "UNFREEZE":
                    opServicesRemote.unfreezeOperator();
                    break;

                case "STATUS":
                    opServicesRemote.printStatus();
                    break;

                case "CRASH":
                    opServicesRemote.crashOperator();
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                PuppetMaster.formPuppetMaster.addNewLineToLog("I think that Operator in " + address + " was murdered");
            }
        }
Ejemplo n.º 6
0
        public void sendTuples()
        {
            Console.WriteLine("sendTuples starting");
            while (true)
            {
                if (_operator.outputTuples.Count != 0)
                {
                    string[] outputTuple;
                    lock (_operator.outputTuples)
                    {
                        outputTuple = (string[])_operator.outputTuples[0].Clone();
                    }

                    lock (_operator.sendAddresses)
                    {
                        switch (_operator.routing)
                        {
                        case "primary":
                            //Console.WriteLine("\n\r send adress -> " + _operator.sendAddresses.Count);
                            if (_operator.sendAddresses.Count != 0)
                            {
                                foreach (string replicaID in _operator.sendAddresses.Keys)
                                {
                                    if (replicaID.Contains("0"))
                                    {
                                        string sendAddress = _operator.sendAddresses[replicaID];
                                        //Console.WriteLine("SEND adress -> " + sendAddress + " tuple -> " + outputTuple[0]);
                                        operatorServices = (OperatorServices)Activator.GetObject(
                                            typeof(OperatorServices),
                                            sendAddress);
                                        operatorServices.exchangeTuples(outputTuple);
                                        lock (_operator.outputTuples)
                                        {
                                            _operator.outputTuples.RemoveAt(0);
                                        }
                                    }
                                }
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
 private static void sendAddressesToPreviousOP()
 {
     try
     {
         foreach (string address in _operator.previousAddresses)
         {
             operatorServices = (OperatorServices)Activator.GetObject(
                 typeof(OperatorServices),
                 address);
             string replica = _operator.id + "-" + _operator.repID;
             operatorServices.setSendAddresses(replica, _operator.myAddress);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Exception e = " + e.Message);
     }
 }
Ejemplo n.º 8
0
        public void sendTuples()
        {
            Console.WriteLine("sendTuples starting");
            while (true)
            {
                if (_operator.freeze)
                {
                    _operator.eventSendTuples.WaitOne();
                }
                if (_operator.outputTuples.Count != 0)
                {
                    Tup outputTuple;
                    lock (_operator.outputTuples)
                    {
                        outputTuple = (Tup)_operator.outputTuples[0].Clone();

                        /*foreach (Tup tup in _operator.outputTuples)
                         * {
                         *  Console.WriteLine("tup = " + tup.id);
                         * }*/
                    }

                    lock (_operator.sendAddresses)
                    {
                        string routing            = _operator.routing;
                        int    fieldNumberHashing = -1;
                        if (routing.Contains('('))
                        {
                            routing            = "hashing";
                            fieldNumberHashing = Int32.Parse(_operator.routing.Split('(')[1].Split(')')[0]);
                        }
                        bool receivedAnswer = true;
                        if (_operator.sendAddresses.Count != 0)
                        {
                            List <string> savedReplicaIDs = new List <string>();
                            bool          validID         = false;
                            Console.WriteLine("output tuple ID = " + outputTuple.id);
                            Console.WriteLine("processing number = " + _operator.processingNumber);
                            //Thread.Sleep(10000);
                            _operator.atualizaProcessingNumber();
                            if (outputTuple.id == _operator.processingNumber + 1)
                            {
                                Console.WriteLine("OLAAA");
                                validID        = true;
                                outputTuple.id = _operator.sequenceNumber + 1;
                                foreach (string operatorID in aliveReplicas.Keys)
                                {
                                    int limit        = aliveReplicas[operatorID].Count;
                                    int replicaIndex = -1;
                                    switch (routing)
                                    {
                                    case "primary":
                                        replicaIndex = 0;     //Always the first available replica of each operator
                                        break;

                                    case "random":
                                        Random random = new Random();
                                        replicaIndex = random.Next(0, limit);
                                        break;

                                    case "hashing":
                                        replicaIndex = getHashValue(outputTuple, limit, fieldNumberHashing);
                                        break;
                                    }
                                    Console.WriteLine("BBBBB");
                                    int    id          = aliveReplicas[operatorID][replicaIndex];
                                    string replicaID   = operatorID + "-" + id;
                                    string sendAddress = _operator.sendAddresses[replicaID];
                                    try
                                    {
                                        operatorServices = (OperatorServices)Activator.GetObject(
                                            typeof(OperatorServices),
                                            sendAddress);
                                        Console.WriteLine("Sending to " + sendAddress + " the following tuple -> " + constructTuple(outputTuple));
                                        var task = Task.Run(() => operatorServices.exchangeTuples(outputTuple));
                                        if (task.Wait(TimeSpan.FromSeconds(TIMEOUT)))
                                        {
                                            contador++; // Just to make an aux print in the Console
                                            Console.WriteLine("Received Answer " + contador);
                                            addSequenceNumberToAllReplicas();
                                            addProcessingNumberToAllReplicas();
                                        }
                                        else
                                        {
                                            Console.WriteLine("Did not received answer");
                                            savedReplicaIDs.Add(replicaID);
                                            receivedAnswer = false;
                                            if (_operator.semantics.Equals("at-most-once"))
                                            {
                                                _operator.addSequenceNumberToAllReplicas();
                                                _operator.addProcessingNumberToAllReplicas();
                                            }
                                            throw new DadStormTimeOutException();
                                        }
                                        if (_operator.loggingLevel.Equals("full"))
                                        {
                                            new Thread(() => puppetMasterServices.addMessageToLog(constructMsgToLog(outputTuple))).Start();
                                        }
                                    }
                                    catch (System.Net.Sockets.SocketException e) //Operator crashou
                                    {
                                        Console.WriteLine("I think that Operator " + replicaID + " crashed. SocketException");
                                    }
                                    catch (DadStormTimeOutException e)
                                    {
                                        Console.WriteLine("I think that Operator " + replicaID + " crashed. TimeOutException");
                                    }

                                    catch (Exception e)
                                    {
                                        Console.WriteLine("EXCEPTION = " + e.InnerException.Message);
                                        Console.WriteLine("I think that Operator " + replicaID + " crashed. General Exception");
                                    }
                                }
                            }

                            foreach (string savedReplicaID in savedReplicaIDs)
                            {
                                string failedOperator  = savedReplicaID.Split('-')[0];
                                int    failedReplicaID = Int32.Parse(savedReplicaID.Split('-')[1]);
                                aliveReplicas[failedOperator].Remove(failedReplicaID);
                            }

                            if (_operator.semantics.Equals("at-most-once") && validID ||
                                _operator.semantics.Equals("at-least-once") && (receivedAnswer))
                            {
                                lock (_operator.outputTuples)
                                {
                                    _operator.outputTuples.RemoveAt(0);
                                }
                            }
                            receivedAnswer = false;
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static void startReadingConfigFile(string filepath, bool step)
        {
            PuppetMasterReadConfig readConfig = new PuppetMasterReadConfig();

            //TODO FileNotFound Exception

            if (fileLines == null)
            {
                fileLines = File.ReadAllLines(filepath);
            }

            int limit = 0;

            if (step)
            {
                limit = lastLine + 1;
                if (limit > fileLines.Length)
                {
                    limit = fileLines.Length;
                }
            }
            else
            {
                limit = fileLines.Length;
            }

            for (int i = lastLine; i < limit; i++)
            {
                lastLine++;
                string[] line = fileLines[i].Split();
                if (!String.IsNullOrEmpty(line[0]))
                {
                    int cont = i + 1;
                    Debug.WriteLine("line " + cont + "=" + line[0]);
                    Dictionary <string, string> lineContentDictionary = readConfig.readLine(line);
                    string lineID = lineContentDictionary["LINE_ID"];
                    Debug.WriteLine("lineID = " + lineID);

                    if (lineID.Equals("OP"))
                    {
                        int    replicaCount = 0;
                        string operatorID   = lineContentDictionary["OPERATOR_ID"];
                        foreach (string address in lineContentDictionary["ADDRESSES"].Split('$'))
                        {
                            string replicaID = operatorID + "-" + replicaCount;
                            operatorsAddresses.Add(replicaID, address);
                            replicaCount++;
                        }

                        foreach (string key in lineContentDictionary.Keys)
                        {
                            string value = lineContentDictionary[key];
                            PuppetMaster.formPuppetMaster.addNewLineToLog(key + " = " + value);
                        }
                        PuppetMaster.formPuppetMaster.addNewLineToLog("\r\n");
                        services.sendOperatorInfoToPCS(lineContentDictionary);
                    }

                    else if (lineID.Equals("START"))
                    {
                        string operatorID = lineContentDictionary["OPERATOR_ID"];
                        PuppetMaster.formPuppetMaster.addNewLineToLog("PCS is about to start: " + operatorID);

                        foreach (string replicaID in operatorsAddresses.Keys)
                        {
                            if (replicaID.Contains(operatorID))
                            {
                                Debug.WriteLine("REPLICA ADDRESS = " + operatorsAddresses[replicaID]);
                                PuppetMaster.formPuppetMaster.addNewLineToLog("REPLICA ADDRESS = " + operatorsAddresses[replicaID]);
                                opServices = (OperatorServices)Activator.GetObject(
                                    typeof(OperatorServices),
                                    operatorsAddresses[replicaID]);

                                opServices.startToProcess();
                            }
                        }
                    }

                    else if (line.Equals("INTERVAL"))
                    {
                        //TODO
                    }

                    else if (line.Equals("STATUS"))
                    {
                        //TODO
                    }

                    else if (line.Equals("CRASH"))
                    {
                        //TODO
                    }

                    else if (line.Equals("FREEZE"))
                    {
                        //TODO
                    }

                    else if (line.Equals("UNFREEZE"))
                    {
                        //TODO
                    }

                    else if (line.Equals("WAIT"))
                    {
                        //TODO
                    }
                }
            }
        }