Beispiel #1
0
        public Server()
        {
            var key = System.Configuration.ConfigurationManager.AppSettings[ConfigurationFactory.SERVER_RING_INDEX_KEY];

            ringIndex     = Int32.Parse(key);
            discoverToken = new PropagateToken(PropagateAction.AddServer, this);
            myServer      = new CachedServer(this);
        }
Beispiel #2
0
        public void AddZoneServer(IServerExtended server, PropagateToken token)
        {
            logger.Info("Adding zone server with index {0}", server.RingIndex);
            lock (knownServers)
            {
                checkRingData(server);
                if (!knownServers.ContainsKey(server.GetUID()))
                {
                    CachedServer cached = new CachedServer(server);
                    knownServers.Add(cached.UID, cached);
                }

                nextRingServer = getNextServerOnRing();
            }
            SendServerAction(token);
        }
Beispiel #3
0
        public void RemoveZoneServer(string serverUid, PropagateToken token)
        {
            CachedServer cachedServer;

            if (!knownServers.TryGetValue(serverUid, out cachedServer))
            {
                logger.Info("Cannot remove unknown server with uid {0}", serverUid);
                return;
            }

            logger.Info("Removing zone server with index {0}", cachedServer.RingIndex);
            lock (knownServers)
            {
                knownServers.Remove(cachedServer.UID);

                if (cachedServer.UID == nextRingServer.UID)
                {
                    nextRingServer = getNextServerOnRing();
                }
            }

            SendServerAction(token);
        }
Beispiel #4
0
        /**
         *  <summary>
         *      Discovery process is done by acquiring a list of possible ring servers from a config file.
         *      Then it asks a complete server list for the ring one server on the config file.
         *      A server is only considered to be in the ring if, when sending the the AddZoneServer token, it arrives with the same list of objects retreived from the server
         *      The first server shall not have any servers on the configuration file, so it assumes the ring is empty
         *  </summary>
         **/

        private void registerAndDiscoverRingServers()
        {
            logger.Info("Starting discovery process");
            var configInfo = getServersFromFile();

            if (configInfo.Count() == 0)
            {
                logger.Info("No servers on config file. Assuming empty ring");
                nextRingServer = myServer;
                return; //Considered first ring server
            }


            var ringServerProxies = getRingServers(configInfo);

            logger.Info("Got ring server list with {0} entries", ringServerProxies.Count());

            foreach (var proxy in ringServerProxies)
            {
                var server = new CachedServer(proxy);
                if (server.RingIndex == this.RingIndex)
                {
                    logger.Error("Server with ring index {0} already exist. Aborting.", server.RingIndex);
                    throw new DiscoveryException();
                }


                knownServers.Add(proxy.GetUID(), server);
            }


            nextRingServer = getNextServerOnRing();

            logger.Info("Trying to register server on ring");
            SendServerAction(discoverToken);
        }