Class PartedLogger<T, P extends T>

java.lang.Object
org.refcodes.logger.PartedLogger<T,P>
Type Parameters:
T - the generic type
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>, Disposable, Resetable

public class PartedLogger<T, P extends T> extends Object implements ComponentComposite
The PartedLogger is a ready to use implementation of a parted Logger extending the AbstractPartedLogger.
See Also:
  • Constructor Details

    • PartedLogger

      public PartedLogger(Column<P> aPartitionColumn, LoggerFactory<Logger<T>> aLoggerFactory, boolean isPartitionAutoInitialize)
      Instantiates a new PartedLogger 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.
    • PartedLogger

      public PartedLogger(Column<P> aPartitionColumn, String aDefaultLoggerName, LoggerFactory<Logger<T>> aLoggerFactory, boolean isPartitionAutoInitialize)
      Instantiates a new PartedLogger 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.
    • PartedLogger

      public PartedLogger(ExecutionStrategy aComponentExecutionStrategy, Column<P> aPartitionColumn, LoggerFactory<Logger<T>> aLoggerFactory, boolean isPartitionAutoInitialize)
      Similar to the PartedLogger(Column, LoggerFactory, boolean) with the additional option of determining the execution strategy of the state change request calls for the encapsulated Logger instances (as of ComponentComposite).
      Parameters:
      aComponentExecutionStrategy - The strategy to be used when invoking a component's (encapsulated Logger 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
    • PartedLogger

      public PartedLogger(ExecutionStrategy aComponentExecutionStrategy, Column<P> aPartitionColumn, String aDefaultLoggerName, LoggerFactory<Logger<T>> aLoggerFactory, boolean isPartitionAutoInitialize)
      Similar to the PartedLogger(Column, LoggerFactory, boolean) with the additional option of determining the execution strategy of the state change request calls for the encapsulated Logger instances (as of ComponentComposite).
      Parameters:
      aComponentExecutionStrategy - The strategy to be used when invoking a component's (encapsulated Logger 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()
      Specified by:
      close in interface Closable
    • dispose

      public void dispose()
      Specified by:
      dispose in interface Disposable
    • 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 Logger<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<Logger<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 Logger<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 Logger<T> getFallbackLogger()
      Returns the fallback Logger.
      Returns:
      The fallback logger or null if none was enabled.