Example #1
0
        /// <summary>
        /// Create a configuration of a CapCloudBlobContainer and save it in the Azure's configuration blob if there is not an instance there.
        /// </summary>
        /// <param name="capCloudBlobContainerName">The name of the CapCloudBlobContainer</param>
        /// <param name="primaryServer"></param>
        /// <param name="secondaryServer"></param>
        /// <param name="sessionState">session state of the SLAEngine. This state is used for registering, and unregistering newly added/removed replicas</param>
        /// <returns></returns>
        public static ContainerConfiguration CreateConfiguration(string capCloudBlobContainerName,
                                                                 string primaryServer, string secondaryServer, SessionState sessionState, bool autoRefresh = false)
        {
            ContainerConfiguration result = new ContainerConfiguration(capCloudBlobContainerName, primaryServer, secondaryServer, sessionState);

            // result.EndCurrentEpoch();  // is this needed?
            result.InitializeConfigurationBlob();
            result.StartNewEpoch(true);

            if (autoRefresh)
            {
                refreshConfigurationTask = Task.Factory.StartNew(() => result.RefreshConfigurationPeriodically());
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Read an already created configuration of a CapCloudBlobContainer from the Azure's configuration blob.
        /// </summary>
        /// <param name="capCloudBlobContainerName">Name of the CapCloudBlobContainer</param>
        /// <param name="sessionState">session state of the SLAEngine. This state is used for registering, and unregistering newly added/removed replicas</param>
        /// <param name="autoRefresh">if true, it will automatically refresh the configuration by reading it periodically from the cloud storage.</param>
        /// <returns></returns>
        public static ContainerConfiguration ReadConfiguration(string capCloudBlobContainerName, SessionState sessionState, bool autoRefresh)
        {
            ContainerConfiguration result = new ContainerConfiguration(capCloudBlobContainerName, sessionState);

            //reads new configuration
            result.ReadConfiguration();
            if (autoRefresh)
            {
                refreshConfigurationTask = Task.Factory.StartNew(() => result.RefreshConfigurationPeriodically());
            }

            if (result.PrimaryServers != null && result.PrimaryServers.Count > 0)
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }