Class PersistenceBackend
- java.lang.Object
-
- org.gcube.documentstore.persistence.PersistenceBackend
-
- Direct Known Subclasses:
FallbackPersistenceBackend
public abstract class PersistenceBackend extends Object
- Author:
- Luca Frosini (ISTI - CNR), Alessandro Pieve (ISTI - CNR)
-
-
Field Summary
Fields Modifier and Type Field Description protected AggregationScheduleraggregationSchedulerprotected FallbackPersistenceBackendfallbackPersistenceprotected intfallbackUseCounterprotected longfallbackUseStartTimeprotected booleanforceFallbackUsestatic intMAX_FALLBACK_RETRYMax Times of Retry before forcing the usage of FallbackPersistenceBackendstatic longMAX_TIME_TO_FALLBACKMax Time Period Used during while the usage of FallbackPersistenceBackend is forcedprotected FallbackMonitorpersistenceBackendMonitor
-
Constructor Summary
Constructors Modifier Constructor Description protectedPersistenceBackend()protectedPersistenceBackend(FallbackPersistenceBackend fallback)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccount(Record record)Persist the Record.protected voidaccountValidateAggregate(Record record, boolean validate, boolean aggregate)protected voidaccountWithFallback(Record... records)protected abstract voidclean()This method is used to allow PersistenceBackend implementations to clean a global status if any (or to renew it) when to much exceptions occurs trying to persist Records.voidclose()This method is used to closeprotected abstract voidcloseConnection()This method is used to close db connectionvoidflush()voidflush(long timeout, TimeUnit timeUnit)Deprecated.AggregationSchedulergetAggregationScheduler()FallbackPersistenceBackendgetFallbackPersistence()abstract booleanisConnectionActive()Check the Connection stateprotected abstract voidopenConnection()This method is used to open db connectionprotected abstract voidprepareConnection(PersistenceBackendConfiguration configuration)Prepare the connection to persistence.protected abstract voidreallyAccount(Record record)This method contains the code to save theRecordprotected voidsetAggregationScheduler(AggregationScheduler aggregationScheduler)protected voidsetFallback(FallbackPersistenceBackend fallback)
-
-
-
Field Detail
-
MAX_TIME_TO_FALLBACK
public static final long MAX_TIME_TO_FALLBACK
Max Time Period Used during while the usage of FallbackPersistenceBackend is forced- See Also:
- Constant Field Values
-
MAX_FALLBACK_RETRY
public static final int MAX_FALLBACK_RETRY
Max Times of Retry before forcing the usage of FallbackPersistenceBackend- See Also:
- Constant Field Values
-
forceFallbackUse
protected boolean forceFallbackUse
-
fallbackUseCounter
protected int fallbackUseCounter
-
fallbackUseStartTime
protected long fallbackUseStartTime
-
fallbackPersistence
protected FallbackPersistenceBackend fallbackPersistence
-
aggregationScheduler
protected AggregationScheduler aggregationScheduler
-
persistenceBackendMonitor
protected FallbackMonitor persistenceBackendMonitor
-
-
Constructor Detail
-
PersistenceBackend
protected PersistenceBackend()
-
PersistenceBackend
protected PersistenceBackend(FallbackPersistenceBackend fallback)
-
-
Method Detail
-
getFallbackPersistence
public FallbackPersistenceBackend getFallbackPersistence()
- Returns:
- the fallbackPersistence
-
setFallback
protected void setFallback(FallbackPersistenceBackend fallback)
- Parameters:
fallback- the fallback to set
-
getAggregationScheduler
public AggregationScheduler getAggregationScheduler()
- Returns:
- the aggregationScheduler
-
setAggregationScheduler
protected void setAggregationScheduler(AggregationScheduler aggregationScheduler)
- Parameters:
aggregationScheduler- the aggregationScheduler to set
-
prepareConnection
protected abstract void prepareConnection(PersistenceBackendConfiguration configuration) throws Exception
Prepare the connection to persistence. This method must be used by implementation class to prepare the connection with the persistence storage, DB, file etc.- Parameters:
configuration- The configuration to create the connection- Throws:
Exception- if fails
-
openConnection
protected abstract void openConnection() throws ExceptionThis method is used to open db connection- Throws:
Exception
-
closeConnection
protected abstract void closeConnection() throws ExceptionThis method is used to close db connection- Throws:
Exception
-
clean
protected abstract void clean() throws ExceptionThis method is used to allow PersistenceBackend implementations to clean a global status if any (or to renew it) when to much exceptions occurs trying to persist Records.- Throws:
Exception
-
isConnectionActive
public abstract boolean isConnectionActive() throws ExceptionCheck the Connection state- Returns:
- true if the connection is active, false otherwise
- Throws:
Exception
-
reallyAccount
protected abstract void reallyAccount(Record record) throws Exception
This method contains the code to save theRecord- Throws:
Exception
-
accountWithFallback
protected void accountWithFallback(Record... records) throws Exception
- Parameters:
records-- Throws:
Exception
-
accountValidateAggregate
protected void accountValidateAggregate(Record record, boolean validate, boolean aggregate)
- Parameters:
record-validate-aggregate-
-
account
public void account(Record record) throws InvalidValueException
Persist the Record. The Record is validated first, then accounted, in a separated thread. So that the program can continue the execution. If the persistence fails the class write that the record in a local file so that the Record can be recorder later.- Parameters:
record- the Record to persist- Throws:
InvalidValueException- if the Record Validation Fails
-
flush
@Deprecated public void flush(long timeout, TimeUnit timeUnit) throws Exception
Deprecated.Useflush()instead- Parameters:
timeout-timeUnit-- Throws:
Exception
-
-