public IBin FindTargetBin(IItem item, List <IBin> bins) { var highestScore = -1.0; var targetBin = bins[0]; foreach (var bin in bins) { var score = bin.ScoreItem(item); if (score > highestScore) { highestScore = score; targetBin = bin; } } if (Math.Abs(highestScore - 1.0) < Double.Epsilon) { // Rotate list IBin first = bins[0]; bins.RemoveAt(0); bins.Add(first); //System.Console.WriteLine("Score {2:0.00}: {0} > {1}", item, targetBin, highestScore); } return(targetBin); }
public void Run() { saveAsBin.Sync(); saveAsBin.Close(); try { File4.Copy(oldUri, newUri); } catch (Exception e) { this._enclosing.ReopenOldConfiguration(saveAsBin, oldConfiguration, newUri, e); } BinConfiguration newConfiguration = this._enclosing.PointToNewUri(oldConfiguration , newUri); try { IBin newBin = this._enclosing._storage.Open(newConfiguration); saveAsBin.DelegateTo(newBin); this._enclosing._binRecords.Remove(oldUri); this._enclosing._binRecords.Put(newUri, new SaveAsStorage.BinRecord(newConfiguration , saveAsBin)); } catch (Exception e) { this._enclosing.ReopenOldConfiguration(saveAsBin, oldConfiguration, newUri, e); } }
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public override IBin Open(BinConfiguration config) { IBin bin = base.Open(config); ((IBlockSize)Environments.My(typeof(IBlockSize))).Register((IListener4)bin); return(bin); }
public PortioningMachine(Container container, ILog log, int nBins) { _container = container; _log = log; for (int i = 0; i < nBins; i++) { _bins.Add(new Bin(container, i)); } _portioner = new Portioner(); _weight = new Weight(_portioner); _inFeed = new InFeed(_weight); IAssignmentAlgorithm assignmentAlgorithm = new BinScoreAlgorithm(); _controlUnit = new ControlUnit(_weight, _portioner, _bins, assignmentAlgorithm); _inFeed.ItemArrived += new ItemArrivedHandler(delegate(object o, IItem i) { //_log.LogMessage($"Item with id {i.Id} arrived at infeed"); }); foreach (IBin bin in _bins) { bin.BinEmptied += new BinEmptiedHandler(delegate(object o, BinStat binStat) { IBin bin = o as IBin; _log.LogMessage($"Bin {binStat.BinNumber} emptied. Current weight: {binStat.Weight:n0}. Target weight: {binStat.TargetWeight:n0}, Give-away: {binStat.Giveaway:n2}%"); }); } }
public virtual void TestExistsWithZeroLengthFile() { IBin storage = subject.Open(new BinConfiguration(TempFile(), false, 0, false)); storage.Close(); Assert.IsFalse(subject.Exists(TempFile())); }
/// <exception cref="System.IO.IOException"></exception> private static void CopyBin(IStorage sourceStorage, IStorage targetStorage, string sourcePath, string targetPath) { IBin origBin = sourceStorage.Open(new BinConfiguration(sourcePath, true, 0, true) ); try { IBin backupBin = targetStorage.Open(new BinConfiguration(targetPath, true, origBin .Length(), false)); try { byte[] buffer = new byte[4096]; int bytesRead = -1; int pos = 0; while ((bytesRead = origBin.Read(pos, buffer, buffer.Length)) >= 0) { backupBin.Write(pos, buffer, bytesRead); pos += bytesRead; } } finally { SyncAndClose(backupBin); } } finally { SyncAndClose(origBin); } }
public void item_handler(object source, IItem item) { _logger.item_arrived(item); IBin bin = _algorithm.find_bin(item, _bins); bin.add(item); }
protected virtual void Open(bool readOnly) { if (null != _bin) { throw new InvalidOperationException(); } _bin = Storage().Open(new BinConfiguration(TempFile(), false, 0, readOnly)); }
/// <exception cref="System.Exception"></exception> private void AssertReadWriteString(IBin adapter, string str) { byte[] data = Sharpen.Runtime.GetBytesForString(str); byte[] read = new byte[2048]; adapter.Write(0, data, data.Length); adapter.Read(0, read, read.Length); Assert.AreEqual(str, Sharpen.Runtime.GetStringForBytes(read, 0, data.Length)); }
protected override IBin ProduceBin(BinConfiguration config, int pageSize) { IBin bin = base.ProduceBin(config, pageSize); bin.Write(0, PagingMemoryStorageTestCase.Data, PagingMemoryStorageTestCase.Data.Length ); return(bin); }
/// <exception cref="System.Exception"></exception> public virtual void SetUp() { storage = new MemoryStorage(); IBin bin = storage.Open(new BinConfiguration(DbPath, false, 0, false)); bin.Write(0, new byte[] { 1, 2, 3 }, 3); bin.Close(); }
private void CheckBinWeight(object o, IItem item) { IBin bin = (o as IBin); if (bin.CurrentWeight >= bin.TargetWeight) { bin.Empty(); } }
private void ReopenOldConfiguration(SaveAsStorage.SaveAsBin saveAsBin, BinConfiguration config, string newUri, Exception e) { IBin safeBin = _storage.Open(config); saveAsBin.DelegateTo(safeBin); throw new Db4oException("Copying to " + newUri + " failed. Reopened " + config.Uri (), e); }
protected virtual void Close() { if (null != _bin) { _bin.Sync(); _bin.Close(); _bin = null; } }
protected override IBin Decorate(BinConfiguration config, IBin bin) { MsgExceptionHandlingTestCase.CloseAwareBin decorated = new MsgExceptionHandlingTestCase.CloseAwareBin (this, bin); lock (_openBins) { _openBins[decorated] = decorated; } return decorated; }
protected override IBin Decorate(BinConfiguration config, IBin bin) { MsgExceptionHandlingTestCase.CloseAwareBin decorated = new MsgExceptionHandlingTestCase.CloseAwareBin (this, bin); lock (_openBins) { _openBins[decorated] = decorated; } return(decorated); }
/// <exception cref="System.IO.IOException"></exception> public virtual void Rename(string oldUri, string newUri) { IBin bin = ((IBin)Sharpen.Collections.Remove(_binsByUri, oldUri)); if (bin == null) { throw new IOException("Bin not found: " + oldUri); } _binsByUri[newUri] = bin; }
private long BackupLength() { IBin backupBin = BackupStorage().Open(new BinConfiguration(TempFile(), true, 0, true )); long backupLength = backupBin.Length(); backupBin.Sync(); backupBin.Close(); return(backupLength); }
public LogReplayer(String logFilePath, IBin bin, ISet commands) { _logFilePath = logFilePath; _bin = bin; _commands = commands; _counts = new Hashtable(); foreach (object com in commands) { _counts[com] = (Int64)0; } }
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public CachingBin(IBin bin, ICache4 cache, int pageCount, int pageSize) : base(bin ) { _onDiscardPage = new _IProcedure4_22(this); _producerFromDisk = new _IFunction4_138(this); _producerFromPool = new _IFunction4_147(this); _pageSize = pageSize; _pagePool = new SimpleObjectPool(NewPagePool(pageCount)); _cache = cache; _fileLength = _bin.Length(); }
private void SyncAndClose(IBin bin) { try { bin.Sync(); } finally { bin.Close(); } }
/// <summary>opens a Bin for the given URI.</summary> /// <remarks>opens a Bin for the given URI.</remarks> /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public override IBin Open(BinConfiguration config) { IBin storage = base.Open(config); if (config.ReadOnly()) { return(new ReadOnlyBin(new CachingStorage.NonFlushingCachingBin(storage, NewCache (), _pageCount, _pageSize))); } return(new CachingBin(storage, NewCache(), _pageCount, _pageSize)); }
protected override IBin Decorate(BinConfiguration config, IBin bin) { var decorated = new CloseAwareBin (this, bin); lock (_openBins) { _openBins[decorated] = decorated; } return(decorated); }
public virtual void Test() { PagingMemoryStorage storage = new _PagingMemoryStorage_13(); IBin testBin = storage.Open(new BinConfiguration(string.Empty, true, 0, false)); Assert.AreEqual(Data.Length, testBin.Length()); int actualLength = (int)testBin.Length(); byte[] read = new byte[actualLength]; testBin.Read(0, read, actualLength); ArrayAssert.AreEqual(Data, read); }
private IBin AcquireBin(BinConfiguration config) { IBin storage = Bin(config.Uri()); if (null != storage) { return(storage); } IBin newStorage = ProduceBin(config, _pageSize); _binsByUri[config.Uri()] = newStorage; return(newStorage); }
public IBin find_bin(IItem item, List <IBin> bins) { IBin curr_bin = bins[0]; foreach (var bin in bins) { if (bin.score_item(item) > curr_bin.score_item(item)) { curr_bin = bin; } } return(curr_bin); }
private IBin ProduceBin(BinConfiguration config) { IBin storage = Bin(config.Uri()); if (null != storage) { return(storage); } IBin newStorage = new PagingMemoryBin(_pageSize, config.InitialLength()); _binsByUri[config.Uri()] = newStorage; return(newStorage); }
protected override IBin Decorate(BinConfiguration config, IBin bin) { try { var file = new FileStream(_fileName, FileMode.Create); var @out = new StreamWriter(file); return new LoggingBin(bin, @out, _config); } catch(FileNotFoundException e) { throw new Db4oIOException(e); } }
protected override IBin Decorate(BinConfiguration config, IBin bin) { try { var file = new FileStream(_fileName, FileMode.Create); var @out = new StreamWriter(file); return(new LoggingBin(bin, @out, _config)); } catch (FileNotFoundException e) { throw new Db4oIOException(e); } }
public virtual void TestInitialLength() { Storage().Open(new BinConfiguration(TempFile(), false, 1000, false)).Close(); IBin bin = Storage().Open(new BinConfiguration(TempFile(), false, 0, false)); try { Assert.AreEqual(1000, bin.Length()); } finally { bin.Close(); } }
private IBin ProduceStorage(BinConfiguration config) { IBin storage = Bin(config.Uri()); if (null != storage) { return(storage); } MemoryBin newStorage = new MemoryBin(new byte[(int)config.InitialLength()], _growthStrategy ); _bins[config.Uri()] = newStorage; return(newStorage); }
private static void SyncAndClose(IBin bin) { if (bin != null) { try { bin.Sync(); } finally { bin.Close(); } } }
/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception> public NonFlushingCachingBin(IBin bin, ICache4 cache, int pageCount, int pageSize ) : base(bin, cache, pageCount, pageSize) { }
public LogReplayer(String logFilePath, IBin bin): this(logFilePath, bin, LogConstants.AllEntries()) { }
public ThreadedSyncBin(IBin bin) : base(bin) { _thread = new Thread(new _IRunnable_23(this), "ThreadedSyncBin"); _thread.Start(); }
public MockBin(IBin bin, string password) : base(bin) { _password = password; }
protected override IBin Decorate(BinConfiguration config, IBin bin) { ResetShutdownState(); return new ExceptionSimulatingStorage.ExceptionSimulatingBin(bin, _exceptionFactory , _triggerCondition); }
public virtual void DelegateTo(IBin bin) { _bin = bin; }
protected virtual IBin Decorate(BinConfiguration config, IBin bin) { return bin; }
public _ICodeBlock_21(IBin adapter) { this.adapter = adapter; }
private void AssertReadOnly(IBin adapter) { Assert.Expect(typeof(Db4oIOException), new _ICodeBlock_21(adapter)); }
protected override IBin Decorate(BinConfiguration config, IBin storage) { return new NonFlushingStorage.NonFlushingBin(storage); }
public BlockAwareBin(IBin bin) : base(bin) { }
public NonFlushingBin(IBin storage) : base(storage) { }
protected override IBin Decorate(BinConfiguration config, IBin bin) { var decorated = new CloseAwareBin (this, bin); lock (_openBins) { _openBins[decorated] = decorated; } return decorated; }
protected override IBin Decorate(BinConfiguration config, IBin bin) { return new MonitoredBin(bin); }
protected override IBin Decorate(BinConfiguration config, IBin bin) { return new MockBin(bin, password); }
public CloseAwareBin(CloseAwareStorage storage, IBin bin) : base(bin) { _storage = storage; }
public MonitoredBin(IBin bin) : base(bin) { _bytesWrittenCounter = Db4oPerformanceCounters.CounterFor(PerformanceCounterSpec.BytesWrittenPerSec, false); _bytesReadCounter = Db4oPerformanceCounters.CounterFor(PerformanceCounterSpec.BytesReadPerSec, false); }
internal SaveAsBin(IBin delegate_) { _bin = delegate_; }
protected override IBin Decorate(BinConfiguration config, IBin bin) { return new LoggingBin(base.Decorate(config, bin)); }
public ReadOnlyBin(IBin storage) : base(storage) { }
public virtual void Replay(IBin bin) { bin.Read(_pos, PrepareBuffer(), _length); }
internal ExceptionSimulatingBin(IBin bin, IExceptionFactory exceptionFactory, ExceptionSimulatingStorage.ExceptionTriggerCondition triggerCondition) : base(bin) { _exceptionFactory = exceptionFactory; _triggerCondition = triggerCondition; }
public virtual void Replay(IBin bin) { bin.Sync(); }