/*
 * Copyright 2020, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.server.storage;

import com.google.protobuf.Message;
import io.spine.annotation.SPI;

import java.util.Iterator;
import java.util.Optional;

/**
 * The base interface for storages.
 *
 * @param <I> the type of identifiers
 * @param <M> the type of records
 */
@SPI
public interface Storage<I, M extends Message> extends AutoCloseable {

    /**
     * Verifies whether the storage is multitenant.
     *
     * @return {@code true} if the storage was created with multitenancy support,
     *         {@code false} otherwise
     */
    boolean isMultitenant();

    /**
     * Returns an iterator over identifiers of records in the storage.
     */
    Iterator<I> index();

    /**
     * Reads a record from the storage by the specified record identifier.
     *
     * @param id the identifier  to read the record
     * @return a record instance
     *         or {@code Optional.empty()} if there is no record matching this request
     * @throws IllegalStateException if the storage was closed before
     */
    Optional<M> read(I id);

    /**
     * Writes a record into the storage.
     *
     * <p>Rewrites it if a record with this ID already exists in the storage.
     *
     * @param id     the ID for the record
     * @param record the record to store
     * @throws IllegalStateException if the storage is closed
     */
    void write(I id, M record);

    /**
     * Closes the storage.
     *
     * <p>Implementations may throw specific exceptions.
     */
    @Override
    void close();

    /**
     * Verifies whether the storage is open.
     *
     * @return {@code true} if the storage is open, {@code false} otherwise
     */
    boolean isOpen();
}

@@ -1220,16 +1220,27 @@
 aram %3CI%3E
+%0A *        
  the typ
@@ -1269,16 +1269,27 @@
 aram %3CM%3E
+%0A *        
  the typ
@@ -1827,16 +1827,31 @@
 param id
+%0A     *        
  the ide
@@ -1862,16 +1862,10 @@
 ier 
- to read
+of
  the
@@ -1863,32 +1863,40 @@
 er of the record
+ to read
 %0A     * @return 
@@ -2028,32 +2028,47 @@
 alStateException
+%0A     *        
  if the storage 
@@ -2279,16 +2279,27 @@
 param id
+%0A     *    
      the
@@ -2337,16 +2337,31 @@
 m record
+%0A     *        
  the rec
@@ -2409,16 +2409,31 @@
 xception
+%0A     *        
  if the 

Format the code.