/*
 * Copyright 2014-2017 Real Logic Ltd.
 *
 * 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.aeron.logbuffer;

import org.agrona.concurrent.UnsafeBuffer;

import static io.aeron.logbuffer.LogBufferDescriptor.*;

/**
 * Provides the functionality to unblock a log at a given position.
 */
public class LogBufferUnblocker
{
    /**
     * Attempt to unblock a log buffer at given position
     *
     * @param termBuffers       for current blockedOffset
     * @param logMetaDataBuffer for log buffer
     * @param blockedPosition   to attempt to unblock
     * @return whether unblocked or not
     */
    public static boolean unblock(
        final UnsafeBuffer[] termBuffers, final UnsafeBuffer logMetaDataBuffer, final long blockedPosition)
    {
        final int termLength = termBuffers[0].capacity();
        final int positionBitsToShift = Integer.numberOfTrailingZeros(termLength);
        final int activeTermCount = activeTermCount(logMetaDataBuffer);
        final int expectedTermCount = (int)(blockedPosition >> positionBitsToShift);
        final int index = indexByTermCount(activeTermCount);
        final long rawTail = rawTailVolatile(logMetaDataBuffer, index);
        final int termId = termId(rawTail);

        if (activeTermCount == (expectedTermCount - 1) && 0 == (blockedPosition & (termLength - 1)))
        {
            return rotateLog(logMetaDataBuffer, activeTermCount, termId);
        }

        final UnsafeBuffer termBuffer = termBuffers[index];
        final int tailOffset = termOffset(rawTail, termLength);
        final int blockedOffset = computeTermOffsetFromPosition(blockedPosition, positionBitsToShift);

        switch (TermUnblocker.unblock(logMetaDataBuffer, termBuffer, blockedOffset, tailOffset, termId))
        {
            case UNBLOCKED_TO_END:
                final int termCount = (int)(blockedPosition >> positionBitsToShift);
                rotateLog(logMetaDataBuffer, termCount, termId);
                // fall through
            case UNBLOCKED:
                return true;
        }

        return false;
    }
}

@@ -2315,93 +2315,8 @@
 ND:%0A
-                final int termCount = (int)(blockedPosition %3E%3E positionBitsToShift);%0A
     
@@ -2356,17 +2356,23 @@
 Buffer, 
-t
+activeT
 ermCount

Remove repeated code.