Exemple #1
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);
            }
Exemple #2
0
        /// <inheritdoc/>
        public IWriteFuture Write(Object message, EndPoint remoteEP)
        {
            if (message == null)
            {
                return(null);
            }

            if (!TransportMetadata.Connectionless && remoteEP != null)
            {
                throw new InvalidOperationException();
            }

            // If the session has been closed or is closing, we can't either
            // send a message to the remote side. We generate a future
            // containing an exception.
            if (Closing || !Connected)
            {
                IWriteFuture  future  = new DefaultWriteFuture(this);
                IWriteRequest request = new DefaultWriteRequest(message, future, remoteEP);
                future.Exception = new WriteToClosedSessionException(request);
                return(future);
            }

            IoBuffer buf = message as IoBuffer;

            if (buf == null)
            {
                System.IO.FileInfo fi = message as System.IO.FileInfo;
                if (fi != null)
                {
                    message = new FileInfoFileRegion(fi);
                }
            }
            else if (!buf.HasRemaining)
            {
                return(DefaultWriteFuture.NewNotWrittenFuture(this,
                                                              new ArgumentException("message is empty. Forgot to call flip()?", "message")));
            }

            // Now, we can write the message. First, create a future
            IWriteFuture  writeFuture  = new DefaultWriteFuture(this);
            IWriteRequest writeRequest = new DefaultWriteRequest(message, writeFuture, remoteEP);

            // Then, get the chain and inject the WriteRequest into it
            IoFilterChain filterChain = this.FilterChain;

            filterChain.FireFilterWrite(writeRequest);

            return(writeFuture);
        }
Exemple #3
0
 public ProtocolCodecSession()
 {
     _notWrittenFuture = DefaultWriteFuture.NewNotWrittenFuture(this, new NotImplementedException());
     _encoderOutput    = new DummyProtocolEncoderOutput(_notWrittenFuture);
     _decoderOutput    = new DummyProtocolDecoderOutput();
 }