Exemplo n.º 1
0
 public void AssignToNew(string filename, IPageFormatter pageFormatter)
 {
     Flush();
     pageFormatter.Format(_page);
     _     = _page.Append(filename, out _block);
     _pins = 0;
 }
Exemplo n.º 2
0
        public Buffer PinNew(string filename, IPageFormatter pageFormatter)
        {
            //try
            //{
            long timestamp = DateTime.UtcNow.Ticks;

            Buffer buffer = null;

            lock (_bufferGatheringLock)
            {
                buffer = _poolStrategy.PinNew(filename, pageFormatter);
            }

            while (buffer == null && !WaitingForTooLong(timestamp))
            {
                Thread.Sleep(_tickWaitingTime);

                lock (_bufferGatheringLock)
                {
                    buffer = _poolStrategy.PinNew(filename, pageFormatter);
                }
            }

            if (buffer == null)
            {
                throw new BufferBusyException();
            }

            return(buffer);
            //}
            //catch (ThreadAbortException)
            //{
            //    throw new BufferBusyException();
            //}
        }
Exemplo n.º 3
0
 public void CanCreateRecordFormatter()
 {
     _tableInfo = new TableInfo(RandomFilename, _schema);
     Assert.DoesNotThrow(() =>
     {
         _recordFormatter = new RecordFormatter(_tableInfo, _fileManager);
     });
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Formatter"/> class.
 /// </summary>
 /// <param name="orderByFormatter">The order by formatter.</param>
 /// <param name="pageFormatter">The page formatter.</param>
 /// <param name="whereFormatter">The where formatter.</param>
 public Formatter(
     [NotNull] IOrderByFormatter orderByFormatter,
     [NotNull] IPageFormatter pageFormatter,
     [NotNull] IWhereFormatter whereFormatter)
 {
     this.orderByFormatter = orderByFormatter;
     this.pageFormatter    = pageFormatter;
     this.whereFormatter   = whereFormatter;
 }
Exemplo n.º 5
0
        public void Setup()
        {
            _fileManager   = new FileManager("temp", "DBs", 100);
            _logManager    = new LogManager(_fileManager, RandomFilename);
            _pageFormatter = new BasePageFormatter();

            // TODO MOCK POOL STRATEGY!!!
            // Or not? It seems default, mock would be like native...
            // Anyway, think about it a bit
        }
Exemplo n.º 6
0
        public Block PinNew(string filename, IPageFormatter pageFormatter)
        {
            var buffer = _bufferManager.PinNew(filename, pageFormatter);
            var block  = buffer.Block;

            _buffers.TryAdd(block, buffer);
            _pins.Add(block);

            return(block);
        }
Exemplo n.º 7
0
        public void CanFormatPageWithNoRecordsInside()
        {
            _tableInfo       = new TableInfo(RandomFilename, _schema);
            _recordFormatter = new RecordFormatter(_tableInfo, _fileManager);
            var page = _fileManager.ResolvePage();

            Assert.DoesNotThrow(() =>
            {
                _recordFormatter.Format(page);
            });
        }
Exemplo n.º 8
0
        public Block Append(string filename, IPageFormatter pageFormatter)
        {
            // A dummy block because honestly we do not care about block, we need to get length of this file
            var dummyBlock = new Block(filename, -1);

            _concurrencyManager.ExclusiveLock(dummyBlock);

            var lastBlock = _bufferList.PinNew(filename, pageFormatter);

            return(lastBlock);
        }
Exemplo n.º 9
0
        public void CanFormatPageWithOneStringFieldInside()
        {
            _schema.AddStringField("field", 30);

            _tableInfo       = new TableInfo(RandomFilename, _schema);
            _recordFormatter = new RecordFormatter(_tableInfo, _fileManager);

            var page = _fileManager.ResolvePage();

            Assert.DoesNotThrow(() =>
            {
                _recordFormatter.Format(page);
            });
        }
Exemplo n.º 10
0
        public Buffer PinNew(string filename, IPageFormatter pageFormatter)
        {
            // Check out, would it be possible to be on a lock as low amount of time as possible?

            lock (_poolLock)
            {
                var buffer = ChooseUnpinnedBuffer();
                if (buffer == null)
                {
                    return(null);
                }

                buffer.AssignToNew(filename, pageFormatter);
                _available--;
                buffer.Pin();
                return(buffer);
            }
        }
Exemplo n.º 11
0
 public AutoRegistrationPlugin(ISynchronizer synchronizer,
                               IRegistrationRepository registrationRepository,
                               IPageRepository pageRepository,
                               IPageFormatter pageFormatter,
                               IEntryFormatter entryFormatter,
                               INotificationSender notificationSender,
                               ILogger logger,
                               IPluginConfiguration configuration,
                               IFileReader fileReader,
                               ISettings settings)
 {
     _synchronizer           = synchronizer;
     _fileReader             = fileReader;
     _settings               = settings;
     _registrationRepository = registrationRepository;
     _pageRepository         = pageRepository;
     _pageFormatter          = pageFormatter;
     _entryFormatter         = entryFormatter;
     _notificationSender     = notificationSender;
     _logger        = logger;
     _configuration = configuration;
 }
Exemplo n.º 12
0
		public AutoRegistrationPlugin(ISynchronizer synchronizer,
		                              IRegistrationRepository registrationRepository,
		                              IPageRepository pageRepository,
		                              IPageFormatter pageFormatter,
		                              IEntryFormatter entryFormatter,
		                              INotificationSender notificationSender,
		                              ILogger logger,
		                              IPluginConfiguration configuration,
		                              IFileReader fileReader,
		                              ISettings settings)
		{
			_synchronizer = synchronizer;
			_fileReader = fileReader;
			_settings = settings;
			_registrationRepository = registrationRepository;
			_pageRepository = pageRepository;
			_pageFormatter = pageFormatter;
			_entryFormatter = entryFormatter;
			_notificationSender = notificationSender;
			_logger = logger;
			_configuration = configuration;
		}
Exemplo n.º 13
0
        public Buffer PinNew(string filename, IPageFormatter pageFormatter)
        {
            lock (_poolLock)
            {
                Buffer buffer = null;
                if (_bufferPool.Count < _totalBuffers)
                {
                    buffer = AddNewBuffer();
                    buffer.AssignToNew(filename, pageFormatter);
                }
                else
                {
                    return(null);
                }

                if (!buffer.IsPinned)
                {
                    _available--;
                }

                buffer.Pin();
                return(buffer);
            }
        }