Ejemplo n.º 1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         WorkerThreadSynchronization.BeginSafeToCallbackRegion();
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 2
0
        public NetworkBinaryStream(Socket socket, int timeout = -1, WorkerThreadSynchronization workerThreadSynchronization = null)
            : base(new NetworkStream(socket), workerThreadSynchronization)
        {
            if (!BitConverter.IsLittleEndian)
            {
                throw new Exception("BigEndian processors are not supported");
            }

            m_socket = socket;
            Timeout  = timeout;
            m_socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
        }
        private SequentialReaderStream <TKey, TValue> Read(SortedTreeEngineReaderOptions readerOptions,
                                                           SeekFilterBase <TKey> keySeekFilter,
                                                           MatchFilterBase <TKey, TValue> keyMatchFilter,
                                                           WorkerThreadSynchronization workerThreadSynchronization)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            Stats.QueriesExecuted++;
            return(new SequentialReaderStream <TKey, TValue>(m_archiveList, readerOptions, keySeekFilter, keyMatchFilter, workerThreadSynchronization));
        }
Ejemplo n.º 4
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (Disposed != null)
                {
                    Disposed(this);
                }
            }
            catch (Exception)
            {
            }

            Interlocked.Add(ref Stats.PointsReturned, m_pointCount);
            m_pointCount = 0;

            if (m_timeout != null)
            {
                m_timeout.Cancel();
                m_timeout = null;
            }

            if (m_tablesOrigList != null)
            {
                m_tablesOrigList.ForEach(x => x.Dispose());
                m_tablesOrigList = null;
                Array.Clear(m_snapshot.Tables, 0, m_snapshot.Tables.Length);
            }
            m_timedOut = true;

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

            if (m_workerThreadSynchronization != null && m_ownsWorkerThreadSynchronization)
            {
                m_workerThreadSynchronization.Dispose();
                m_workerThreadSynchronization = null;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a <see cref="RemoteBinaryStream"/>
        /// </summary>
        /// <param name="stream">the underlying stream to wrap</param>
        /// <param name="workerThreadSynchronization">the synchronization object</param>
        public RemoteBinaryStream(Stream stream, WorkerThreadSynchronization workerThreadSynchronization = null)
        {
            if (!BitConverter.IsLittleEndian)
            {
                throw new Exception("BigEndian processors are not supported");
            }

            if (workerThreadSynchronization is null)
            {
                workerThreadSynchronization = new WorkerThreadSynchronization();
            }

            m_workerThreadSynchronization = workerThreadSynchronization;
            m_receiveBuffer   = new byte[BufferSize];
            m_sendBuffer      = new byte[BufferSize];
            m_sendLength      = 0;
            m_receiveLength   = 0;
            m_receivePosition = 0;
            m_stream          = stream;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Disconnects the socket.  Does not throw an exception.
        /// </summary>
        /// <remarks></remarks>
        public void Disconnect()
        {
            Socket socket = Interlocked.Exchange(ref m_socket, null);

            if (socket != null)
            {
                try
                {
                    socket.Shutdown(SocketShutdown.Both);
                }
                catch
                {
                }
                try
                {
                    socket.Close();
                }
                catch
                {
                }
            }
            WorkerThreadSynchronization.BeginSafeToCallbackRegion();
        }
            public TreeStream <TKey, TValue> Read(SortedTreeEngineReaderOptions readerOptions, SeekFilterBase <TKey> keySeekFilter, MatchFilterBase <TKey, TValue> keyMatchFilter, WorkerThreadSynchronization workerThreadSynchronization)
            {
                if (m_disposed)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }

                SequentialReaderStream <TKey, TValue> stream = m_server.Read(readerOptions, keySeekFilter, keyMatchFilter, workerThreadSynchronization);

                if (!stream.EOS)
                {
                    stream.Disposed += OnStreamDisposal;

                    lock (m_syncRoot)
                        m_openStreams.Add(stream);
                }

                return(stream);
            }
Ejemplo n.º 8
0
        public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList,
                                      SortedTreeEngineReaderOptions readerOptions             = null,
                                      SeekFilterBase <TKey> keySeekFilter                     = null,
                                      MatchFilterBase <TKey, TValue> keyMatchFilter           = null,
                                      WorkerThreadSynchronization workerThreadSynchronization = null)
        {
            if (readerOptions is null)
            {
                readerOptions = SortedTreeEngineReaderOptions.Default;
            }
            if (keySeekFilter is null)
            {
                keySeekFilter = new SeekFilterUniverse <TKey>();
            }
            if (keyMatchFilter is null)
            {
                keyMatchFilter = new MatchFilterUniverse <TKey, TValue>();
            }
            if (workerThreadSynchronization is null)
            {
                m_ownsWorkerThreadSynchronization = true;
                workerThreadSynchronization       = new WorkerThreadSynchronization();
            }

            m_workerThreadSynchronization = workerThreadSynchronization;
            m_pointCount         = 0;
            m_keySeekFilter      = keySeekFilter;
            m_keyMatchFilter     = keyMatchFilter;
            m_keyMatchIsUniverse = m_keyMatchFilter as MatchFilterUniverse <TKey, TValue> != null;

            if (readerOptions.Timeout.Ticks > 0)
            {
                m_timeout = new TimeoutOperation();
                m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true);
            }

            m_snapshot = archiveList.CreateNewClientResources();
            m_snapshot.UpdateSnapshot();
            m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >();

            for (int x = 0; x < m_snapshot.Tables.Count(); x++)
            {
                ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x];
                if (table != null)
                {
                    if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange))
                    {
                        try
                        {
                            m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table));
                        }
                        catch (Exception e)
                        {
                            //ToDo: Make sure firstkey.tostring doesn't ever throw an exception.
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine($"Archive ID {table.FileId}");
                            sb.AppendLine($"First Key {table.FirstKey.ToString()}");
                            sb.AppendLine($"Last Key {table.LastKey.ToString()}");
                            sb.AppendLine($"File Size {table.SortedTreeTable.BaseFile.ArchiveSize}");
                            sb.AppendLine($"File Name {table.SortedTreeTable.BaseFile.FilePath}");
                            Log.Publish(MessageLevel.Error, "Error while reading file", sb.ToString(), null, e);
                        }
                    }
                    else
                    {
                        m_snapshot.Tables[x] = null;
                    }
                }
            }

            m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan);

            m_keySeekFilter.Reset();
            if (m_keySeekFilter.NextWindow())
            {
                SeekToKey(m_keySeekFilter.StartOfFrame);
            }
            else
            {
                Dispose();
            }
        }
Ejemplo n.º 9
0
        public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList,
                                      SortedTreeEngineReaderOptions readerOptions             = null,
                                      SeekFilterBase <TKey> keySeekFilter                     = null,
                                      MatchFilterBase <TKey, TValue> keyMatchFilter           = null,
                                      WorkerThreadSynchronization workerThreadSynchronization = null)
        {
            if (readerOptions == null)
            {
                readerOptions = SortedTreeEngineReaderOptions.Default;
            }
            if (keySeekFilter == null)
            {
                keySeekFilter = new SeekFilterUniverse <TKey>();
            }
            if (keyMatchFilter == null)
            {
                keyMatchFilter = new MatchFilterUniverse <TKey, TValue>();
            }
            if (workerThreadSynchronization == null)
            {
                m_ownsWorkerThreadSynchronization = true;
                workerThreadSynchronization       = new WorkerThreadSynchronization();
            }

            m_workerThreadSynchronization = workerThreadSynchronization;
            m_pointCount         = 0;
            m_keySeekFilter      = keySeekFilter;
            m_keyMatchFilter     = keyMatchFilter;
            m_keyMatchIsUniverse = (m_keyMatchFilter as MatchFilterUniverse <TKey, TValue>) != null;

            if (readerOptions.Timeout.Ticks > 0)
            {
                m_timeout = new TimeoutOperation();
                m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true);
            }

            m_snapshot = archiveList.CreateNewClientResources();
            m_snapshot.UpdateSnapshot();
            m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >();

            for (int x = 0; x < m_snapshot.Tables.Count(); x++)
            {
                ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x];
                if (table != null)
                {
                    if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange))
                    {
                        m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table));
                    }
                    else
                    {
                        m_snapshot.Tables[x] = null;
                    }
                }
            }

            m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan);

            m_keySeekFilter.Reset();
            if (m_keySeekFilter.NextWindow())
            {
                SeekToKey(m_keySeekFilter.StartOfFrame);
            }
            else
            {
                Dispose();
            }
        }