/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You 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 org.apache.coyote.ajp;

import org.apache.coyote.Processor;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.net.Nio2Channel;
import org.apache.tomcat.util.net.Nio2Endpoint;
import org.apache.tomcat.util.net.Nio2Endpoint.Handler;
import org.apache.tomcat.util.net.SocketWrapperBase;


/**
 * This the NIO2 based protocol handler implementation for AJP.
 */
public class AjpNio2Protocol extends AbstractAjpProtocol<Nio2Channel> {

    private static final Log log = LogFactory.getLog(AjpNio2Protocol.class);

    @Override
    protected Log getLog() { return log; }


    // ------------------------------------------------------------ Constructor

    public AjpNio2Protocol() {
        super(new Nio2Endpoint());
        AjpConnectionHandler cHandler = new AjpConnectionHandler(this);
        setHandler(cHandler);
        ((Nio2Endpoint) getEndpoint()).setHandler(cHandler);
    }


    // ----------------------------------------------------- JMX related methods

    @Override
    protected String getNamePrefix() {
        return ("ajp-nio2");
    }


    // --------------------------------------  AjpConnectionHandler Inner Class

    protected static class AjpConnectionHandler
            extends AbstractAjpConnectionHandler<Nio2Channel>
            implements Handler {

        public AjpConnectionHandler(AjpNio2Protocol proto) {
            super(proto);
        }

        @Override
        protected Log getLog() {
            return log;
        }

        /**
         * Expected to be used by the Poller to release resources on socket
         * close, errors etc.
         */
        @Override
        public void release(SocketWrapperBase<Nio2Channel> socket) {
            Processor processor = connections.remove(socket.getSocket());
            if (processor != null) {
                processor.recycle();
                recycledProcessors.push(processor);
            }
        }

        @Override
        public void release(SocketWrapperBase<Nio2Channel> socket,
                Processor processor, boolean addToPoller) {
            if (getLog().isDebugEnabled()) {
                log.debug("Socket: [" + socket + "], Processor: [" + processor +
                        "], addToPoller: [" + addToPoller + "]");
            }
            processor.recycle();
            recycledProcessors.push(processor);
        }

        @Override
        public void closeAll() {
            for (Nio2Channel channel : connections.keySet()) {
                ((Nio2Endpoint) getProtocol().getEndpoint()).closeSocket(channel.getSocket());
            }
        }
    }
}

@@ -2944,40 +2944,28 @@
     
-if (getLog().isDebugEnab
+processor.recyc
 le
-d
 ()
-) %7B
+;
 %0A   
@@ -2977,49 +2977,16 @@
     
-    log.debug(%22Socket: %5B%22 + socket + %22%5D, 
+recycled
 Proc
@@ -2990,23 +2990,23 @@
 rocessor
-: %5B%22 + 
+s.push(
 processo
@@ -3006,18 +3006,18 @@
 rocessor
- +
+);
 %0A       
@@ -3025,156 +3025,87 @@
     
-            %22%5D, addToPoller: %5B%22 + addToPoller + %22%5D%22);%0A            %7D%0A            processor.recycle();%0A            recycledProcessors.push(processor);
+if (addToPoller) %7B%0A                socket.registerReadInterest();%0A            %7D
 %0A   

Align release() for NIO2 with NIO and APR. - remove (non-i18n) debug message - register for read if necessary (likely to be a NO-OP for NIO2 + AJP)