Exemple #1
0
        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);
                }
            }
        }
Exemple #2
0
 public void Unregister(StreamID streamID)
 {
     lock (this)
     {
         if (StreamTracingEnabled)
         {
             StreamEvents.Deallocate(streamID);
         }
         InternalUnregister(streamID);
     }
 }