Esempio n. 1
0
        public void TestWriteFuture()
        {
            DefaultWriteFuture future = new DefaultWriteFuture(null);
            Assert.IsFalse(future.Done);
            Assert.IsFalse(future.Written);

            TestThread thread = new TestThread(future);
            thread.Start();

            future.Written = true;
            thread.Join();

            Assert.IsTrue(thread.success);
            Assert.IsTrue(future.Done);
            Assert.IsTrue(future.Written);

            future = new DefaultWriteFuture(null);
            thread = new TestThread(future);
            thread.Start();

            future.Exception = new Exception();
            thread.Join();

            Assert.IsTrue(thread.success);
            Assert.IsTrue(future.Done);
            Assert.IsFalse(future.Written);
            Assert.IsTrue(future.Exception.GetType() == typeof(Exception));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a new <see cref="DefaultWriteFuture"/> which is already marked as 'not written'.
        /// </summary>
        public static IWriteFuture NewNotWrittenFuture(IoSession session, Exception cause)
        {
            DefaultWriteFuture unwrittenFuture = new DefaultWriteFuture(session);

            unwrittenFuture.Exception = cause;
            return(unwrittenFuture);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a new <see cref="DefaultWriteFuture"/> which is already marked as 'written'.
        /// </summary>
        public static IWriteFuture NewWrittenFuture(IoSession session)
        {
            DefaultWriteFuture writtenFuture = new DefaultWriteFuture(session);

            writtenFuture.Written = true;
            return(writtenFuture);
        }
Esempio n. 4
0
            public override IWriteFuture Flush()
            {
                IQueue<Object> bufferQueue = MessageQueue;
                IWriteFuture future = null;

                while (!bufferQueue.IsEmpty)
                {
                    Object encodedMessage = bufferQueue.Dequeue();

                    if (encodedMessage == null)
                        break;

                    // Flush only when the buffer has remaining.
                    IoBuffer buf = encodedMessage as IoBuffer;
                    if (buf == null || buf.HasRemaining)
                    {
                        future = new DefaultWriteFuture(_session);
                        _nextFilter.FilterWrite(_session, new EncodedWriteRequest(encodedMessage, future, _destination));
                    }
                }

                if (future == null)
                {
                    // Creates an empty writeRequest containing the destination
                    IWriteRequest writeRequest = new DefaultWriteRequest(DefaultWriteRequest.EmptyMessage, null, _destination);
                    future = DefaultWriteFuture.NewNotWrittenFuture(_session, new NothingWrittenException(writeRequest));
                }

                return future;
            }
Esempio n. 5
0
 /// <summary>
 /// Returns a new <see cref="DefaultWriteFuture"/> which is already marked as 'not written'.
 /// </summary>
 public static IWriteFuture NewNotWrittenFuture(IoSession session, Exception cause)
 {
     DefaultWriteFuture unwrittenFuture = new DefaultWriteFuture(session);
     unwrittenFuture.Exception = cause;
     return unwrittenFuture;
 }
Esempio n. 6
0
 /// <summary>
 /// Returns a new <see cref="DefaultWriteFuture"/> which is already marked as 'written'.
 /// </summary>
 public static IWriteFuture NewWrittenFuture(IoSession session)
 {
     DefaultWriteFuture writtenFuture = new DefaultWriteFuture(session);
     writtenFuture.Written = true;
     return writtenFuture;
 }