/// <summary> /// Periodically uploads SLAs and SessionStates. /// SLAs and SessionStates are stored in two Azure tables called. /// </summary> public void StartUploadConfigurationTask(string containerName, List <ConsistencySLAEngine> engines, SessionState sessionState, ServerMonitor monitor) { activeUploaders[containerName] = true; int sleepDuration = 0; int epoch; DateTimeOffset lastModified; ReplicaConfiguration configuration = ClientRegistry.GetConfiguration(containerName, false); if (configuration == null) { activeUploaders[containerName] = false; } while (activeUploaders[containerName]) { try { configuration.SyncWithCloud(ClientRegistry.GetConfigurationAccount()); while (!configuration.IsInFastMode()) { lock (configuration) Monitor.Wait(configuration, 1000); } epoch = configuration.Epoch; Console.WriteLine("Uploading SLA and SessionState with Epoch: " + epoch); lastModified = configuration.EpochModifiedTime; // |====a====|-conf in progress-|====b====| //Clients upload their configurations between the middle of a configuration period, and before a configuration epoch is finished. //I.e., after for example a, and before the first next bar, or after b, and before the next upcomming bar. if (DateTimeOffset.Now.Subtract(lastModified).TotalMilliseconds > ConstPool.CONFIGURATION_UPLOAD_INTERVAL / 2) { UploadClientData(containerName, epoch, engines, sessionState, monitor); //Console.WriteLine("Uploaded the configuration to the azure storage. ..."); sleepDuration = ConstPool.CONFIGURATION_UPLOAD_INTERVAL; } else { //we try to push the upload to some time after the middle of an epoch duration. sleepDuration = (ConstPool.CONFIGURATION_UPLOAD_INTERVAL / 2) - DateTimeOffset.Now.Subtract(lastModified).Milliseconds; } Thread.Sleep(sleepDuration); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); throw ex; } } }
public Replicator(string capCloudBlobContainerName) { configuration = ClientRegistry.GetConfiguration(capCloudBlobContainerName, true); name = configuration.Name; }