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 containsentitiesthat 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)andinTransaction(Supplier)An alternative way of using transactions is provided via
inTransaction(Runnable)andinTransaction(Supplier). These will take care of committing and rolling back a transaction.Examples:
silo.inTransaction(() -> { entity.store("test id", object); });- Author:
- Andreas Holstenson
-
-
Method Summary
Modifier and Type Method Description ResourceHandleacquireResourceHandle()Acquire a new resource lock for the current thread.BinaryEntitybinary(String entityName)Get access to the binary entity with the given name.voidclose()<T> Tcreate(Class<T> siloInterface)Create a new instance of the specified interface for usage with the storage.<T extends Entity>
Tentity(String entityName, Class<T> type)Get an entity of the given type.booleanhasEntity(String entityName)Check if the given entity is available.default voidinTransaction(Runnable runnable)Run the givenRunnablein a transaction.default <T> TinTransaction(Supplier<T> supplier)Run the givenSupplierin a transaction.TransactionnewTransaction()Create a new transaction for the current thread.StructuredEntitystructured(String entityName)Get an entity used for storing structured data with the given name.
-
-
-
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 givenSupplierin a transaction.- Parameters:
supplier-- Returns:
-
inTransaction
default void inTransaction(Runnable runnable)
Run the givenRunnablein a transaction.- Parameters:
runnable-
-
close
void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-