Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 
 package io.undertow.channels;
 
 
Wrapper for write timeout. This should always be the first wrapper applied to the underlying channel.

Author(s):
Stuart Douglas
See also:
org.xnio.Options.WRITE_TIMEOUT
 
 
     private int writeTimeout;
     private XnioExecutor.Key handle;
 
     private final Runnable timeoutCommand = new Runnable() {
         @Override
         public void run() {
             ..tracef("Timing out channel %s due to inactivity");
             try {
                 if (.isWriteResumed()) {
                     ChannelListeners.invokeChannelListener(WriteTimeoutStreamSinkChannel.this.get());
                 }
             } finally {
                 IoUtils.safeClose();
             }
         }
     };

    

Parameters:
delegate The underlying channel
 
     public WriteTimeoutStreamSinkChannel(final StreamSinkChannel delegate) {
         super(delegate);
         try {
             Integer timeout = delegate.getOption(.);
             if (timeout != null) {
                 this. = timeout;
             } else {
                 this. = 0;
             }
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
     }
 
     private void handleWriteTimeout(final long ret) {
         if ( > 0) {
             if (ret == 0 &&  == null) {
             } else if (ret > 0 &&  != null) {
                 .remove();
             }
         }
     }
 
     @Override
     public int write(final ByteBuffer srcthrows IOException {
         int ret = .write(src);
         handleWriteTimeout(ret);
         return ret;
     }
 
     @Override
     public long write(final ByteBuffer[] srcsfinal int offsetfinal int lengththrows IOException {
         long ret = .write(srcsoffsetlength);
         handleWriteTimeout(ret);
         return ret;
    }
    @Override
    public int writeFinal(ByteBuffer srcthrows IOException {
        int ret = .writeFinal(src);
        handleWriteTimeout(ret);
        return ret;
    }
    @Override
    public long writeFinal(ByteBuffer[] srcsint offsetint lengththrows IOException {
        long ret = .writeFinal(srcsoffsetlength);
        handleWriteTimeout(ret);
        return ret;
    }
    @Override
    public long writeFinal(ByteBuffer[] srcsthrows IOException {
        long ret = .writeFinal(srcs);
        handleWriteTimeout(ret);
        return ret;
    }
    @Override
    public long transferFrom(final FileChannel srcfinal long positionfinal long countthrows IOException {
        long ret = .transferFrom(srcpositioncount);
        handleWriteTimeout(ret);
        return ret;
    }
    @Override
    public long transferFrom(final StreamSourceChannel sourcefinal long countfinal ByteBuffer throughBufferthrows IOException {
        long ret = .transferFrom(sourcecountthroughBuffer);
        handleWriteTimeout(ret);
        return ret;
    }
    @Override
    public <T> T setOption(final Option<T> optionfinal T valuethrows IllegalArgumentExceptionIOException {
        T ret = super.setOption(optionvalue);
        if (option == .) {
             = (Integervalue;
            if ( != null) {
                .remove();
                if( > 0) {
                    getWriteThread().executeAfter(.);
                }
            }
        }
        return ret;
    }
New to GrepCode? Check out our FAQ X