Class PartedTrimLogger<T, P extends T>

java.lang.Object
org.refcodes.logger.PartedTrimLogger<T,P>
Type Parameters:
T - The type of the Record instances managed by the Logger.
P - The type of the Column's value used for partitioning the Logger.
All Implemented Interfaces:
Flushable, Closable, ComponentComposite, Decomposable, Destroyable, Flushable, Initializable, LifecycleComponent, LinkComponent, Openable, Pausable, Resumable, Startable, Stoppable, LogDecorator, Logger<T>, QueryLogger<T>, TrimLogger<T>, Clearable, Disposable, Resetable

public class PartedTrimLogger<T, P extends T> extends Object implements ComponentComposite
The PartedTrimLogger is a ready to use implementation of a parted TrimLogger extending the AbstractPartedTrimLogger.
  • Constructor Details

    • PartedTrimLogger

      public PartedTrimLogger(Column<P> aPartitionColumn, LoggerFactory<TrimLogger<T>> aLoggerFactory, boolean isPartitionAutoInitialize)
      Instantiates a new PartedTrimLogger with the according parameters.
      Parameters:
      aPartitionColumn - the Column identifying partition column for sharding.
      aLoggerFactory - the LoggerFactory populating this composite with partitions.
      isPartitionAutoInitialize - True in case a partition not yet existing is to be created on the fly, e.g. in case a log is applied against a non existing partition, then the initPartition(Object) method is invoked upon this partition. Find and delete operations are not considered.
    • PartedTrimLogger

      public PartedTrimLogger(Column<P> aPartitionColumn, String aDefaultLoggerName, LoggerFactory<TrimLogger<T>> aLoggerFactory, boolean isPartitionAutoInitialize)
      Instantiates a new PartedTrimLogger with the according parameters.
      Parameters:
      aPartitionColumn - the Column identifying partition column for sharding.
      aDefaultLoggerName - In case a fallback Logger is to be used when no partition can be determined, then this parameter defines the name of the fallback Logger.
      aLoggerFactory - the LoggerFactory populating this composite with partitions.
      isPartitionAutoInitialize - True in case a partition not yet existing is to be created on the fly, e.g. in case a log is applied against a non existing partition, then the initPartition(Object) method is invoked upon this partition. Find and delete operations are not considered.
    • PartedTrimLogger

      public PartedTrimLogger(ExecutionStrategy aComponentExecutionStrategy, Column<P> aPartitionColumn, LoggerFactory<TrimLogger<T>> aLoggerFactory, boolean isPartitionAutoInitialize)
      Similar to the PartedTrimLogger(Column, LoggerFactory, boolean) constructor with the additional option of determining the execution strategy of the state change request calls for the encapsulated TrimLogger instances (as of ComponentComposite).
      Parameters:
      aComponentExecutionStrategy - The strategy to be used when invoking a component's (encapsulated TrimLogger instance's) state change request call (as of ComponentComposite).
      aPartitionColumn - the Column identifying partition column for sharding.
      aLoggerFactory - the LoggerFactory populating this composite with partitions.
      isPartitionAutoInitialize - the is partition auto initialize
    • PartedTrimLogger

      public PartedTrimLogger(ExecutionStrategy aComponentExecutionStrategy, Column<P> aPartitionColumn, String aDefaultLoggerName, LoggerFactory<TrimLogger<T>> aLoggerFactory, boolean isPartitionAutoInitialize)
      Similar to the PartedTrimLogger(Column, LoggerFactory, boolean) constructor with the additional option of determining the execution strategy of the state change request calls for the encapsulated TrimLogger instances (as of ComponentComposite).
      Parameters:
      aComponentExecutionStrategy - The strategy to be used when invoking a component's (encapsulated TrimLogger instance's) state change request call (as of ComponentComposite).
      aPartitionColumn - the Column identifying partition column for sharding.
      aDefaultLoggerName - In case a fallback Logger is to be used when no partition can be determined, then this parameter defines the name of the fallback Logger.
      aLoggerFactory - the LoggerFactory populating this composite with partitions.
      isPartitionAutoInitialize - the is partition auto initialize
  • Method Details

    • initialize

      public void initialize() throws InitializeException
      Specified by:
      initialize in interface Initializable
      Throws:
      InitializeException
    • start

      public void start() throws StartException
      Specified by:
      start in interface Startable
      Throws:
      StartException
    • pause

      public void pause() throws PauseException
      Specified by:
      pause in interface Pausable
      Throws:
      PauseException
    • resume

      public void resume() throws ResumeException
      Specified by:
      resume in interface Resumable
      Throws:
      ResumeException
    • stop

      public void stop() throws StopException
      Specified by:
      stop in interface Stoppable
      Throws:
      StopException
    • decompose

      public void decompose()
      Specified by:
      decompose in interface Decomposable
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in interface Flushable
      Throws:
      IOException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface Destroyable
    • reset

      public void reset()
      Specified by:
      reset in interface Resetable
    • open

      public void open() throws IOException
      Specified by:
      open in interface Openable
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface Closable
      Throws:
      IOException
    • dispose

      public void dispose()
      Specified by:
      dispose in interface Disposable
    • deleteLogs

      public void deleteLogs(Criteria aCriteria) throws BadCriteriaException
      Deletes logged Record instances according to the provided Criteria.
      Specified by:
      deleteLogs in interface TrimLogger<L extends TrimLogger<T>>
      Parameters:
      aCriteria - The Criteria to be applied when deleting previously logged Record instances.
      Throws:
      BadCriteriaException - thrown in case of problems related to some Criteria.
    • clear

      public void clear()
      Specified by:
      clear in interface Clearable
    • findLogs

      public Records<T> findLogs()
      Retrieves all available Record instances being logged.
      Specified by:
      findLogs in interface QueryLogger<L extends QueryLogger<T>>
      Returns:
      A Records instance containing all available Record instances being logged.
    • findLogs

      public Records<T> findLogs(int aLimit)
      Retrieves all available Record instances being logged matching the given criteria and restrictions.
      Specified by:
      findLogs in interface QueryLogger<L extends QueryLogger<T>>
      Parameters:
      aLimit - The maximum Record instances contained in the returned Records instance; there may be more Record instances which are not contained in the Records instance in case the Records instance's size is that of the specified limit.
      Returns:
      A Records instance containing all available Record instances being logged matching the given criteria and restrictions.
    • findLogs

      public Records<T> findLogs(Criteria aCriteria)
      Retrieves all available Record instances being logged matching the given criteria and restrictions.
      Specified by:
      findLogs in interface QueryLogger<L extends QueryLogger<T>>
      Parameters:
      aCriteria - The Criteria to be applied to the Record instances
      Returns:
      A Records instance containing all available Record instances being logged matching the given criteria and restrictions.
    • findLogs

      public Records<T> findLogs(Header<T> aHeader, int aLimit)
      Retrieves all available Record instances being logged matching the given criteria and restrictions.
      Specified by:
      findLogs in interface QueryLogger<L extends QueryLogger<T>>
      Parameters:
      aHeader - The Header used to restrict the "columns" (key/value entries) in the retrieved Record instances (provided by the Records instance).
      aLimit - The maximum Record instances contained in the returned Records instance; there may be more Record instances which are not contained in the Records instance in case the Records instance's size is that of the specified limit.
      Returns:
      A Records instance containing all available Record instances being logged matching the given criteria and restrictions.
    • findLogs

      public Records<T> findLogs(Criteria aCriteria, int aLimit) throws BadCriteriaException
      Retrieves all available Record instances being logged matching the given criteria and restrictions.
      Specified by:
      findLogs in interface QueryLogger<L extends QueryLogger<T>>
      Parameters:
      aCriteria - The Criteria to be applied to the Record instances
      aLimit - The maximum Record instances contained in the returned Records instance; there may be more Record instances which are not contained in the Records instance in case the Records instance's size is that of the specified limit.
      Returns:
      A Records instance containing all available Record instances being logged matching the given criteria and restrictions.
      Throws:
      BadCriteriaException - thrown in case of problems related to some Criteria.
    • findLogs

      public Records<T> findLogs(Criteria aCriteria, Header<T> aHeader) throws BadCriteriaException
      Retrieves all available Record instances being logged matching the given criteria and restrictions.
      Specified by:
      findLogs in interface QueryLogger<L extends QueryLogger<T>>
      Parameters:
      aCriteria - The Criteria to be applied to the Record instances
      aHeader - The Header used to restrict the "columns" (key/value entries) in the retrieved Record instances (provided by the Records instance).
      Returns:
      A Records instance containing all available Record instances being logged matching the given criteria and restrictions.
      Throws:
      BadCriteriaException - thrown in case of problems related to some Criteria.
    • findLogs

      public Records<T> findLogs(Criteria aCriteria, Header<T> aHeader, int aLimit) throws BadCriteriaException
      Retrieves all available Record instances being logged matching the given criteria and restrictions.
      Specified by:
      findLogs in interface QueryLogger<L extends QueryLogger<T>>
      Parameters:
      aCriteria - The Criteria to be applied to the Record instances
      aHeader - The Header used to restrict the "columns" (key/value entries) in the retrieved Record instances (provided by the Records instance).
      aLimit - The maximum Record instances contained in the returned Records instance; there may be more Record instances which are not contained in the Records instance in case the Records instance's size is that of the specified limit.
      Returns:
      A Records instance containing all available Record instances being logged matching the given criteria and restrictions.
      Throws:
      BadCriteriaException - thrown in case of problems related to some Criteria.
    • getPartitionLoggers

      protected Collection<TrimLogger<T>> getPartitionLoggers(Set<P> aPartitions)
      Retrieves a collection with Logger instances managing the provided partitions.
      Parameters:
      aPartitions - The partitions for which to get the Logger instances.
      Returns:
      A Collection with none to many Logger instances
    • log

      public void log(Record<? extends T> aRecord)
      Logs a Record. The targeted data sink for the Record instances (where them are physically stored) depends on the implementation of the Logger. It can be a console, a file, a stream or a database.
      Specified by:
      log in interface Logger<L extends Logger<T>>
      Parameters:
      aRecord - The Record to be logged.
    • hasPartition

      public boolean hasPartition(P aPartition)
      Tests whether the provided partition exists.
      Parameters:
      aPartition - The value of the Column in a Record specifying the partition which is to be addressed (or even auto initialized).
      Returns:
      True in case the partition exists, else false.
    • initPartition

      public TrimLogger<T> initPartition(P aPartition) throws InitializeException
      Initializes the given partition.
      Parameters:
      aPartition - The value of the Column in a Record specifying the partition which is to be auto initialized.
      Returns:
      the l
      Throws:
      InitializeException - in case initialization failed e.g. when the partition already exists or the system was not able to create the required amount of endpoints.
    • destroyPartition

      public void destroyPartition(P aPartition)
      Destroys the given partition. External resources might stay untouched! In case the partition does not exist, then there is no partition to be destroyed. To make things easier, this is not considered an exceptional state as after the call we expect that there is none such partition (any more) which is not destroyed.
      Parameters:
      aPartition - the partition
    • flushPartition

      public void flushPartition(P aPartition) throws IOException
      Flushes the given partition, all buffered data is to be forwarded to the physical data sink.
      Parameters:
      aPartition - The partition to be flushed.
      Throws:
      IOException - in case there were problems when flushing, e.g. there is none such partition.
    • decomposePartition

      public void decomposePartition(P aPartition)
      Decomposes the given partition. External resources might get deleted (such as files or DB schemas)! In case the partition does not exist, then there is no partition to be decomposed. To make things easier, this is not considered an exceptional state as after the call we expect that there is none such partition (any more).
      Parameters:
      aPartition - The partition to be decomposed.
    • getLoggers

      protected Collection<TrimLogger<T>> getLoggers()
      Provides access to the partitions managed by the AbstractPartedLogger. This is ehttps://www.metacodes.proly useful for extensions of this class such as the AbstractPartedQueryLogger or the AbstractPartedTrimLogger.
      Returns:
      The Logger instances managed by the AbstractPartedLogger instance.
    • getPartitionUid

      protected String getPartitionUid(P aPartition)
      Depending whether the partition object provides a Universal-TID or not we return the string representation of the partition's object or the UID.
      Parameters:
      aPartition - The partition for which to get the identifier
      Returns:
      The UID in case the partition provides a UID, else the partition's string representation.
    • getPartitionColumn

      protected Column<P> getPartitionColumn()
      Provides access to the Column used to identify partitions.
      Returns:
      The Column identifying partitions.
    • getPartitionLogger

      protected TrimLogger<T> getPartitionLogger(P aPartition)
      Returns the Logger being responsible for the given partition.
      Parameters:
      aPartition - The partition for which to get the responsible Logger.
      Returns:
      The Logger responsible for the given partition or null if none was found for the partition.
    • getFallbackLogger

      protected TrimLogger<T> getFallbackLogger()
      Returns the fallback Logger.
      Returns:
      The fallback logger or null if none was enabled.