Exemplo n.º 1
0
        public void addServerToView(String serverid, String serverurl)
        {
            //prevent deadlock
            if (!server.getView().ContainsKey(serverid))
            {
                lock (server)
                {
                    Console.WriteLine("-------- BEGIN VIEW UPDATE --------");
                    server.updateView("add", serverid, serverurl);
                    Console.WriteLine("Server added: " + serverid + " @ " + serverurl);
                    String backupInfo = server.getBackupServer()[0];
                    for (int i = 1; i < server.getBackupServer().Length; i++)
                    {
                        backupInfo += ", " + server.getBackupServer()[i];
                    }
                    Console.WriteLine("New Backup-URL: " + backupInfo);
                    if (!server.getBackupServer().Equals(server.getURL()))
                    {
                        ServerCli bscli = (ServerCli)Activator.GetObject(typeof(ServerCli), server.getBackupServer()[0]);
                        bscli.addServerToView(serverid, serverurl);
                    }
                    //send command to update backup server to clients
                    foreach (IClient client in clientsList)
                    {
                        client.setBackupServerURL(server.getBackupServer());
                    }
                    //recreate BackupProposals
                    recreateBackupProposals();

                    Console.WriteLine("Backup server in " + clientsList.Count + " client(s) updated.");
                    Console.WriteLine("--------- END VIEW UPDATE ---------");
                }
            }
        }
Exemplo n.º 2
0
 public void updateBackupProposals()
 {
     foreach (String url in server.getView().Values)
     {
         try
         {
             ServerCli bscli = (ServerCli)Activator.GetObject(typeof(ServerCli), url);
             bscli.fillMPBackup();
         }
         catch (Exception e)
         {
             Console.WriteLine("Excpetion updateBackupProposals: " + e.Message + " on url: " + url);
         }
     }
 }
Exemplo n.º 3
0
        public Message GetMeetingProposalURL(string mpTopic)
        {
            //look if the server that has the mp is this one
            foreach (MeetingProposal serMP in meetingProposals)
            {
                if (serMP.getMPTopic().Equals(mpTopic))
                {
                    return(new Message(true, server.getURL(), ""));
                }
            }

            //look for the proposal on another servers
            string[] backupList = server.getBackupServer();
            string   result     = null;

            foreach (string serv in backupList)
            {
                ServerCli bscli = null;
                List <MeetingProposal> bserMPList = null;
                if (!serv.Equals(server.getURL()))
                {
                    try
                    {
                        bscli      = (ServerCli)Activator.GetObject(typeof(ServerCli), serv);
                        bserMPList = bscli.getServerMeetingProposals();
                        foreach (MeetingProposal m in bserMPList)
                        {
                            if (m.getMPTopic().Equals(mpTopic))
                            {
                                result = serv;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
            if (result == null)
            {
                return(new Message(false, null, "Meeting proposal not found!"));
            }
            else
            {
                return(new Message(true, result, ""));
            }
        }
Exemplo n.º 4
0
 public void recreateBackupProposals()
 {
     Console.WriteLine("Recreation of proposal backups started");
     foreach (String url in server.getView().Values)
     {
         try
         {
             ServerCli bscli = (ServerCli)Activator.GetObject(typeof(ServerCli), url);
             bscli.createNewMPBackup();
         }
         catch (Exception e)
         {
             Console.WriteLine("Excpetion recreateBackupProposals: " + e);
         }
     }
     updateBackupProposals();
     Console.WriteLine("Recreation of proposal backups finished");
 }
Exemplo n.º 5
0
        //should be called on client-side each time an user is updated
        private IClient findClient(String username)
        {
            IClient result = null;

            //look for the client on the server
            foreach (IClient ic in clientsList)
            {
                if (ic.getUser().getName().Equals(username))
                {
                    result = ic;
                }
            }

            //look for the client on the other servers
            if (result == null)
            {
                string[] backupList = server.getBackupServer();
                foreach (string servURL in backupList)
                {
                    ServerCli      bscli   = null;
                    List <IClient> cliList = null;
                    if (!servURL.Equals(server.getURL()))
                    {
                        try
                        {
                            bscli   = (ServerCli)Activator.GetObject(typeof(ServerCli), servURL);
                            cliList = bscli.getClientsList();
                        }
                        catch (Exception e)
                        {
                        }
                        foreach (IClient c in cliList)
                        {
                            if (c.getUser().getName().Equals(username))
                            {
                                result = c;
                            }
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        public void bookRoom(MeetingRoom mr, string time)
        {
            lock (meetingLocations)
            {
                foreach (MeetingLocation ml in meetingLocations)
                {
                    foreach (MeetingRoom room in ml.GetMeetingRooms())
                    {
                        if (room.GetName() == mr.GetName())
                        {
                            if (room.isBooked(time))
                            {
                                return;
                            }
                            else
                            {
                                room.book(time);
                            }
                        }
                    }
                }
            }
            if (!server.getBackupServer().Equals(server.getURL()))
            {
                ServerCli bscli = null;
                try
                {
                    bscli = (ServerCli)Activator.GetObject(typeof(ServerCli), server.getBackupServer()[0]);
                    bscli.bookRoom(mr, time);
                }
                catch (Exception e)
                {
                    Task <Message> task = Task <Message> .Factory.StartNew(() => Response("RemoveServerFromView", new List <String>()
                    {
                        bscli.getsURL()
                    }));

                    task.Wait();
                }
            }
        }
Exemplo n.º 7
0
        //Get client urls from the server plus one alive from backup
        public Message getSharedClientsList()
        {
            List <string> list    = null;
            List <string> auxList = null;
            ServerCli     bscli   = null;

            //get servers clients list
            list = getClientsURLList();
            string[] backupList = server.getBackupServer();
            //find a active backup server with active clients
            for (int i = 0; i < backupList.Length; i++)
            {
                if (!server.getBackupServer()[0].Equals(server.getURL()))
                {
                    try
                    {
                        bscli = (ServerCli)Activator.GetObject(typeof(ServerCli), backupList[i]);
                    }
                    catch (Exception e)
                    {
                        if (i + 1 < backupList.Length)
                        {
                            bscli = (ServerCli)Activator.GetObject(typeof(ServerCli), backupList[i + 1]);
                        }
                    }
                    if (bscli != null)
                    {
                        //get the clients list from the found backup server
                        auxList = bscli.getClientsURLList();
                        if (auxList.Count() != 0)
                        {
                            list.Add(auxList[0]);
                        }
                    }
                }
            }


            return(new Message(true, list, ""));
        }
Exemplo n.º 8
0
        public Message closeRequest(string topic, string username)
        {
            string    primary = server.getView().Values[0];
            ServerCli serv    = (ServerCli)Activator.GetObject(typeof(ServerCli), primary);

            Message mess;// = serv.sequence(server.getURL(), topic, username);

            if (!primary.Equals(server.getURL()))
            {
                Task <Message> task = Task <Message> .Factory.StartNew(() => serv.sequence(server.getURL(), topic, username));

                bool done = task.Wait(timeout);

                if (done)
                {
                    mess = task.Result;
                }
                else
                {
                    mess = new Message(false, null, "Close not successfull");
                }
            }
            else
            {
                Task <Message> task = Task <Message> .Factory.StartNew(() => sequence(server.getURL(), topic, username));

                bool done = task.Wait(timeout);

                if (done)
                {
                    mess = task.Result;
                }
                else
                {
                    mess = new Message(false, null, "Close not successfull");
                }
            }

            return(mess);
        }
Exemplo n.º 9
0
 public void fillMPBackup()
 {
     Console.WriteLine("Update of proposal backups started");
     for (int i = 0; i < server.getBackupServer().Length; i++)
     {
         try
         {
             ServerCli bscli = (ServerCli)Activator.GetObject(typeof(ServerCli), server.getBackupServer()[i]);
             bscli.setMPBackup(i, meetingProposals);
         }
         catch (Exception e)
         {
             removeServerFromView(new List <String>()
             {
                 server.getBackupServer()[i]
             });
             recreateBackupProposals();
             fillMPBackup();
         }
     }
     Console.WriteLine("Update of proposal backups finished");
 }
Exemplo n.º 10
0
        public static void Main(string[] args)
        {
            string[] vs = args[0].Split(
                new[] { "'" },
                StringSplitOptions.None);

            String id        = vs[0];
            String URL       = vs[1];
            int    maxFaults = Int32.Parse(vs[2]);
            int    minDelay  = Int32.Parse(vs[3]);
            int    maxDelay  = Int32.Parse(vs[4]);

            Uri myUri = new Uri(URL);

            TcpChannel channel = new TcpChannel(myUri.Port);

            ChannelServices.RegisterChannel(channel, false);

            SchedulingServer server = new SchedulingServer(id, URL, maxFaults, minDelay, maxDelay);
            ServerCli        mo     = new ServerCli(server);

            //RemotingServices.Marshal(mo, "mcm", typeof(ServerCli));

            RemotingServices.Marshal(mo, myUri.Segments[1], typeof(ServerCli));

            HttpChannel channel1 = new HttpChannel(myUri.Port + 200);

            ChannelServices.RegisterChannel(channel1, false);

            PuppetServer ps = new PuppetServer(mo);                   //testing this

            RemotingServices.Marshal(ps, "ps", typeof(PuppetServer)); // testing this

            Console.WriteLine("Server " + id + " started on Port " + myUri.Port);
            System.Console.ReadLine();
        }
Exemplo n.º 11
0
 public PuppetServer(ServerCli sc)
 {
     this.sc = sc;
 }
Exemplo n.º 12
0
        public Message removeServerFromView(List <String> serverurls)
        {
            foreach (String serverurl in serverurls)
            {
                if (server.getView().IndexOfValue(serverurl) != -1)
                {
                    String serverid = server.getView().Keys[server.getView().IndexOfValue(serverurl)];

                    //prevent deadlock
                    if (server.getView().ContainsKey(serverid))
                    {
                        lock (server)
                        {
                            Console.WriteLine("-------- BEGIN VIEW UPDATE --------");
                            server.updateView("remove", serverid, serverurl);
                            Console.WriteLine("Server removed: " + serverid + " @ " + serverurl);
                            String backupInfo = server.getBackupServer()[0];
                            for (int i = 1; i < server.getBackupServer().Length; i++)
                            {
                                backupInfo += ", " + server.getBackupServer()[i];
                            }
                            Console.WriteLine("New Backup-URL: " + backupInfo);

                            if (!server.getBackupServer()[0].Equals(server.getURL()))
                            {
                                tryConnectToBackup(0, serverurls);

                                void tryConnectToBackup(int indexBackupUpdate, List <String> args)
                                {
                                    try
                                    {
                                        ServerCli bscli = (ServerCli)Activator.GetObject(typeof(ServerCli), server.getBackupServer()[indexBackupUpdate]);
                                        bscli.removeServerFromView(args);
                                    }
                                    catch (Exception e)
                                    {
                                        if (indexBackupUpdate + 1 < server.getBackupServer().Length)
                                        {
                                            args.Add(server.getBackupServer()[indexBackupUpdate]);
                                            tryConnectToBackup(indexBackupUpdate + 1, args);
                                        }
                                        else
                                        {
                                            Console.WriteLine("Error: No Backup-server reachable!");
                                        }
                                    }
                                }
                            }
                            //send command to update backup server to clients
                            foreach (IClient client in clientsList)
                            {
                                client.setBackupServerURL(server.getBackupServer());
                            }
                            Console.WriteLine("Backup server in " + clientsList.Count + " client(s) updated.");
                            Console.WriteLine("--------- END VIEW UPDATE ---------");
                        }
                    }
                }
            }
            for (int i = 0; i < serverurls.Count; i++)
            {
                meetingProposals.AddRange(meetingProposalsBackup[i]);
            }
            return(new Message(true, null, ""));
        }
Exemplo n.º 13
0
        public Message sequence(string url, string topic, string username)
        {
            Message mess = null;

            if (!closes.ContainsValue(url + " " + topic + " " + username))
            {
                seq++;
                closes.Add(seq, url + " " + topic + " " + username);

                Monitor.Enter(server); //lock
                try
                {
                    closes.TryGetValue(request, out string str);
                    string[] data = str.Split(' ');


                    if (!data[0].Equals(server.getURL()))
                    {
                        ServerCli      serv = (ServerCli)Activator.GetObject(typeof(ServerCli), data[0]);
                        Task <Message> task = Task <Message> .Factory.StartNew(() => serv.CloseMeetingProposal(data[1], data[2]));

                        bool done = task.Wait(timeout);

                        if (done)
                        {
                            mess = task.Result;
                        }
                        else
                        {
                            mess = new Message(false, null, "Server to close timed out abort operation");
                        }
                    }
                    else
                    {
                        Task <Message> task = Task <Message> .Factory.StartNew(() => CloseMeetingProposal(data[1], data[2]));

                        bool done = task.Wait(timeout);

                        if (done)
                        {
                            mess = task.Result;
                        }
                        else
                        {
                            mess = new Message(false, null, "Server to close timed out abort operation");
                        }
                    }

                    request++;
                }
                finally
                {
                    Monitor.Pulse(server);
                    Monitor.Exit(server);
                }
            }
            else
            {
                mess = new Message(false, null, "Duplicated request");
            }

            return(mess);
        }