class ContractCheckingIndexProxy extends DelegatingIndexProxy {

    @Override
    public void close() throws IOException
    {
        if ( state.compareAndSet( State.INIT, State.CLOSED ) )
        {
            super.close();
            return;
        }

        if ( state.compareAndSet( State.STARTING, State.CLOSED ) )
        {
            throw new IllegalStateException( "Concurrent close while creating index" );
        }

        if ( state.compareAndSet( State.STARTED, State.CLOSED ) )
        {
            waitOpenCallsToClose();
            super.close();
            return;
        }

        throw new IllegalStateException( "IndexProxy already closed" );
    }

    public  ContractCheckingIndexProxy( IndexProxy delegate, boolean started );

}