private Replica CreateReplica(int failedId)
        {
            ReplicaCreationInfo rci = new ReplicaCreationInfo();

            //adress of crashed replica
            rci.Address  = info.Addresses[failedId];
            rci.Id       = failedId;
            rci.Operator = info;
            return(new Replica(rci));
        }
        public string Serialize(OperatorInfo info, string address, int id)
        {
            var rep = new ReplicaCreationInfo
            {
                Operator = info,
                Address  = address,
                Id       = id
            };
            //TextWriter tw = new StringWriter();
            MemoryStream stream1 = new MemoryStream();

            System.Runtime.Serialization.DataContractSerializer serializer = new System.Runtime.Serialization.DataContractSerializer(rep.GetType());
            serializer.WriteObject(stream1, rep);
            var s = Encoding.ASCII.GetString(stream1.ToArray());

            return(s.ToString());
        }
Example #3
0
        static void Main(string[] args)
        {
            //var c = new List<string> { "a", "b" };
            //var op = Operations.GetOperation("COUNT");
            //op.Process(c);
            //op.Process(c);
            //var a = Operations.GetCustomOperation(@"SharedTypes.dll", "SharedTypes.CustomFunctions", "reverse");
            // var b = Operations.GetCustomOperation(@"C:\Users\Goncalo\Source\Repos\DAD2016\Operator\Operator\bin\Debug\SharedTypes.dll", "SharedTypes.CustomFunctions", "dup");
            //var c = a(new List<string> { "a", "b" });
            // var d = b(new List<string> { "a", "b" });
            if (args.Length < 1)
            {
                Console.WriteLine("Missing creation info argument.");
                loop();
            }



            TextReader tr = new StringReader(args[0]);

            ReplicaCreationInfo rep = null;

            try
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(ReplicaCreationInfo));
                rep = (ReplicaCreationInfo)serializer.ReadObject(XmlReader.Create(tr));
            }
            catch (Exception e)
            {
                Console.WriteLine($"Creation info XML has a wrong format. Exception: {e.Message}");
                throw;
            } finally
            {
                tr.Close();
            }

            if (rep == null)
            {
                loop();
            }
            var info = rep.Operator;

            Console.WriteLine($"Successfully initiated replica {info.Addresses.IndexOf(rep.Address)} of {info.ID}.");
            string address = rep.Address;


            Replica        replica    = new Replica(rep);
            ReplicaManager repManager = new ReplicaManager(replica, info);

            Regex portRegex = new Regex(@"tcp://(\w|\.)+:(?<port>(\d+))(/(?<name>\w*))?", RegexOptions.IgnoreCase);
            var   match     = portRegex.Match(address);

            if (!match.Groups["port"].Success || !match.Groups["name"].Success)
            {
                Console.WriteLine($"URL ({address}) malformed. Unable to create process.");
                return;
            }
            var port = Int32.Parse(match.Groups["port"].Value);
            var name = match.Groups["name"].Value;

            try
            {
                TcpChannel channel = new TcpChannel(port);
                ChannelServices.RegisterChannel(channel, false);
            } catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            RemotingServices.Marshal(repManager, name, typeof(ReplicaManager));
            Console.WriteLine($"Listening at {address}. Press Enter to exit.");
            Console.ReadLine();
        }
Example #4
0
        public Replica(ReplicaCreationInfo rep)
        {
            // Console.WriteLine("\a");
            var info = rep.Operator;

            this.OperatorId      = info.ID;
            this.MasterURL       = info.MasterURL;
            this.ProcessFunction = Operations.GetOperation(info.OperatorFunction, info.OperatorFunctionArgs);


            this.shouldNotify = info.ShouldNotify;
            this.inputFiles   = info.InputFiles;
            // primary is the first one in the array
            this.SelfURL      = rep.Address;
            this.MasterURL    = info.MasterURL;
            this.ID           = rep.Id;
            this.destinations = new Dictionary <string, Destination>();

            if (info.OutputOperators == null || info.OutputOperators.Count == 0)
            {
                // it is an output operator
                //this.destinations.Add("output_file", new OutputFile(this, info.Semantic));
            }
            else
            {
                foreach (var dstInfo in info.OutputOperators)
                {
                    destinations.Add(dstInfo.ID, new NeighbourOperator(this, dstInfo, info.Semantic));
                }
            }

            var allOrigins = new List <OriginOperator>();

            this.originOperators = new Dictionary <string, List <OriginOperator> >();
            foreach (var op in info.InputReplicas.Keys)
            {
                this.originOperators[op] = new List <OriginOperator>();
                for (int i = 0; i < info.InputReplicas[op].Count; i++)
                {
                    this.originOperators[op].Add(new OriginOperator(op, i));
                    allOrigins.Add(originOperators[op][i]);
                }
            }
            if (inputFiles != null && inputFiles.Count > 0)
            {
                this.originOperators[this.OperatorId] = new List <OriginOperator>();
                this.originOperators[this.OperatorId].Add(new OriginOperator(this.OperatorId, 0));
                allOrigins.Add(originOperators[this.OperatorId][0]);
            }
            this.inBuffer = new MergedInBuffer(allOrigins);



            if (info.RtStrategy == SharedTypes.RoutingStrategy.Primary)
            {
                this.routingStrategy = new PrimaryStrategy(info.Addresses.Count);
            }
            else if (info.RtStrategy == SharedTypes.RoutingStrategy.Hashing)
            {
                this.routingStrategy = new HashingStrategy(info.Addresses.Count, info.HashingArg);
            }
            else
            {
                this.routingStrategy = new RandomStrategy(info.Addresses.Count, OperatorId.GetHashCode());
            }

            // Start reading from file(s)

            Task.Run(() => mainLoop());

            if (shouldNotify)
            {
                //destinations.Add(new LoggerDestination(this, info.Semantic, $"{OperatorId}({ID})", MasterURL));
                destinations.Add("puppet_master_logger", new LoggerDestination(this, info.Semantic, SelfURL, MasterURL));
            }

            // Configure windows position

            string a = this.OperatorId;

            if (a.Equals("OP1"))
            {
                SetWindowPosition(600, 0, 400, 200);
            }
            if (a.Equals("OP2"))
            {
                SetWindowPosition(950, 0, 400, 200);
            }
            if (a.Equals("OP3"))
            {
                SetWindowPosition(600, 200, 400, 200);
            }
            if (a.Equals("OP4"))
            {
                SetWindowPosition(950, 200, 400, 200);
            }
            if (a.Equals("OP5"))
            {
                SetWindowPosition(600, 400, 400, 200);
            }
            if (a.Equals("OP6"))
            {
                SetWindowPosition(950, 400, 400, 200);
            }
            if (a.Equals("OP7"))
            {
                SetWindowPosition(600, 600, 400, 200);
            }
            if (a.Equals("OP8"))
            {
                SetWindowPosition(950, 600, 400, 200);
            }
            if (a.Equals("OP9"))
            {
                SetWindowPosition(600, 800, 400, 200);
            }
        }