Esempio n. 1
0
        /// <summary>
        /// Newly created caches do not have a MemoryStore or a DiskStore.
        ///
        /// This method creates those and makes the cache ready to accept elements.
        /// </summary>
        internal void Init()
        {
            lock (this) {
                if (_configuration.MaxElementsInMemory == 0)
                {
                    _configuration.MaxElementsInMemory = 1;
                    if (_log.IsWarnEnabled)
                    {
                        _log.Warn(string.Format(
                                      CultureInfo.InvariantCulture,
                                      SR.WarnZeroMemoryStoreSize,
                                      _configuration.Name));
                    }
                }

                _diskStore   = this.CreateDiskStore();
                _memoryStore = MemoryStore.Create(this, _diskStore);
                this.ChangeStatus(Status.Alive);
            }

            if (_log.IsDebugEnabled)
            {
                _log.Debug("Initialised cache: " + _configuration.Name);
            }
        }
Esempio n. 2
0
        private void MintBlock(List <Transaction> transactions, Chain chain)
        {
            // sync disk writes before generating more
            DiskStore.FlushAll();

            var hashes = new HashSet <Hash>(transactions.Select(tx => tx.Hash));

            var isFirstBlock = chain.LastBlock == null;

            while (hashes.Count > 0)
            {
                var block = new Block(isFirstBlock ? 1 : (chain.LastBlock.Height + 1), chain.Address, Timestamp.Now, hashes, isFirstBlock ? Hash.Null : chain.LastBlock.Hash);

                try
                {
                    chain.AddBlock(block, transactions);
                }
                catch (InvalidTransactionException e)
                {
                    var tx = transactions.First(x => x.Hash == e.Hash);
                    Interlocked.Decrement(ref _size);
                    hashes.Remove(e.Hash);

                    lock (_rejections)
                    {
                        _rejections[e.Hash] = e.Message;
                    }

                    transactions.Remove(tx);
                    OnTransactionFailed?.Invoke(tx);
                    continue;
                }

                foreach (var tx in transactions)
                {
                    Interlocked.Decrement(ref _size);
                    OnTransactionRemoved?.Invoke(tx);
                }
                break;
            }

            lock (_pendingBlocks)
            {
                _pendingBlocks.Remove(chain);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Flushes all cache items from memory to auxilliary caches and close the auxilliary caches.
        /// Should be invoked only by CacheManager.
        /// </summary>
        public void Dispose()
        {
            try {
                lock (this) {
                    if (_memoryStore != null)
                    {
                        _memoryStore.Dispose();
                        _memoryStore = null;
                    }

                    if (_diskStore != null)
                    {
                        _diskStore.Dispose();
                        _diskStore = null;
                    }

                    _status = Status.Shutdown;
                }

                this.NotificationService.NotifyDisposed(false);
            } finally {
                GC.SuppressFinalize(this);
            }
        }
Esempio n. 4
0
 public AppMetadataStore(DirectoryInfo aStoreDirectory)
 {
     var xmlReaderWriter = new XmlReaderWriter(AppMetadataSchemaSet, Logger);
     iDiskStore = new DiskStore<AppMetadata>(
         aStoreDirectory,
         AppFileExtension,
         aReader => ParseAppElement(xmlReaderWriter.ReadFile(aReader)),
         (aWriter, aApp) => xmlReaderWriter.WriteFile(aWriter, AppToXElement(aApp)));
 }
Esempio n. 5
0
 public DiskStorageContext(Address address, string name, KeyStoreDataSize dataSize)
 {
     _memory = new MemoryStore(32);
     _disk   = new DiskStore(address.Text + "_" + name, dataSize);
 }
Esempio n. 6
0
 public disk()
 {
     _path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
     Store = new DiskStore(_path);
 }