class DelayedDirtyPageStoreWrite implements PageStoreWriter {
    /** Real flush dirty page implementation. */
    private final PageStoreWriter flushDirtyPage;

    /** Page size. */
    private final int pageSize;

    /** Thread local with byte buffers. */
    private final ThreadLocal<ByteBuffer> byteBufThreadLoc;

    /** Replacing pages tracker, used to register & unregister pages being written. */
    private final DelayedPageReplacementTracker tracker;

    /** Full page id to be written on {@link #finishReplacement()} or null if nothing to write. */
    @Nullable private FullPageId fullPageId;

    /** Byte buffer with page data to be written on {@link #finishReplacement()} or null if nothing to write. */
    @Nullable private ByteBuffer byteBuf;

    /** Partition update tag to be used in{@link #finishReplacement()} or null if -1 to write. */
    private int tag = -1;

    /**
     * @param flushDirtyPage real writer to save page to store.
     * @param byteBufThreadLoc thread local buffers to use for pages copying.
     * @param pageSize page size.
     * @param tracker tracker to lock/unlock page reads.
     */
    public DelayedDirtyPageStoreWrite(
        PageStoreWriter flushDirtyPage,
        ThreadLocal<ByteBuffer> byteBufThreadLoc,
        int pageSize,
        DelayedPageReplacementTracker tracker
    ) {
        this.flushDirtyPage = flushDirtyPage;
        this.pageSize = pageSize;
        this.byteBufThreadLoc = byteBufThreadLoc;
        this.tracker = tracker;
    }

    /** {@inheritDoc} */
    @Override public void writePage(FullPageId fullPageId, ByteBuffer byteBuf, int tag) {
        tracker.lock(fullPageId);

        ByteBuffer tlb = byteBufThreadLoc.get();

        tlb.rewind();

        long writeAddr = GridUnsafe.bufferAddress(tlb);
        long origBufAddr = GridUnsafe.bufferAddress(byteBuf);

        GridUnsafe.copyMemory(origBufAddr, writeAddr, pageSize);

        this.fullPageId = fullPageId;
        this.byteBuf = tlb;
        this.tag = tag;
    }

    /**
     * Runs actual write if required. Method is 'no op' if there was no page selected for replacement.
     * @throws IgniteCheckedException if write failed.
     */
    public void finishReplacement() throws IgniteCheckedException {<FILL_FUNCTION_BODY>}
}

        if (byteBuf == null && fullPageId == null)
            return;

        try {
            flushDirtyPage.writePage(fullPageId, byteBuf, tag);
        }
        finally {
            tracker.unlock(fullPageId);

            fullPageId = null;
            byteBuf = null;
            tag = -1;
        }
    
<no_super_class>