Exemplo n.º 1
0
        public override bool Open(ClusterConfig config, bool nonblocking)
        {
            this.m_cluster_config = config;
            m_cancelSrc           = new CancellationTokenSource();
            m_nameservice         = AssemblyUtility.GetAllClassInstances <INameService>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using name service provided by '{m_nameservice.GetType().FullName}'");
            m_chunktable = AssemblyUtility.GetAllClassInstances <IChunkTable>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using chunk table provided by '{m_chunktable.GetType().FullName}'");
            m_taskqueue = AssemblyUtility.GetAllClassInstances <ITaskQueue>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using task queue provided by '{m_taskqueue.GetType().FullName}'");
            m_healthmanager = AssemblyUtility.GetAllClassInstances <IHealthManager>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using health manager provided by '{m_healthmanager.GetType().FullName}'");
            m_backupmgr = AssemblyUtility.GetAllClassInstances <IBackupManager>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using backup manager provided by '{m_backupmgr.GetType().FullName}'");
            m_persistent_storage = AssemblyUtility.GetAllClassInstances <IPersistentStorage>().First();
            Log.WriteLine(LogLevel.Info, $"{nameof(DynamicMemoryCloud)}: using persistent storage provided by '{m_persistent_storage.GetType().FullName}'");

            m_nameservice.Start(m_cancelSrc.Token);
            m_taskqueue.Start(m_cancelSrc.Token);
            m_chunktable.Start(m_cancelSrc.Token);
            m_healthmanager.Start(m_cancelSrc.Token);
            m_backupmgr.Start(m_cancelSrc.Token);

            m_myid                 = GetInstanceId(InstanceGuid);
            m_storageTable         = new DynamicStorageTable(PartitionCount);
            m_storageTable[m_myid] = Global.LocalStorage;
            NickName               = GenerateNickName(InstanceGuid);

            int redundancy = DynamicClusterConfig.Instance.MinimumReplica;

            m_cloudidx    = new CloudIndex(m_cancelSrc.Token, m_nameservice, m_chunktable, this, NickName, PartitionTable);
            m_healthmon   = new HealthMonitor(m_cancelSrc.Token, m_nameservice, m_cloudidx, m_healthmanager, redundancy);
            m_partitioner = new Partitioner(m_cancelSrc.Token, m_cloudidx, m_nameservice, m_taskqueue, DynamicClusterConfig.Instance.ReplicationMode, redundancy);
            m_taskexec    = new Executor(m_cancelSrc.Token, m_nameservice, m_taskqueue);
            m_backupctl   = new BackupController(m_cancelSrc.Token, m_backupmgr, m_nameservice, m_persistent_storage, m_taskqueue);

            Log.WriteLine($"{nameof(DynamicMemoryCloud)}: Partition {MyPartitionId}: Instance '{NickName}' {InstanceGuid} opened.");
            Global.CommunicationInstance.Started += InitModule;

            return(true);
        }