Class SimpleDbLoggerImpl<T>

  • Type Parameters:
    T - The type of the Record instances managed by the Logger.
    All Implemented Interfaces:
    java.io.Flushable, org.refcodes.component.Component, org.refcodes.component.Decomposeable, org.refcodes.component.Destroyable, org.refcodes.component.Flushable, org.refcodes.component.Initializable, org.refcodes.logger.Logger<T>
    Direct Known Subclasses:
    SimpleDbQueryLoggerImpl

    public class SimpleDbLoggerImpl<T>
    extends java.lang.Object
    implements org.refcodes.logger.Logger<T>, org.refcodes.component.Component, org.refcodes.component.Initializable, org.refcodes.component.Decomposeable, org.refcodes.component.Flushable
    The SimpleDbLoggerImpl is the Amazon SimpleDB implementation of the Logger interface. As Amazon SimpleDB stores only String values (everything is a String), type information may be lost as inferencing from the String content may not be possible. The Record instances Column.toStorageString(Object) and Column.fromStorageString(String) methods are used to apply conversion.

    ATTENTION: Logging field values exceeding the size of 1024 characters will be truncated and an error message is logged out. We assume not having fields longer than 1024 bytes with this implementation of the Logger.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.refcodes.component.Decomposeable

        org.refcodes.component.Decomposeable.DecomposeAutomaton
      • Nested classes/interfaces inherited from interface org.refcodes.component.Destroyable

        org.refcodes.component.Destroyable.DestroyAutomaton
      • Nested classes/interfaces inherited from interface org.refcodes.component.Flushable

        org.refcodes.component.Flushable.FlushBuilder<B extends org.refcodes.component.Flushable.FlushBuilder<B>>
      • Nested classes/interfaces inherited from interface org.refcodes.component.Initializable

        org.refcodes.component.Initializable.InitializeAutomaton, org.refcodes.component.Initializable.InitializeBuilder<B extends org.refcodes.component.Initializable.InitializeBuilder<B>>, org.refcodes.component.Initializable.UncheckedInitializable
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static org.refcodes.logger.RuntimeLogger LOGGER  
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleDbLoggerImpl​(java.lang.String aDomainName, java.lang.String aAccessKey, java.lang.String aSecretKey, java.lang.String aEndPoint, org.refcodes.tabular.ColumnFactory<T> aColumnFactory)
      Constructs the SimpleDbLoggerImpl for a given SimpleDB domain.
      SimpleDbLoggerImpl​(java.lang.String aDomainName, java.lang.String aAccessKey, java.lang.String aSecretKey, org.refcodes.tabular.ColumnFactory<T> aColumnFactory)
      Constructs the SimpleDbLoggerImpl for a given SimpleDB domain.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addHeaderColumn​(java.lang.String eKey)
      Adds a key to the dynamically created Header for reducing object creation overhead when massively logging data as no Column instances are created once the key was already added.
      protected static void clearDomain​(com.amazonaws.services.simpledb.AmazonSimpleDB aAmazonSimpleDbClient, java.lang.String aDomainName)
      Clears all content from the given Amazon SimpleDB domain.
      void decompose()
      void destroy()
      void flush()
      protected void flushBuffer()
      Flushes the buffer with Records already encapsulated in Amazon SimpleDB's items.
      protected com.amazonaws.services.simpledb.AmazonSimpleDB getAmazonSimpleDbClient()
      Retrieves the amazon SimpleDB client to be used.
      protected static com.amazonaws.services.simpledb.AmazonSimpleDB getAmazonSimpleDbClient​(java.io.File aConfigFile)
      Retrieves an AmazonSimpleDBClient from a configuration file containing the access- and the secret key.
      protected java.lang.String getAmazonSimpleDbDomainName()
      Retrieves the domain name to be used.
      protected static java.util.List<java.lang.String> getDomainNames​(com.amazonaws.services.simpledb.AmazonSimpleDBClient aAmazonSimpleDbClient)
      Retrieves a list of domain names retrievable from the given AmazonSimpleDBClient.
      protected org.refcodes.tabular.Header<T> getHeader()
      Provides access to the Header member variable required for Record related operation.
      protected static boolean hasDomain​(com.amazonaws.services.simpledb.AmazonSimpleDBClient aAmazonSimpleDbClient, java.lang.String aDomainName)
      Tests whether the given domain exists in Amazon SimpleDB.
      void initialize()
      protected static boolean isRequestTimeoutException​(java.lang.Exception aException)
      Checks if is request timeout exception.
      protected static boolean isServiceUnavailableException​(java.lang.Exception aException)
      Checks if is service unavailable exception.
      void log​(org.refcodes.tabular.Record<? extends T> aRecord)
      Log.
      protected void setAmazonSimpleDbDomainName​(java.lang.String aAmazonSimpleDbDomainName)
      Sets the domain name to be used.
      protected static java.lang.String toMessage​(java.lang.Throwable aThrowable)
      Creates an Amazon AWS specific exception message from the given throwable containing additional information such as the AWS error code, the AWS error type, the request ID, the service name and the status code.
      • Methods inherited from interface org.refcodes.component.Flushable

        flushUnchecked, isFlushable
      • Methods inherited from interface org.refcodes.component.Initializable

        initializeUnchecked
      • Methods inherited from interface org.refcodes.logger.Logger

        printSeparator
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        protected static org.refcodes.logger.RuntimeLogger LOGGER
    • Constructor Detail

      • SimpleDbLoggerImpl

        public SimpleDbLoggerImpl​(java.lang.String aDomainName,
                                  java.lang.String aAccessKey,
                                  java.lang.String aSecretKey,
                                  org.refcodes.tabular.ColumnFactory<T> aColumnFactory)
        Constructs the SimpleDbLoggerImpl for a given SimpleDB domain.
        Parameters:
        aDomainName - The name for the Amazon SimpleDB domain
        aAccessKey - The Amazon access key for Amazon SimpleDB
        aSecretKey - The Amazon secret key for Amazon SimpleDB
        aColumnFactory - The ColumnFactory to create default Column instances for Record instances to be processed
      • SimpleDbLoggerImpl

        public SimpleDbLoggerImpl​(java.lang.String aDomainName,
                                  java.lang.String aAccessKey,
                                  java.lang.String aSecretKey,
                                  java.lang.String aEndPoint,
                                  org.refcodes.tabular.ColumnFactory<T> aColumnFactory)
        Constructs the SimpleDbLoggerImpl for a given SimpleDB domain.
        Parameters:
        aDomainName - The name for the Amazon SimpleDB domain
        aAccessKey - The Amazon access key for Amazon SimpleDB
        aSecretKey - The Amazon secret key for Amazon SimpleDB
        aEndPoint - The end-point (Amazon region) to use (see AbstractSimpleDbClient's constructor documentation for possible values).
        aColumnFactory - The ColumnFactory to create default Column instances for Record instances to be processed
    • Method Detail

      • log

        public void log​(org.refcodes.tabular.Record<? extends T> aRecord)
                 throws org.refcodes.logger.IllegalRecordRuntimeException,
                        org.refcodes.logger.UnexpectedLogRuntimeException
        Log.
        Specified by:
        log in interface org.refcodes.logger.Logger<T>
        Parameters:
        aRecord - the record
        Throws:
        org.refcodes.logger.IllegalRecordRuntimeException - the illegal record runtime exception
        org.refcodes.logger.UnexpectedLogRuntimeException - the unexpected log runtime exception
      • initialize

        public void initialize()
                        throws org.refcodes.component.InitializeException
        Specified by:
        initialize in interface org.refcodes.component.Initializable
        Throws:
        org.refcodes.component.InitializeException
      • destroy

        public void destroy()
        Specified by:
        destroy in interface org.refcodes.component.Destroyable
      • decompose

        public void decompose()
        Specified by:
        decompose in interface org.refcodes.component.Decomposeable
      • flush

        public void flush()
                   throws org.refcodes.component.OpenException
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in interface org.refcodes.component.Flushable
        Throws:
        org.refcodes.component.OpenException
      • getHeader

        protected org.refcodes.tabular.Header<T> getHeader()
        Provides access to the Header member variable required for Record related operation.
        Returns:
        The Header.
      • addHeaderColumn

        protected void addHeaderColumn​(java.lang.String eKey)
        Adds a key to the dynamically created Header for reducing object creation overhead when massively logging data as no Column instances are created once the key was already added.
        Parameters:
        eKey - The key for which a Column is to be added.
      • flushBuffer

        protected void flushBuffer()
        Flushes the buffer with Records already encapsulated in Amazon SimpleDB's items.
      • getAmazonSimpleDbDomainName

        protected java.lang.String getAmazonSimpleDbDomainName()
        Retrieves the domain name to be used.
        Returns:
        The domain name.
      • setAmazonSimpleDbDomainName

        protected void setAmazonSimpleDbDomainName​(java.lang.String aAmazonSimpleDbDomainName)
        Sets the domain name to be used.
        Parameters:
        aAmazonSimpleDbDomainName - the new amazon simple db domain name
      • getAmazonSimpleDbClient

        protected com.amazonaws.services.simpledb.AmazonSimpleDB getAmazonSimpleDbClient()
        Retrieves the amazon SimpleDB client to be used.
        Returns:
        The SimpleDB client to be used.
      • isRequestTimeoutException

        protected static boolean isRequestTimeoutException​(java.lang.Exception aException)
        Checks if is request timeout exception.
        Parameters:
        aException - the exception
        Returns:
        true, if is request timeout exception
      • isServiceUnavailableException

        protected static boolean isServiceUnavailableException​(java.lang.Exception aException)
        Checks if is service unavailable exception.
        Parameters:
        aException - the exception
        Returns:
        true, if is service unavailable exception
      • toMessage

        protected static java.lang.String toMessage​(java.lang.Throwable aThrowable)
        Creates an Amazon AWS specific exception message from the given throwable containing additional information such as the AWS error code, the AWS error type, the request ID, the service name and the status code.
        Parameters:
        aThrowable - The throwable from which to generate the Amazon AWS specific exception message.
        Returns:
        The according exception message.
      • clearDomain

        protected static void clearDomain​(com.amazonaws.services.simpledb.AmazonSimpleDB aAmazonSimpleDbClient,
                                          java.lang.String aDomainName)
        Clears all content from the given Amazon SimpleDB domain.
        Parameters:
        aAmazonSimpleDbClient - The AmazonSimpleDBClient.
        aDomainName - The domain name of the domain to be cleared.
      • getAmazonSimpleDbClient

        protected static com.amazonaws.services.simpledb.AmazonSimpleDB getAmazonSimpleDbClient​(java.io.File aConfigFile)
                                                                                         throws java.io.IOException
        Retrieves an AmazonSimpleDBClient from a configuration file containing the access- and the secret key.
        Parameters:
        aConfigFile - The configuration file used to configure the AmazonSimpleDBClient.
        Returns:
        An AmazonSimpleDBClient.
        Throws:
        java.io.IOException - In case there were problems reading the configuration file.
      • getDomainNames

        protected static java.util.List<java.lang.String> getDomainNames​(com.amazonaws.services.simpledb.AmazonSimpleDBClient aAmazonSimpleDbClient)
        Retrieves a list of domain names retrievable from the given AmazonSimpleDBClient.
        Parameters:
        aAmazonSimpleDbClient - The AmazonSimpleDBClient.
        Returns:
        A list containing String instances representing the retrievable domain names.
      • hasDomain

        protected static boolean hasDomain​(com.amazonaws.services.simpledb.AmazonSimpleDBClient aAmazonSimpleDbClient,
                                           java.lang.String aDomainName)
        Tests whether the given domain exists in Amazon SimpleDB.
        Parameters:
        aAmazonSimpleDbClient - The AmazonSimpleDBClient.
        aDomainName - The domain name to be tested.
        Returns:
        True in case the domain with the given name exists, else false.