Package se.l4.silo

Interface Silo

  • All Superinterfaces:
    AutoCloseable, Closeable

    public interface Silo
    extends Closeable
    Silo storage, provides access to all entities stored, transactions and resource management. An instance of this class contains entities that can be used to store and retrieve data.

    Transactions

    Silo provides transaction support. In normal usage every write operation is a tiny transaction, so a store operation will internally be mapped against a transaction. Transactions in Silo are implemented so that they become readable when they are committed, so any changes made in a transaction are not visible either within our outside the transaction.

    Using newTransaction()

    When newTransaction() is called a transaction is activated for the current thread. Transactions must either be committed or rolled back when they are used.

    Example:

     Transaction tx = silo.newTransaction();
     try {
       // Perform operations as usual here
       entity.store("test id", object);
    
       tx.commit();
     } catch(Throwable t) {
       tx.rollback();
     }
     

    Using inTransaction(Runnable) and inTransaction(Supplier)

    An alternative way of using transactions is provided via inTransaction(Runnable) and inTransaction(Supplier). These will take care of committing and rolling back a transaction.

    Examples:

     silo.inTransaction(() -> {
       entity.store("test id", object);
     });
     
    Author:
    Andreas Holstenson
    • Method Detail

      • create

        <T> T create​(Class<T> siloInterface)
        Create a new instance of the specified interface for usage with the storage.
        Parameters:
        siloInterface -
        Returns:
      • hasEntity

        boolean hasEntity​(String entityName)
        Check if the given entity is available.
        Parameters:
        entityName -
        Returns:
      • entity

        <T extends Entity> T entity​(String entityName,
                                    Class<T> type)
        Get an entity of the given type.
        Parameters:
        entityName -
        type -
      • binary

        BinaryEntity binary​(String entityName)
        Get access to the binary entity with the given name.
        Parameters:
        entityName -
        Returns:
      • structured

        StructuredEntity structured​(String entityName)
        Get an entity used for storing structured data with the given name.
        Parameters:
        entityName -
        Returns:
      • newTransaction

        Transaction newTransaction()
        Create a new transaction for the current thread.
        Returns:
      • acquireResourceHandle

        ResourceHandle acquireResourceHandle()
        Acquire a new resource lock for the current thread.
        Returns:
      • inTransaction

        default <T> T inTransaction​(Supplier<T> supplier)
        Run the given Supplier in a transaction.
        Parameters:
        supplier -
        Returns:
      • inTransaction

        default void inTransaction​(Runnable runnable)
        Run the given Runnable in a transaction.
        Parameters:
        runnable -