All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.refcodes.logger.alt.simpledb.AbstractSimpleDbLoggerFactory Maven / Gradle / Ivy

There is a newer version: 3.3.8
Show newest version
// /////////////////////////////////////////////////////////////////////////////
// REFCODES.ORG
// =============================================================================
// This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
// under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
// licenses:
// =============================================================================
// GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
// together with the GPL linking exception applied; as being applied by the GNU
// Classpath ("http://www.gnu.org/software/classpath/license.html")
// =============================================================================
// Apache License, v2.0 ("http://www.apache.org/licenses/TEXT-2.0")
// =============================================================================
// Please contact the copyright holding author(s) of the software artifacts in
// question for licensing issues not being covered by the above listed licenses,
// also regarding commercial licensing models or regarding the compatibility
// with other open source licenses.
// /////////////////////////////////////////////////////////////////////////////

package org.refcodes.logger.alt.simpledb;

import java.util.Map;
import java.util.logging.Level;

import org.refcodes.logger.Logger;
import org.refcodes.logger.LoggerFactory;
import org.refcodes.tabular.Column;
import org.refcodes.tabular.ColumnFactory;
import org.refcodes.textual.SecretHintBuilder;

/**
 * The {@link AbstractSimpleDbLoggerFactory} implements the
 * {@link LoggerFactory} and creates {@link Logger} instances using the SimpleDB
 * NoSQL engine from Amazon. The {@link LoggerFactory} methods
 * {@link #createInstance(String)} and {@link #createInstance(String)} actually
 * return {@link SimpleDbLogger} instances being configured to use an Amazon
 * SimpleDB domain name constructed from an Amazon SimpleDB domain prefix
 * (provided to the constructor) and suffix (provided to the factory methods).
 *
 * @param  The type (sub-type) of the {@link Logger} to be created.
 * @param  The type of the {@link Record} instances managed by the
 *        {@link Logger}.
 */
abstract class AbstractSimpleDbLoggerFactory, T> implements LoggerFactory {

	// /////////////////////////////////////////////////////////////////////////
	// STATICS:
	// /////////////////////////////////////////////////////////////////////////

	private static java.util.logging.Logger LOGGER = java.util.logging.Logger.getLogger( AbstractSimpleDbLoggerFactory.class.getName() );

	// /////////////////////////////////////////////////////////////////////////
	// VARIABLES:
	// /////////////////////////////////////////////////////////////////////////

	private String _schemaPrefix;
	private String _accessKey;
	private String _secretKey;
	private String _endPoint;
	private ColumnFactory _columnFactory;

	// /////////////////////////////////////////////////////////////////////////
	// CONSTRUCTORS:
	// /////////////////////////////////////////////////////////////////////////

	/**
	 * Creates an {@link AbstractSimpleDbLoggerFactory} for creating Amazon
	 * SimpleDB based {@link Logger} instances.
	 * 
	 * @param aDomainPrefix The Amazon SimpleDB domain name's prefix.
	 * @param aAccessKey The Amazon access key to use.
	 * @param aSecretKey The Amazon secret key to use.
	 * @param aEndPoint The end-point (Amazon region) to use.
	 * @param aColumnFactory The {@link ColumnFactory} used to handle the
	 *        {@link Column} instances.
	 */
	public AbstractSimpleDbLoggerFactory( String aDomainPrefix, String aAccessKey, String aSecretKey, String aEndPoint, ColumnFactory aColumnFactory ) {
		_schemaPrefix = aDomainPrefix;
		_accessKey = aAccessKey;
		_secretKey = aSecretKey;
		_endPoint = aEndPoint;
		_columnFactory = aColumnFactory;
		LOGGER.log( Level.FINE, "Using Amazon SimpleDB domain prefix \"" + aDomainPrefix + "\", access key \"" + SecretHintBuilder.asString( aAccessKey ) + "\", secret key \"" + SecretHintBuilder.asString( aSecretKey ) + "\" and the end-point \"" + aEndPoint + "\"." );
	}

	// /////////////////////////////////////////////////////////////////////////
	// METHODS:
	// /////////////////////////////////////////////////////////////////////////

	/**
	 * {@inheritDoc}
	 */
	@Override
	abstract public L createInstance( String aDomainSuffix );

	/**
	 * {@inheritDoc}
	 */
	@Override
	public L createInstance( String aDomainSuffix, Map aProperties ) {
		return createInstance( aDomainSuffix );
	}

	// /////////////////////////////////////////////////////////////////////////
	// HELPER:
	// /////////////////////////////////////////////////////////////////////////

	/**
	 * Provides access to the schema prefix.
	 * 
	 * @return The schema prefix
	 */
	protected String getSchemaPrefix() {
		return _schemaPrefix;
	}

	/**
	 * Retrieves the Amazon access key.
	 * 
	 * @return The Amazon access key.
	 */
	protected String getAccessKey() {
		return _accessKey;
	}

	/**
	 * Retrieves the Amazon secret key.
	 * 
	 * @return The Amazon secret key.
	 */
	protected String getSecretKey() {
		return _secretKey;
	}

	/**
	 * Retrieves the Amazon SimpleDB end-point.
	 * 
	 * @return The Amazon SimpleDB end-point.
	 */
	protected String getEndPoint() {
		return _endPoint;
	}

	/**
	 * Retrieves the {@link ColumnFactory} to be used.
	 * 
	 * @return The {@link ColumnFactory} to be used.
	 */
	protected ColumnFactory getColumnFactory() {
		return _columnFactory;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy