Package org.refcodes.logger.alt.simpledb
Class SimpleDbLogger<T>
java.lang.Object
org.refcodes.logger.alt.simpledb.SimpleDbLogger<T>
- Type Parameters:
T
- The type of theRecord
instances managed by theLogger
.
- All Implemented Interfaces:
Flushable
,org.refcodes.component.Component
,org.refcodes.component.Decomposable
,org.refcodes.component.Destroyable
,org.refcodes.component.Flushable
,org.refcodes.component.Initializable
,org.refcodes.logger.LogDecorator
,org.refcodes.logger.Logger<T>
- Direct Known Subclasses:
SimpleDbQueryLogger
public class SimpleDbLogger<T>
extends Object
implements org.refcodes.logger.Logger<T>, org.refcodes.component.Component, org.refcodes.component.Initializable, org.refcodes.component.Decomposable, org.refcodes.component.Flushable
The
SimpleDbLogger
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.Decomposable
org.refcodes.component.Decomposable.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
-
Constructor Summary
ConstructorDescriptionSimpleDbLogger
(String aDomainName, String aAccessKey, String aSecretKey, String aEndPoint, org.refcodes.tabular.ColumnFactory<T> aColumnFactory) Constructs theSimpleDbLogger
for a given SimpleDB domain.SimpleDbLogger
(String aDomainName, String aAccessKey, String aSecretKey, org.refcodes.tabular.ColumnFactory<T> aColumnFactory) Constructs theSimpleDbLogger
for a given SimpleDB domain. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addHeaderColumn
(String aKey) Adds a key to the dynamically createdHeader
for reducing object creation overhead when massively logging data as noColumn
instances are created once the key was already added.protected static void
clearDomain
(com.amazonaws.services.simpledb.AmazonSimpleDB aAmazonSimpleDbClient, String aDomainName) Clears all content from the given Amazon SimpleDB domain.void
void
destroy()
void
flush()
protected void
Flushes the buffer withRecords
already encapsulated in Amazon SimpleDB's items.protected com.amazonaws.services.simpledb.AmazonSimpleDB
Retrieves the amazon SimpleDB client to be used.protected static com.amazonaws.services.simpledb.AmazonSimpleDB
getAmazonSimpleDbClient
(File aConfigFile) Retrieves anAmazonSimpleDBClient
from a configuration file containing the access- and the secret key.protected String
Retrieves the domain name to be used.getDomainNames
(com.amazonaws.services.simpledb.AmazonSimpleDBClient aAmazonSimpleDbClient) Retrieves a list of domain names retrievable from the givenAmazonSimpleDBClient
.protected org.refcodes.tabular.Header<T>
Provides access to theHeader
member variable required forRecord
related operation.protected static boolean
hasDomain
(com.amazonaws.services.simpledb.AmazonSimpleDBClient aAmazonSimpleDbClient, String aDomainName) Tests whether the given domain exists in Amazon SimpleDB.void
protected static boolean
isRequestTimeoutException
(Exception aException) Checks if is request timeout exception.protected static boolean
isServiceUnavailableException
(Exception aException) Checks if is service unavailable exception.void
Log aRecord
instance.protected void
setAmazonSimpleDbDomainName
(String aAmazonSimpleDbDomainName) Sets the domain name to be used.protected static String
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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
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.LogDecorator
printHead, printSeparator, printTail
-
Constructor Details
-
SimpleDbLogger
public SimpleDbLogger(String aDomainName, String aAccessKey, String aSecretKey, org.refcodes.tabular.ColumnFactory<T> aColumnFactory) Constructs theSimpleDbLogger
for a given SimpleDB domain.- Parameters:
aDomainName
- The name for the Amazon SimpleDB domainaAccessKey
- The Amazon access key for Amazon SimpleDBaSecretKey
- The Amazon secret key for Amazon SimpleDBaColumnFactory
- TheColumnFactory
to create defaultColumn
instances forRecord
instances to be processed
-
SimpleDbLogger
public SimpleDbLogger(String aDomainName, String aAccessKey, String aSecretKey, String aEndPoint, org.refcodes.tabular.ColumnFactory<T> aColumnFactory) Constructs theSimpleDbLogger
for a given SimpleDB domain.- Parameters:
aDomainName
- The name for the Amazon SimpleDB domainaAccessKey
- The Amazon access key for Amazon SimpleDBaSecretKey
- The Amazon secret key for Amazon SimpleDBaEndPoint
- The end-point (Amazon region) to use (seeAbstractSimpleDbClient
's constructor documentation for possible values).aColumnFactory
- TheColumnFactory
to create defaultColumn
instances forRecord
instances to be processed
-
-
Method Details
-
log
Log aRecord
instance.- Specified by:
log
in interfaceorg.refcodes.logger.Logger<T>
- Parameters:
aRecord
- theRecord
instance to be logged.- Throws:
org.refcodes.logger.IllegalRecordRuntimeException
- thrown in case the record cannot be logged as a specific implementation might expect some dedicatedColumn
instances to be contained in the provided Record.org.refcodes.logger.UnexpectedLogRuntimeException
- thrown in case some other problems regarding logging occurred, e.g. the data sink (physical system where to log to) experiences problems.
-
initialize
public void initialize() throws org.refcodes.component.InitializeException- Specified by:
initialize
in interfaceorg.refcodes.component.Initializable
- Throws:
org.refcodes.component.InitializeException
-
destroy
public void destroy()- Specified by:
destroy
in interfaceorg.refcodes.component.Destroyable
-
decompose
public void decompose()- Specified by:
decompose
in interfaceorg.refcodes.component.Decomposable
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in interfaceorg.refcodes.component.Flushable
- Throws:
IOException
-
getHeader
Provides access to theHeader
member variable required forRecord
related operation.- Returns:
- The
Header
.
-
addHeaderColumn
Adds a key to the dynamically createdHeader
for reducing object creation overhead when massively logging data as noColumn
instances are created once the key was already added.- Parameters:
aKey
- The key for which aColumn
is to be added.
-
flushBuffer
protected void flushBuffer()Flushes the buffer withRecords
already encapsulated in Amazon SimpleDB's items. -
getAmazonSimpleDbDomainName
Retrieves the domain name to be used.- Returns:
- The domain name.
-
setAmazonSimpleDbDomainName
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
Checks if is request timeout exception.- Parameters:
aException
- the exception- Returns:
- true, if is request timeout exception
-
toMessage
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, String aDomainName) Clears all content from the given Amazon SimpleDB domain.- Parameters:
aAmazonSimpleDbClient
- TheAmazonSimpleDBClient
.aDomainName
- The domain name of the domain to be cleared.
-
getAmazonSimpleDbClient
protected static com.amazonaws.services.simpledb.AmazonSimpleDB getAmazonSimpleDbClient(File aConfigFile) throws IOException Retrieves anAmazonSimpleDBClient
from a configuration file containing the access- and the secret key.- Parameters:
aConfigFile
- The configuration file used to configure theAmazonSimpleDBClient
.- Returns:
- An
AmazonSimpleDBClient
. - Throws:
IOException
- In case there were problems reading the configuration file.
-
getDomainNames
protected static List<String> getDomainNames(com.amazonaws.services.simpledb.AmazonSimpleDBClient aAmazonSimpleDbClient) Retrieves a list of domain names retrievable from the givenAmazonSimpleDBClient
.- Parameters:
aAmazonSimpleDbClient
- TheAmazonSimpleDBClient
.- Returns:
- A list containing
String
instances representing the retrievable domain names.
-
hasDomain
protected static boolean hasDomain(com.amazonaws.services.simpledb.AmazonSimpleDBClient aAmazonSimpleDbClient, String aDomainName) Tests whether the given domain exists in Amazon SimpleDB.- Parameters:
aAmazonSimpleDbClient
- TheAmazonSimpleDBClient
.aDomainName
- The domain name to be tested.- Returns:
- True in case the domain with the given name exists, else false.
-