public StreamHeader(StreamID streamID, IStreamProvider provider) : base() { _streamID = streamID; _provider = provider; #if LOCKSTREAMS FLockID = new LockID(this, AStreamID.ToString()); #endif }
public override void Deallocate(StreamID streamID) { lock (this) { StreamHeader header = GetStreamHeader(streamID); if (StreamTracingEnabled) { StreamEvents.Deallocate(streamID); } _headers.Remove(streamID); StreamID sourceStreamID;; if (!_referencingHeaders.TryGetValue(streamID, out sourceStreamID)) { // if this stream is a referenced stream if (header.References.Count > 0) { // select a referencing stream to be the new source stream StreamID newStreamID = header.References[0]; StreamHeader newHeader = GetStreamHeader(newStreamID); // reassign the stream id for the stream in the provider (from this stream to the new source stream id) header.Provider.Reassign(header.StreamID, newStreamID); // change the provider in the header for the new source stream id newHeader.Provider = header.Provider; if (newHeader.Stream != null) { newHeader.Stream.SourceStream = newHeader.Provider.Open(newStreamID); // TODO: Shouldn't this close the old stream? } // dereference the new header _referencingHeaders.Remove(newStreamID); header.References.RemoveAt(0); // move all references to this stream to the new source stream MoveReferences(header, newHeader); } else { // destroy this stream header.Provider.Destroy(streamID); } } else { // if this stream is a reference stream StreamHeader sourceHeader = GetStreamHeader(sourceStreamID); // move all references to this stream to the source stream MoveReferences(header, sourceHeader); // dereference the source stream sourceHeader.References.Remove(streamID); _referencingHeaders.Remove(streamID); } } }
public override void Destroy(StreamID streamID) { lock (this) { FileStreamHeader header = GetStreamHeader(streamID); _headers.Remove(streamID); header.Dispose(); } }
// IStreamManager public StreamID Allocate() { // Allocates a new stream in the source stream manager, and saves the header and local cache for it locally StreamID streamID = _sourceStreamManager.Allocate(); LocalStreamHeader header = new LocalStreamHeader(streamID); _headers.Add(header); return(streamID); }
public override void Reassign(StreamID oldStreamID, StreamID newStreamID) { lock (this) { FileStreamHeader oldHeader = GetStreamHeader(oldStreamID); _headers.Remove(oldStreamID); oldHeader.StreamID = newStreamID; _headers.Add(oldHeader); } }
public void Flush(StreamID streamID) { // Ensures that the given local cache is flushed to the source stream manager LocalStreamHeader header; if (_headers.TryGetValue(streamID, out header) && (header.Stream != null)) { header.Stream.Flush(); } }
private FileStreamHeader GetStreamHeader(StreamID streamID) { FileStreamHeader header; if (!_headers.TryGetValue(streamID, out header)) { throw new StreamsException(StreamsException.Codes.StreamIDNotFound, streamID.ToString()); } return(header); }
public void Unregister(StreamID streamID) { lock (this) { if (StreamTracingEnabled) { StreamEvents.Deallocate(streamID); } InternalUnregister(streamID); } }
public void Deallocate(StreamID streamID) { for (int index = 0; index < Count; index++) { if (this[index].StreamID == streamID) { this[index].Deallocated = true; break; } } }
public int CompareTo(object AObject) { if (!(AObject is StreamID)) { throw new StreamsException(StreamsException.Codes.InvalidComparison, AObject.GetType().Name); } StreamID LValue = (StreamID)AObject; return(LValue.Value == Value ? 0 : (LValue.Value > Value ? 1 : -1)); }
public void Close(StreamID streamID) { for (int index = 0; index < Count; index++) { if (this[index].StreamID == streamID) { this[index].OpenCount--; break; } } }
public IRemoteStream OpenRemote(StreamID streamID, LockMode mode) { Stream stream = Open(streamID, mode); IRemoteStream result = stream as IRemoteStream; if (result != null) { return(result); } return(new CoverStream(stream)); }
public StreamID Register(IStreamProvider provider) { lock (this) { StreamID streamID = InternalGetNextStreamID(); InternalRegister(streamID, provider); if (StreamTracingEnabled) { StreamEvents.Add(new RegisterStreamEvent(streamID)); } return(streamID); } }
public override StreamID Allocate() { lock (this) { StreamID streamID = InternalGetNextStreamID(); if (StreamTracingEnabled) { StreamEvents.Add(new AllocateStreamEvent(streamID)); } _defaultProvider.Create(streamID); InternalRegister(streamID, _defaultProvider); return(streamID); } }
public override StreamID Reference(StreamID streamID) { lock (this) { StreamID localStreamID = InternalGetNextStreamID(); StreamHeader header = GetStreamHeader(streamID); if (StreamTracingEnabled) { StreamEvents.Add(new ReferenceStreamEvent(localStreamID, header.StreamID)); } header.References.Add(localStreamID); _referencingHeaders.Add(localStreamID, streamID); InternalRegister(localStreamID, _defaultProvider); return(localStreamID); } }
public Stream Open(StreamID streamID, LockMode mode) { // Ensures that the given stream is supported by a local cache and returns a stream accessing it LocalStreamHeader header; if (!_headers.TryGetValue(streamID, out header)) { header = new LocalStreamHeader(streamID, new LocalStream(this, streamID, mode)); //FSourceStreamManager.Open(AStreamID, AMode))); _headers.Add(header); } else if (header.Stream == null) { header.Stream = new LocalStream(this, streamID, mode); //, FSourceStreamManager.Open(AStreamID, AMode)); } return(new CoverStream(header.Stream)); }
public override void Close(int ownerID, StreamID streamID) { lock (this) { #if DEBUG _closeCount++; #endif if (_streamTracingEnabled) { StreamEvents.Close(streamID); StreamOpens.Add(String.Format("Close {0}", streamID.Value.ToString())); } StreamHeader header = GetStreamHeader(streamID); InternalClose(header); } }
public override Stream Open(int ownerID, StreamID streamID, LockMode mode) { lock (this) { #if DEBUG _openCount++; #endif if (_streamTracingEnabled) { StreamEvents.Open(streamID); StreamOpens.Add(String.Format("Open {0}", streamID.Value.ToString())); } StreamHeader header = GetStreamHeader(streamID); return(new ManagedStream(this, ownerID, streamID, InternalOpen(header, false))); } }
public void Release(StreamID streamID) { // Ensures that the given local cache is flushed and closes the stream obtained from the source stream manager LocalStreamHeader header; if (_headers.TryGetValue(streamID, out header)) { if (header.Stream != null) { header.Stream.Flush(); #if UNMANAGEDSTREAM FSourceStreamManager.Close(AStreamID); #else header.Stream.Close(); #endif header.Stream = null; } _headers.Remove(header.StreamID); header.Dispose(); } }
protected void MoveReferences(StreamHeader fromHeader, StreamHeader toHeader) { for (int index = fromHeader.References.Count - 1; index >= 0; index--) { StreamID streamID = fromHeader.References[index]; // Remove the reference to the from header fromHeader.References.RemoveAt(index); _referencingHeaders.Remove(streamID); // Add the reference to the to header toHeader.References.Add(streamID); _referencingHeaders.Add(streamID, toHeader.StreamID); // Make sure the referencing header has the right stream StreamHeader referenceHeader = GetStreamHeader(streamID); if (referenceHeader.Stream != null) { referenceHeader.Stream.SourceStream = toHeader.Provider.Open(toHeader.StreamID); // TODO: Shouldn't this close the old stream? } } }
public abstract StreamID Reference(StreamID streamID);
public abstract void Reassign(StreamID oldStreamID, StreamID newStreamID);
public abstract void Destroy(StreamID streamID);
public abstract void Close(StreamID streamID);
public abstract Stream Open(StreamID streamID);
public abstract void Close(int ownerID, StreamID streamID);
public IRemoteStream OpenRemote(int ownerID, StreamID streamID, LockMode mode) { return((IRemoteStream)Open(ownerID, streamID, mode)); }
public abstract Stream Open(int ownerID, StreamID streamID, LockMode mode);
public abstract void Deallocate(StreamID streamID);
public void Close(StreamID streamID) { // Close takes no action, the local cache is still maintained, so the remote stream is kept open // a call to flush is required to force the data back to the remote stream manager }