Class AggregationScheduler
java.lang.Object
org.gcube.documentstore.records.aggregation.AggregationScheduler
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
BufferAggregationScheduler
- Author:
- Luca Frosini (ISTI - CNR)
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Filestatic final Stringstatic final Stringstatic final Stringbooleanstatic final Stringstatic final Stringprotected ScheduledFuture<?>protected ScheduledFuture<?>static final org.slf4j.Loggerprotected final PersistenceExecutorstatic final intstatic final longThe Max amount of time for reload a configuration Get from configurationprotected int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAggregationScheduler(PersistenceExecutor persistenceExecutor) protectedAggregationScheduler(PersistenceExecutor persistenceExecutor, AggregationConfiguration config) -
Method Summary
Modifier and TypeMethodDescriptionvoidaggregate(Record record, PersistenceExecutor persistenceExecutor) Get a record and try to aggregate with other buffered Records.protected voidaggregate(Record record, PersistenceExecutor persistenceExecutor, boolean forceFlush) Aggregates the record, if any, and persists the buffered records when it is time to, or when forced.protected static AggregationConfigurationCheckConfiguration(PersistenceBackendConfiguration configuration) protected voidclear()voidflush(PersistenceExecutor persistenceExecutor) voidflushAfterWaiting(PersistenceExecutor persistenceExecutor, long timeout, TimeUnit timeUnit) Persists the buffered records with the given executor after waiting, at most for the given time, for the persistence in progress, if any.static AggregatedRecordgetAggregatedRecord(Record record) protected PersistenceBackendConfigurationGet Configuration (used from reload configuration)static Propertiesprotected static AggregatedRecordinstantiateAggregatedRecord(Record record) protected abstract booleanisTimeToPersist(int maxRecordNumber, long oldRecordMaxTime) protected voidmadeAggregation(Record record) static AggregationSchedulernewInstance(PersistenceExecutor persistenceExecutor) static AggregationSchedulernewInstance(PersistenceExecutor persistenceExecutor, PersistenceBackendConfiguration configuration) protected voidpersist(PersistenceExecutor persistenceExecutor, Record[] recordsToPersist) Persists the records, one persistence at a time for this scheduler.protected voidreallyFlush(PersistenceExecutor persistenceExecutor) protected voidreloadConfigurationvoidrun()protected abstract voidvoidsetConfig(AggregationConfiguration newConfig) voidshutdown()protected Record[]Takes the buffered records out of the buffer.
-
Field Details
-
logger
public static final org.slf4j.Logger logger -
AGGREGATION_SCHEDULER_TIME
- See Also:
-
BUFFER_RECORD_TIME
- See Also:
-
BUFFER_RECORD_NUMBER
- See Also:
-
RANDOM_INIT_START
public static final int RANDOM_INIT_START- See Also:
-
TIME_RELOAD_CONFIGURATION
public static final long TIME_RELOAD_CONFIGURATIONThe Max amount of time for reload a configuration Get from configuration- See Also:
-
CONFIG_DIRECTORY_NAME
- See Also:
-
FILE_NAME
- See Also:
-
AGGREGATION_PROPERTIES_FILE
-
totalBufferedRecords
protected int totalBufferedRecords -
bufferedRecords
-
persistenceExecutor
-
changeConfiguration
public boolean changeConfiguration -
futureFlush
-
futureReload
-
-
Constructor Details
-
AggregationScheduler
-
AggregationScheduler
protected AggregationScheduler(PersistenceExecutor persistenceExecutor, AggregationConfiguration config)
-
-
Method Details
-
newInstance
-
newInstance
public static AggregationScheduler newInstance(PersistenceExecutor persistenceExecutor, PersistenceBackendConfiguration configuration) throws NumberFormatException, Exception - Throws:
NumberFormatExceptionException
-
instantiateAggregatedRecord
- Throws:
Exception
-
getAggregatedRecord
- Throws:
Exception
-
madeAggregation
-
flush
- Throws:
Exception
-
schedulerSpecificClear
protected abstract void schedulerSpecificClear() -
clear
protected void clear() -
aggregate
protected void aggregate(Record record, PersistenceExecutor persistenceExecutor, boolean forceFlush) throws Exception Aggregates the record, if any, and persists the buffered records when it is time to, or when forced. The buffer is taken under this scheduler's lock, and persisted outside it: a slow persistence does not block the aggregation of the incoming records.- Parameters:
record- the record to aggregate, ornullto only check whether to persistpersistenceExecutor- the executor persisting the recordsforceFlush- whether to persist the buffered records in any case- Throws:
Exception- if the persistence fails; the records are then buffered again
-
takeBufferedRecords
Takes the buffered records out of the buffer.- Returns:
- the buffered records, or
nullif the buffer is empty
-
persist
protected void persist(PersistenceExecutor persistenceExecutor, Record[] recordsToPersist) throws Exception Persists the records, one persistence at a time for this scheduler. If the persistence fails, the records are buffered again, so that the next flush retries them.- Parameters:
persistenceExecutor- the executor persisting the recordsrecordsToPersist- the records- Throws:
Exception- if the persistence fails
-
flushAfterWaiting
public void flushAfterWaiting(PersistenceExecutor persistenceExecutor, long timeout, TimeUnit timeUnit) throws Exception Persists the buffered records with the given executor after waiting, at most for the given time, for the persistence in progress, if any. Meant for a local executor at shutdown, e.g. the fallback file: the persistence in progress gets a chance to complete, or to put its records back into the buffer; if it does not complete in time, its outcome is unknown and the buffered records are persisted anyway.- Parameters:
persistenceExecutor- the executor persisting the recordstimeout- the maximum time to wait for the persistence in progresstimeUnit- the unit of the timeout- Throws:
Exception- if the persistence fails
-
reallyFlush
- Throws:
Exception
-
aggregate
Get a record and try to aggregate with other buffered Records.- Parameters:
record- The RecordpersistenceExecutor-- Throws:
Exception
-
isTimeToPersist
protected abstract boolean isTimeToPersist(int maxRecordNumber, long oldRecordMaxTime) -
reloadConfiguration
protected void reloadConfiguration()reloadConfiguration -
getConfiguration
Get Configuration (used from reload configuration)- Returns:
- PersistenceBackendConfiguration
-
getPropertiesFromFile
- Throws:
IOException
-
CheckConfiguration
protected static AggregationConfiguration CheckConfiguration(PersistenceBackendConfiguration configuration) throws IOException - Throws:
IOException
-
getConfig
-
setConfig
-
run
public void run() -
shutdown
public void shutdown()
-