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;
 
 
Stream sink channel. When this channel is considered detached it will no longer forward calls to the delegate

Author(s):
Stuart Douglas
 
 public abstract class DetachableStreamSinkChannel implements StreamSinkChannel {
 
 
     protected final StreamSinkChannel delegate;
 
     public DetachableStreamSinkChannel(final StreamSinkChannel delegate) {
         this. = delegate;
     }
 
     protected abstract boolean isFinished();
 
     @Override
     public void suspendWrites() {
         if (isFinished()) {
             return;
         }
         .suspendWrites();
     }
 
 
     @Override
     public boolean isWriteResumed() {
         if (isFinished()) {
             return false;
         }
         return .isWriteResumed();
     }
 
     @Override
     public void shutdownWrites() throws IOException {
         if (isFinished()) {
             return;
         }
         .shutdownWrites();
     }
 
     @Override
     public void awaitWritable() throws IOException {
         if (isFinished()) {
             throw ..channelIsClosed();
         }
         .awaitWritable();
     }
 
     @Override
     public void awaitWritable(final long timefinal TimeUnit timeUnitthrows IOException {
         if (isFinished()) {
             throw ..channelIsClosed();
         }
         .awaitWritable(timetimeUnit);
     }
 
     @Override
     public XnioExecutor getWriteThread() {
         return .getWriteThread();
    }
    @Override
    public boolean isOpen() {
        return !isFinished() && .isOpen();
    }
    @Override
    public void close() throws IOException {
        if (isFinished()) return;
        .close();
    }
    @Override
    public boolean flush() throws IOException {
        if (isFinished()) {
            return true;
        }
        return .flush();
    }
    @Override
    public long transferFrom(final FileChannel srcfinal long positionfinal long countthrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .transferFrom(srcpositioncount);
    }
    @Override
    public long transferFrom(final StreamSourceChannel sourcefinal long countfinal ByteBuffer throughBufferthrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .transferFrom(sourcecountthroughBuffer);
    }
    @Override
    public ChannelListener.Setter<? extends StreamSinkChannelgetWriteSetter() {
        if ( == null) {
             = new ChannelListener.SimpleSetter<>();
            if (!isFinished()) {
                if( instanceof ConduitStreamSinkChannel) {
                    ((ConduitStreamSinkChannel).setWriteListener(ChannelListeners.delegatingChannelListener(this));
                } else {
                    .getWriteSetter().set(ChannelListeners.delegatingChannelListener(this));
                }
            }
        }
        return ;
    }
    @Override
    public ChannelListener.Setter<? extends StreamSinkChannelgetCloseSetter() {
        if ( == null) {
             = new ChannelListener.SimpleSetter<>();
            if (!isFinished()) {
                .getCloseSetter().set(ChannelListeners.delegatingChannelListener(this));
            }
        }
        return ;
    }
    @Override
    public XnioWorker getWorker() {
        return .getWorker();
    }
    @Override
    public XnioIoThread getIoThread() {
        return .getIoThread();
    }
    @Override
    public long write(final ByteBuffer[] srcsfinal int offsetfinal int lengththrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .write(srcsoffsetlength);
    }
    @Override
    public long write(final ByteBuffer[] srcsthrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .write(srcs);
    }
    @Override
    public int writeFinal(ByteBuffer srcthrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .writeFinal(src);
    }
    @Override
    public long writeFinal(ByteBuffer[] srcsint offsetint lengththrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .writeFinal(srcsoffsetlength);
    }
    @Override
    public long writeFinal(ByteBuffer[] srcsthrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .writeFinal(srcs);
    }
    @Override
    public boolean supportsOption(final Option<?> option) {
        return .supportsOption(option);
    }
    @Override
    public <T> T getOption(final Option<T> optionthrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .getOption(option);
    }
    @Override
    public <T> T setOption(final Option<T> optionfinal T valuethrows IllegalArgumentExceptionIOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .setOption(optionvalue);
    }
    @Override
    public int write(final ByteBuffer srcthrows IOException {
        if (isFinished()) {
            throw ..channelIsClosed();
        }
        return .write(src);
    }
    @Override
    public void resumeWrites() {
        if (isFinished()) {
            return;
        }
        .resumeWrites();
    }
    @Override
    public void wakeupWrites() {
        if (isFinished()) {
            return;
        }
        .wakeupWrites();
    }
    public void responseDone() {
        if( instanceof ConduitStreamSinkChannel) {
            ((ConduitStreamSinkChannel).setCloseListener(null);
            ((ConduitStreamSinkChannel).setWriteListener(null);
        } else {
            .getCloseSetter().set(null);
            .getWriteSetter().set(null);
        }
        if (.isWriteResumed()) {
            .suspendWrites();
        }
    }
New to GrepCode? Check out our FAQ X