public Receipt Store <T>(WarehouseKey key, IEnumerable <T> data, IEnumerable <LoadingDockPolicy> loadingDockPolicies) { ThrowIfNotInitialized(); var uuid = Guid.NewGuid(); ConcurrentBag <LoadingDockPolicy> enforcedPolicies = new ConcurrentBag <LoadingDockPolicy>(); // resolve the appropriate store, based on the policy Parallel.ForEach(ResolveShelves <T>(loadingDockPolicies), (shelf) => { shelf.Store(key, data, enforcedPolicies); }); // the receipt is largely what was passed in when it was stored var receipt = new Receipt(enforcedPolicies.Any()) { UUID = uuid, Key = key.Id, Scope = key.Scope, // add the policies that were upheld during the store, this is necessary, // because this warehouse might not be able to satisfy all of the policies Policies = enforcedPolicies.Distinct().ToList(), SHA256Checksum = CalculateChecksum <T>(data) }; SessionReceipts.Add(receipt); return(receipt); }
public void Store(WarehouseKey key, IEnumerable <string> payload, IProducerConsumerCollection <LoadingDockPolicy> enforcedPolicies) { Records.AddOrUpdate(new MemoryShelfKey(key.Scope, key.Id), payload.ToList(), (k, a) => payload.ToList()); foreach (var pol in SupportedPolicies) { enforcedPolicies.TryAdd(pol); } }
public void Append <T>(WarehouseKey key, IEnumerable <T> data, IEnumerable <LoadingDockPolicy> loadingDockPolicies) { ThrowIfNotInitialized(); Parallel.ForEach(ResolveShelves <T>(loadingDockPolicies), (shelf) => { shelf.Append(key, data); }); }
public ShelfManifest GetManifest(WarehouseKey key) { if (CanRetrieve(key)) { // the only way to get metadata from a memory shelf is to actually just retrieve it. // TODO: store metadata separately for items as stord return(new ShelfManifest(SupportedPolicies, CalculateSize(Retrieve(key)))); } return(null); }
public IEnumerable <T> Retrieve <T>(WarehouseKey key) { ThrowIfNotInitialized(); return (Shelves // We can't just use the OfType, because we ned to handle inheritance // buy we do want this for speed. .OfType <IShelf <T> >() .FirstOrDefault(shelf => shelf.CanRetrieve(key)) .Retrieve(key) ?? Enumerable.Empty <T>()); }
public WarehouseKeyManifest GetManifest(WarehouseKey key) { // right now, we just return the data that was sent when it was created var policies = SessionReceipts.FirstOrDefault(sr => sr.Key == key.Id)?.Policies; // if there aren't any receipts for this, the warehouse has no idea where they're stored. // TODO: ideally, the warehouse will eventually be able to resolve the receipts from their state if (policies == null) { return(new WarehouseKeyManifest()); } return(new WarehouseKeyManifest { // TODO: where do we get the type from? is it passed in? Why should it matter here? StorageShelvesManifests = ResolveShelves <object>(policies).Where(s => s.CanRetrieve(key)).Select(shelf => shelf.GetManifest(key)).ToList(), StoragePolicies = policies }); }
public void Append(WarehouseKey key, IEnumerable <string> additionalPayload) { Records.AddOrUpdate(new MemoryShelfKey(key.Scope, key.Id), additionalPayload.ToList(), (k, a) => a.Concat(additionalPayload).ToList()); }
public IEnumerable <string> Retrieve(WarehouseKey key) { return(Records.GetValueOrDefault(new MemoryShelfKey(key.Scope, key.Id), new List <string>())); }
public bool CanRetrieve(WarehouseKey key) { return(Records.Keys.Contains(new MemoryShelfKey(key.Scope, key.Id))); }