} // no thread protected public Application(Config config = null) { Config = config; if (null == Config) { Config = Config.Load(); } InternalThreadPool = new Util.SimpleThreadPool( Config.InternalThreadPoolWorkerCount, "ZezeSpecialThreadPool"); int workerThreads, completionPortThreads; ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads); if (Config.WorkerThreads > 0) { workerThreads = Config.WorkerThreads; } if (Config.CompletionPortThreads > 0) { completionPortThreads = Config.CompletionPortThreads; } ThreadPool.SetMinThreads(workerThreads, completionPortThreads); Config.CreateDatabase(Databases); GlobalAgent = new GlobalAgent(this); _checkpoint = new Checkpoint(Databases.Values); }
public void Stop() { lock (this) { if (false == IsStart) { return; } ClearInUseAndIAmSureAppStopped(); IsStart = false; Checkpoint?.StopAndJoin(); GlobalAgent?.Stop(); foreach (var db in Databases.Values) { db.Close(); } TableSys = null; Databases.Clear(); } }
public void Start() { lock (this) { //ClearInUseAndIAmSureAppStopped(); foreach (var db in Databases.Values) { db.DirectOperates.SetInUse(Config.AutoKeyLocalId, Config.GlobalCacheManagerHostNameOrAddress); } if (IsStart) { return; } IsStart = true; // 由于 AutoKey,TableSys需要先打开。TableSys肯定在defaultDb中。并且要在其他database都初始化table后再加入。 TableSys = new TableSys(); Database defaultDb = GetDatabase(""); defaultDb.storages.Add(TableSys.Open(this, defaultDb)); foreach (var db in Databases.Values) { db.Open(this); } defaultDb.AddTable(TableSys); if (Config.GlobalCacheManagerHostNameOrAddress.Length > 0) { GlobalAgent.Start(Config.GlobalCacheManagerHostNameOrAddress, Config.GlobalCacheManagerPort); } Checkpoint.Start(Config.CheckpointPeriod); ///////////////////////////////////////////////////// /// Schemas Check Schemas.Compile(); var keyOfSchemas = Zeze.Serialize.ByteBuffer.Allocate(); keyOfSchemas.WriteString("zeze.Schemas." + Config.AutoKeyLocalId); while (true) { var(data, version) = defaultDb.DirectOperates.GetDataWithVersion(keyOfSchemas); if (null != data) { var SchemasPrevious = new Schemas(); try { SchemasPrevious.Decode(data); SchemasPrevious.Compile(); } catch (Exception ex) { SchemasPrevious = null; logger.Error(ex, "Schemas Implement Changed?"); } if (false == Schemas.IsCompatible(SchemasPrevious, Config)) { throw new Exception("Database Struct Not Compatible!"); } } var newdata = Serialize.ByteBuffer.Allocate(); Schemas.Encode(newdata); if (defaultDb.DirectOperates.SaveDataWithSameVersion(keyOfSchemas, newdata, ref version)) { break; } } } }