Example #1
0
File: RKM.cs Project: pepipe/ISEL
        public void addServerToRKM(ServerInfo serverInfo)
        {
            String serviceAddress = serverInfo.Channel + "://" + serverInfo.ServerAddress + ":" + serverInfo.ServerPort + "/" + serverInfo.ServiceName;
            IServer svc = (IServer)Activator.GetObject(
                                        typeof(IServer),
                                        serviceAddress);
            Console.WriteLine("New server added to RKM: {0}", serviceAddress);

            //if we don't have servers in the ring we don't need to set the last server pointer to the new one
            if (m_ring.Count > 0)
            {
                ServerInfo lastServerInfo;
                IServer lastServerProxy;

                bool notException = false;
                do
                {
                    try
                    {
                        lastServerInfo = m_ring.Last<ServerInfo>();
                        serviceAddress = lastServerInfo.Channel + "://" + lastServerInfo.ServerAddress + ":" + lastServerInfo.ServerPort + "/" + lastServerInfo.ServiceName;
                        lastServerProxy = (IServer)Activator.GetObject(typeof(IServer), serviceAddress);
                        lastServerProxy.setNextRingServer(serverInfo);
                        notException = false;
                    }catch(Exception)
                    {
                        lock (lockThis)
                        {
                            m_ring.Remove(m_ring.Last<ServerInfo>());
                        }
                        notException = true;
                    }
                } while (notException && m_ring.Count > 0);
            }

            lock (lockThis)
            {
                m_ring.Add(serverInfo);
            }
            //the new server in the ring will have it's next server pointed to the first in the rings list of servers
            svc.setNextRingServer(m_ring.First<ServerInfo>());

            printRingConfiguration();
        }
Example #2
0
 public void setNextRingServer(ServerInfo nextServer)
 {
     m_nextServer = nextServer;
     Console.WriteLine("Next ring server: {0}:{1}", nextServer.ServerAddress, nextServer.ServerPort);
 }
Example #3
0
File: RKM.cs Project: pepipe/ISEL
 public void removeServerFromRKM(ServerInfo oldServer)
 {
     lock (lockThis)
     {
         m_ring.Remove(oldServer);
         reconstructRing();
     }
 }
Example #4
0
File: RKM.cs Project: pepipe/ISEL
        public void disconnectFromServer(ServerInfo server)
        {
            try
            {
                lock (lockThis)
                {
                    m_ring[m_ring.IndexOf(server)].ClientCount--;
                }

            }catch
            {
                removeServerFromRKM(server);
            }
        }
Example #5
0
File: RKM.cs Project: pepipe/ISEL
        public ServerInfo connectToServer(ServerInfo oldServer = null)
        {
            //if oldServer is different of null means that that server is down.
            if(oldServer != null)
            {
                removeServerFromRKM(oldServer);
                printRingConfiguration();
            }

            if (m_ring.Count <= 0)
                return null;

            //connect to the server with less clients
            int serverPos = getServerWithLessClients();
            lock (lockThis)
            {
                m_ring[serverPos].ClientCount++;
                return m_ring[serverPos];
            }
        }
Example #6
0
        public bool Equals(ServerInfo si)
        {
            // If parameter is null return false:
            if ((object)si == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (ServerAddress == si.ServerAddress && ServerPort == si.ServerPort);
        }