Exemplo n.º 1
0
        public ChunkManager(string name, ChunkManagerConfig config, bool isMemoryMode, IEnumerable <string> relativePaths = null)
        {
            Ensure.NotNull(name, "name");
            Ensure.NotNull(config, "config");

            Name          = name;
            _config       = config;
            _isMemoryMode = isMemoryMode;
            if (relativePaths == null)
            {
                _chunkPath = _config.BasePath;
            }
            else
            {
                var chunkPath = _config.BasePath;
                foreach (var relativePath in relativePaths)
                {
                    chunkPath = Path.Combine(chunkPath, relativePath);
                }
                _chunkPath = chunkPath;
            }
            if (!Directory.Exists(_chunkPath))
            {
                Directory.CreateDirectory(_chunkPath);
            }
            _chunks            = new ConcurrentDictionary <int, Chunk>();
            _scheduleService   = null /* ObjectContainer.Resolve<IScheduleService>()*/;
            _bytesWriteDict    = new ConcurrentDictionary <int, BytesInfo>();
            _fileReadDict      = new ConcurrentDictionary <int, CountInfo>();
            _unmanagedReadDict = new ConcurrentDictionary <int, CountInfo>();
            _cachedReadDict    = new ConcurrentDictionary <int, CountInfo>();
        }
Exemplo n.º 2
0
        private Chunk(string filename, ChunkManager chunkManager, ChunkManagerConfig chunkConfig, bool isMemoryChunk)
        {
            Ensure.NotNullOrEmpty(filename, "filename");
            Ensure.NotNull(chunkManager, "chunkManager");
            Ensure.NotNull(chunkConfig, "chunkConfig");

            _filename       = filename;
            _chunkManager   = chunkManager;
            _chunkConfig    = chunkConfig;
            _isMemoryChunk  = isMemoryChunk;
            _lastActiveTime = DateTime.Now;
        }
Exemplo n.º 3
0
        public static Chunk FromOngoingFile <T>(string filename, ChunkManager chunkManager, ChunkManagerConfig config, Func <byte[], T> readRecordFunc, bool isMemoryChunk) where T : ILogRecord
        {
            var chunk = new Chunk(filename, chunkManager, config, isMemoryChunk);

            try
            {
                chunk.InitOngoing(readRecordFunc);
            }
            catch (OutOfMemoryException)
            {
                chunk.Dispose();
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Chunk {0} init from ongoing file failed.", chunk), ex);
                chunk.Dispose();
                throw;
            }

            return(chunk);
        }
Exemplo n.º 4
0
        public static Chunk FromCompletedFile(string filename, ChunkManager chunkManager, ChunkManagerConfig config, bool isMemoryChunk)
        {
            var chunk = new Chunk(filename, chunkManager, config, isMemoryChunk);

            try
            {
                chunk.InitCompleted();
            }
            catch (OutOfMemoryException)
            {
                chunk.Dispose();
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Chunk {0} init from completed file failed.", chunk), ex);
                chunk.Dispose();
                throw;
            }

            return(chunk);
        }
Exemplo n.º 5
0
        public static Chunk CreateNew(string filename, int chunkNumber, ChunkManager chunkManager, ChunkManagerConfig config, bool isMemoryChunk)
        {
            var chunk = new Chunk(filename, chunkManager, config, isMemoryChunk);

            try
            {
                chunk.InitNew(chunkNumber);
            }
            catch (OutOfMemoryException)
            {
                chunk.Dispose();
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Chunk {0} create failed.", chunk), ex);
                chunk.Dispose();
                throw;
            }

            return(chunk);
        }