Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.proxy;
 
 
 
 public abstract class ProxyConnection extends AbstractConnection
 {
     protected static final Logger LOG = .;
     private final IteratingCallback pipe = new ProxyIteratingCallback();
     private final ByteBufferPool bufferPool;
     private final ConcurrentMap<StringObjectcontext;
     private Connection connection;
 
     protected ProxyConnection(EndPoint endpExecutor executorByteBufferPool bufferPoolConcurrentMap<StringObjectcontext)
     {
         super(endpexecutor);
         this. = bufferPool;
         this. = context;
     }
 
     public ByteBufferPool getByteBufferPool()
     {
         return ;
     }
 
     public ConcurrentMap<StringObjectgetContext()
     {
         return ;
     }
 
     public Connection getConnection()
     {
         return ;
     }
 
     public void setConnection(Connection connection)
     {
         this. = connection;
     }
 
     @Override
     public void onFillable()
     {
         .iterate();
     }
 
     protected abstract int read(EndPoint endPointByteBuffer bufferthrows IOException;
 
     protected abstract void write(EndPoint endPointByteBuffer bufferCallback callback);
 
     @Override
     public String toString()
     {
         return String.format("%s[l:%d<=>r:%d]",
                 super.toString(),
                 getEndPoint().getLocalAddress().getPort(),
                 getEndPoint().getRemoteAddress().getPort());
     }
 
     private class ProxyIteratingCallback extends IteratingCallback
     {
         private ByteBuffer buffer;
         private int filled;
 
         @Override
         protected Action process() throws Exception
         {
              = .acquire(getInputBufferSize(), true);
             try
             {
                 int filled = this. = read(getEndPoint(), );
                if (.isDebugEnabled())
                    .debug("{} filled {} bytes"ProxyConnection.thisfilled);
                if (filled > 0)
                {
                    write(.getEndPoint(), this);
                    return .;
                }
                else if (filled == 0)
                {
                    .release();
                    fillInterested();
                    return .;
                }
                else
                {
                    .release();
                    .getEndPoint().shutdownOutput();
                    return .;
                }
            }
            catch (IOException x)
            {
                if (.isDebugEnabled())
                    .debug(ProxyConnection.this + " could not fill"x);
                disconnect();
                return .;
            }
        }
        @Override
        public void succeeded()
        {
            if (.isDebugEnabled())
                .debug("{} wrote {} bytes"ProxyConnection.this);
            .release();
            super.succeeded();
        }
        @Override
        protected void onCompleteSuccess()
        {
        }
        @Override
        protected void onCompleteFailure(Throwable x)
        {
            if (.isDebugEnabled())
                .debug(ProxyConnection.this + " failed to write " +  + " bytes"x);
            disconnect();
        }
        private void disconnect()
        {
            .release();
            ProxyConnection.this.close();
            .close();
        }
    }
New to GrepCode? Check out our FAQ X