Пример #1
0
            public void Flush(LoopbackSession session)
            {
                IWriteRequestQueue queue = session.WriteRequestQueue;

                if (!session.Closing)
                {
                    lock (session.Lock)
                    {
                        try
                        {
                            if (queue.IsEmpty(session))
                            {
                                return;
                            }

                            IWriteRequest req;
                            DateTime      currentTime = DateTime.Now;
                            while ((req = queue.Poll(session)) != null)
                            {
                                Object m = req.Message;
                                _chain.PushEvent(new IoEvent(IoEventType.MessageSent, session, req), false);
                                session.RemoteSession.FilterChain.FireMessageReceived(GetMessageCopy(m));
                                IoBuffer buf = m as IoBuffer;
                                if (buf != null)
                                {
                                    session.IncreaseWrittenBytes(buf.Remaining, currentTime);
                                }
                            }
                        }
                        finally
                        {
                            if (_chain._flushEnabled)
                            {
                                _chain.FlushEvents();
                            }
                        }
                    }

                    FlushPendingDataQueues(session);
                }
                else
                {
                    List <IWriteRequest> failedRequests = new List <IWriteRequest>();
                    IWriteRequest        req;
                    while ((req = queue.Poll(session)) != null)
                    {
                        failedRequests.Add(req);
                    }

                    if (failedRequests.Count > 0)
                    {
                        WriteToClosedSessionException cause = new WriteToClosedSessionException(failedRequests);
                        foreach (IWriteRequest r in failedRequests)
                        {
                            r.Future.Exception = cause;
                        }
                        session.FilterChain.FireExceptionCaught(cause);
                    }
                }
            }