Esempio n. 1
0
 /// <summary>
 /// 文件流写入器
 /// </summary>
 /// <param name="cacheFile"></param>
 internal FileStreamWriter(FileStreamWriter cacheFile)
 {
     cache       = cacheFile.cache;
     Config      = cacheFile.Config;
     bufferPool  = SubBuffer.Pool.GetPool(Config.BufferSize);
     flushHandle = flush;
 }
Esempio n. 2
0
 /// <summary>
 /// 文件读取器
 /// </summary>
 /// <param name="file">文件流写入器</param>
 /// <param name="index">当前读取位置</param>
 /// <param name="onRead">读取文件回调委托</param>
 internal FileReader(FileStreamWriter file, long index, AutoCSer.Net.TcpServer.ServerCallback <ReadFileParameter> onRead)
 {
     this.file   = file;
     this.index  = index;
     this.onRead = onRead;
     buffer      = new byte[(int)file.Config.ReaderBufferSize];
     readHandle  = read;
 }
Esempio n. 3
0
 /// <summary>
 /// 文件读取器
 /// </summary>
 /// <param name="file">文件流写入器</param>
 /// <param name="index">当前读取位置</param>
 /// <param name="onRead">读取文件回调委托</param>
 internal FileReader(FileStreamWriter file, long index, Func <AutoCSer.Net.TcpServer.ReturnValue <ReadFileParameter>, bool> onRead)
 {
     this.file   = file;
     this.index  = index;
     this.onRead = onRead;
     buffer      = new byte[(int)file.Config.ReaderBufferSize];
     readHandle  = read;
 }
Esempio n. 4
0
        internal void ReadFile(ulong version, long index, Func <AutoCSer.Net.TcpServer.ReturnValue <ReadFileParameter>, bool> onRead)
        {
            FileStreamWriter file = Cache.File;

            if (file == null || !file.Read(version, index, onRead))
            {
                onRead(default(ReadFileParameter));
            }
        }
Esempio n. 5
0
        internal void ReadFile(ulong version, long index, AutoCSer.Net.TcpServer.ServerCallback <ReadFileParameter> onRead)
        {
            FileStreamWriter file = Cache.File;

            if (file == null || !file.Read(version, index, onRead))
            {
                onRead.Callback(default(ReadFileParameter));
            }
        }
Esempio n. 6
0
 /// <summary>
 /// 触发定时任务
 /// </summary>
 internal override void OnTimer()
 {
     for (FileStreamWriter writer = FileStreamWriter.Writers.End; writer != null; writer = writer.DoubleLinkPrevious)
     {
         writer.OnTimer();
     }
     Cache.MessageQueue.DistributionFileReader.OnTimer();
     //if (CacheTimeout.Timeouts.End != null)
     //{
     //    AutoCSer.Net.TcpServer.ServerCallQueue.Default.Add(new CacheManagerServerCall { Type = CacheManagerServerCallType.Timeout });
     //}
 }
Esempio n. 7
0
 /// <summary>
 /// 重建文件流
 /// </summary>
 /// <returns></returns>
 internal ReturnType NewFileStream()
 {
     if (isDisposed == 0)
     {
         if (File != null)
         {
             if (NewFile == null)
             {
                 NewFile = new FileStreamWriter(File);
                 return(currentGetter == null?NewFile.Start(File) : ReturnType.Success);
             }
             return(ReturnType.FileStreamExists);
         }
         return(ReturnType.NotFoundFileStream);
     }
     return(ReturnType.Disposed);
 }
Esempio n. 8
0
 private static void onTime(Date.NowTime.OnTimeFlag flag)
 {
     if ((flag & Date.NowTime.OnTimeFlag.CacheFile) != 0)
     {
         for (FileStreamWriter writer = FileStreamWriter.Writers.End; writer != null; writer = writer.DoubleLinkPrevious)
         {
             writer.OnTimer();
         }
     }
     if ((flag & Date.NowTime.OnTimeFlag.CacheDistributionTimeout) != 0)
     {
         Cache.MessageQueue.DistributionFileReader.OnTimer();
     }
     //if (CacheTimeout.Timeouts.End != null)
     //{
     //    AutoCSer.Net.TcpServer.ServerCallQueue.Default.Add(new CacheManagerServerCall { Type = CacheManagerServerCallType.Timeout });
     //}
 }
Esempio n. 9
0
        /// <summary>
        /// 释放资源
        /// </summary>
        internal void DisposeTcpQueue()
        {
            CanWrite = false;
            if (File != null)
            {
                File.Close();
                File = null;
            }
            CacheGetter getter = waitGetterLink;

            waitGetterLink = null;
            while (getter != null)
            {
                getter = getter.Cancel();
            }
            getter     = getterLink;
            getterLink = currentGetter = null;
            while (getter != null)
            {
                getter = getter.Cancel();
            }
        }
Esempio n. 10
0
 /// <summary>
 /// 重建文件流
 /// </summary>
 /// <param name="cacheFile"></param>
 /// <returns></returns>
 internal ReturnType Start(FileStreamWriter cacheFile)
 {
     IsDisposed = 1;
     SubBuffer.PoolBufferFull buffer = default(SubBuffer.PoolBufferFull);
     try
     {
         snapshot = new Snapshot.Cache(cache, true);
         FileInfo file = new FileInfo(cacheFile.isSwitchFile ? Config.GetFileName : Config.GetSwitchFileName);
         FileName = file.FullName;
         if (file.Exists)
         {
             AutoCSer.IO.File.MoveBak(FileName);
         }
         fileStream = new FileStream(FileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read, bufferPool.Size, FileOptions.None);
         create(ref buffer, 0);
         return(ReturnType.Success);
     }
     catch (Exception error)
     {
         cache.TcpServer.AddLog(error);
     }
     finally
     {
         buffer.Free();
         if (IsDisposed == 0)
         {
             AutoCSer.Threading.ThreadPool.TinyBackground.Start(writeCache);
         }
         else
         {
             cache.NextGetter();
             if (fileStream != null)
             {
                 fileStream.Dispose();
             }
         }
     }
     return(ReturnType.SnapshotFileStartError);
 }
Esempio n. 11
0
 /// <summary>
 /// 缓存管理
 /// </summary>
 /// <param name="config">缓存服务配置</param>
 /// <param name="tcpServer">缓存服务</param>
 internal CacheManager(MasterServerConfig config, AutoCSer.Net.TcpInternalServer.Server tcpServer)
 {
     Config     = config;
     TcpServer  = tcpServer;
     tcpQueue   = tcpServer.CallQueue;
     shortPaths = new ShortPathItem[config.GetShortPathCount];
     if (config.IsFile)
     {
         disposeHandle = Dispose;
         IsFile        = true;
         File          = new FileStreamWriter(this, config);
         foreach (Cache.MessageQueue.Node messageQueue in LoadMessageQueues)
         {
             messageQueue.Start();
         }
         LoadMessageQueues.SetNull();
         IsLoaded = CanWrite = true;
         AutoCSer.DomainUnload.Unloader.Add(disposeHandle, DomainUnload.Type.Action);
     }
     else
     {
         IsLoaded = CanWrite = true;
     }
 }
Esempio n. 12
0
        internal ulong GetFileVersion()
        {
            FileStreamWriter file = Cache.File;

            return(file != null ? file.Version : 0);
        }
Esempio n. 13
0
 internal void OnCreatedNewFileStream()
 {
     AutoCSer.Threading.ThreadPool.TinyBackground.Start(File.Close);
     File    = NewFile;
     NewFile = null;
 }
Esempio n. 14
0
 internal void CreateNewFileStreamError()
 {
     Buffer.DisposeLink(NewFile.BufferLink.GetClear());
     NewFile = null;
 }