Skip to content

Commit

Permalink
Rename ExtractionNamespaceCacheFactory to CachePopulator (the last pa…
Browse files Browse the repository at this point in the history
…rt of apache#3667) (apache#4303)

* Renamed ExtractionNamespaceCacheFactory to CachePopulator, and related classes

* Rename CachePopulator to CacheGenerator
  • Loading branch information
leventov authored and gianm committed Jun 3, 2017
1 parent b90c28e commit ebabe14
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@
/**
*
*/
public interface ExtractionNamespaceCacheFactory<T extends ExtractionNamespace>
public interface CacheGenerator<T extends ExtractionNamespace>
{
/**
* If the lookup source, encapsulated by this {@code ExtractionNamespaceCacheFactory}, has data newer than identified
* If the lookup source, encapsulated by this {@code CacheGenerator}, has data newer than identified
* by the given {@code lastVersion} (which is null at the first run of this method, or the version from the previous
* run), this method creates a new {@code CacheScheduler.VersionedCache} with {@link
* CacheScheduler#createVersionedCache}, called on the given {@code scheduler}, with the version string identifying
* the current version of lookup source, populates the created {@code VersionedCache} and returns it. If the lookup
* source is up-to-date, this methods returns null.
*
* @param namespace The ExtractionNamespace for which to populate data.
* @param id An object uniquely corresponding to the {@link CacheScheduler.Entry}, for which this populateCache()
* @param namespace The ExtractionNamespace for which to generate cache.
* @param id An object uniquely corresponding to the {@link CacheScheduler.Entry}, for which this generateCache()
* method is called. Also it has the same toString() representation, that is useful for logging
* @param lastVersion The version which was last cached
* @param scheduler Should be used only to call {@link CacheScheduler#createVersionedCache}.
* @return the new cache along with the new version, or null if the last version is up-to-date.
*/
@Nullable
CacheScheduler.VersionedCache populateCache(
CacheScheduler.VersionedCache generateCache(
T namespace,
CacheScheduler.EntryImpl<T> id,
String lastVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes(value = {
@JsonSubTypes.Type(name = "jdbc", value = JDBCExtractionNamespace.class),
@JsonSubTypes.Type(name = "uri", value = URIExtractionNamespace.class),
@JsonSubTypes.Type(name = "jdbc", value = JdbcExtractionNamespace.class),
@JsonSubTypes.Type(name = "uri", value = UriExtractionNamespace.class),
@JsonSubTypes.Type(name = StaticMapExtractionNamespace.TYPE_NAME, value = StaticMapExtractionNamespace.class)
})
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
*/
@JsonTypeName("jdbc")
public class JDBCExtractionNamespace implements ExtractionNamespace
public class JdbcExtractionNamespace implements ExtractionNamespace
{
@JsonProperty
private final MetadataStorageConnectorConfig connectorConfig;
Expand All @@ -50,7 +50,7 @@ public class JDBCExtractionNamespace implements ExtractionNamespace
private final Period pollPeriod;

@JsonCreator
public JDBCExtractionNamespace(
public JdbcExtractionNamespace(
@NotNull @JsonProperty(value = "connectorConfig", required = true)
final MetadataStorageConnectorConfig connectorConfig,
@NotNull @JsonProperty(value = "table", required = true)
Expand Down Expand Up @@ -109,7 +109,7 @@ public long getPollMs()
public String toString()
{
return String.format(
"JDBCExtractionNamespace = { connectorConfig = { %s }, table = %s, keyColumn = %s, valueColumn = %s, tsColumn = %s, pollPeriod = %s}",
"JdbcExtractionNamespace = { connectorConfig = { %s }, table = %s, keyColumn = %s, valueColumn = %s, tsColumn = %s, pollPeriod = %s}",
connectorConfig.toString(),
table,
keyColumn,
Expand All @@ -129,7 +129,7 @@ public boolean equals(Object o)
return false;
}

JDBCExtractionNamespace that = (JDBCExtractionNamespace) o;
JdbcExtractionNamespace that = (JdbcExtractionNamespace) o;

if (!connectorConfig.equals(that.connectorConfig)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
*
*/
@JsonTypeName("uri")
public class URIExtractionNamespace implements ExtractionNamespace
public class UriExtractionNamespace implements ExtractionNamespace
{
@JsonProperty
private final URI uri;
Expand All @@ -73,7 +73,7 @@ public class URIExtractionNamespace implements ExtractionNamespace
private final Period pollPeriod;

@JsonCreator
public URIExtractionNamespace(
public UriExtractionNamespace(
@JsonProperty(value = "uri", required = false)
URI uri,
@JsonProperty(value = "uriPrefix", required = false)
Expand Down Expand Up @@ -144,7 +144,7 @@ public long getPollMs()
@Override
public String toString()
{
return "URIExtractionNamespace{" +
return "UriExtractionNamespace{" +
"uri=" + uri +
", uriPrefix=" + uriPrefix +
", namespaceParseSpec=" + namespaceParseSpec +
Expand All @@ -163,7 +163,7 @@ public boolean equals(Object o)
return false;
}

URIExtractionNamespace that = (URIExtractionNamespace) o;
UriExtractionNamespace that = (UriExtractionNamespace) o;

if (getUri() != null ? !getUri().equals(that.getUri()) : that.getUri() != null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.druid.common.utils.JodaUtils;
import io.druid.java.util.common.Pair;
import io.druid.java.util.common.logger.Logger;
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
import io.druid.query.lookup.namespace.JDBCExtractionNamespace;
import io.druid.query.lookup.namespace.CacheGenerator;
import io.druid.query.lookup.namespace.JdbcExtractionNamespace;
import io.druid.server.lookup.namespace.cache.CacheScheduler;
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.Handle;
Expand All @@ -44,18 +44,17 @@
/**
*
*/
public final class JDBCExtractionNamespaceCacheFactory
implements ExtractionNamespaceCacheFactory<JDBCExtractionNamespace>
public final class JdbcCacheGenerator implements CacheGenerator<JdbcExtractionNamespace>
{
private static final Logger LOG = new Logger(JDBCExtractionNamespaceCacheFactory.class);
private final ConcurrentMap<CacheScheduler.EntryImpl<JDBCExtractionNamespace>, DBI> dbiCache =
private static final Logger LOG = new Logger(JdbcCacheGenerator.class);
private final ConcurrentMap<CacheScheduler.EntryImpl<JdbcExtractionNamespace>, DBI> dbiCache =
new ConcurrentHashMap<>();

@Override
@Nullable
public CacheScheduler.VersionedCache populateCache(
final JDBCExtractionNamespace namespace,
final CacheScheduler.EntryImpl<JDBCExtractionNamespace> entryId,
public CacheScheduler.VersionedCache generateCache(
final JdbcExtractionNamespace namespace,
final CacheScheduler.EntryImpl<JdbcExtractionNamespace> entryId,
final String lastVersion,
final CacheScheduler scheduler
)
Expand Down Expand Up @@ -132,9 +131,9 @@ public Pair<String, String> map(
}
}

private DBI ensureDBI(CacheScheduler.EntryImpl<JDBCExtractionNamespace> id, JDBCExtractionNamespace namespace)
private DBI ensureDBI(CacheScheduler.EntryImpl<JdbcExtractionNamespace> id, JdbcExtractionNamespace namespace)
{
final CacheScheduler.EntryImpl<JDBCExtractionNamespace> key = id;
final CacheScheduler.EntryImpl<JdbcExtractionNamespace> key = id;
DBI dbi = null;
if (dbiCache.containsKey(key)) {
dbi = dbiCache.get(key);
Expand All @@ -151,7 +150,7 @@ private DBI ensureDBI(CacheScheduler.EntryImpl<JDBCExtractionNamespace> id, JDBC
return dbi;
}

private Long lastUpdates(CacheScheduler.EntryImpl<JDBCExtractionNamespace> id, JDBCExtractionNamespace namespace)
private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> id, JdbcExtractionNamespace namespace)
{
final DBI dbi = ensureDBI(id, namespace);
final String table = namespace.getTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import io.druid.guice.PolyBind;
import io.druid.initialization.DruidModule;
import io.druid.query.lookup.NamespaceLookupExtractorFactory;
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
import io.druid.query.lookup.namespace.CacheGenerator;
import io.druid.query.lookup.namespace.ExtractionNamespace;
import io.druid.query.lookup.namespace.JDBCExtractionNamespace;
import io.druid.query.lookup.namespace.JdbcExtractionNamespace;
import io.druid.query.lookup.namespace.StaticMapExtractionNamespace;
import io.druid.query.lookup.namespace.URIExtractionNamespace;
import io.druid.query.lookup.namespace.UriExtractionNamespace;
import io.druid.server.lookup.namespace.cache.NamespaceExtractionCacheManager;
import io.druid.server.lookup.namespace.cache.OffHeapNamespaceExtractionCacheManager;
import io.druid.server.lookup.namespace.cache.OnHeapNamespaceExtractionCacheManager;
Expand All @@ -59,7 +59,7 @@ public List<? extends Module> getJacksonModules()
);
}

public static MapBinder<Class<? extends ExtractionNamespace>, ExtractionNamespaceCacheFactory<?>> getNamespaceFactoryMapBinder(
public static MapBinder<Class<? extends ExtractionNamespace>, CacheGenerator<?>> getNamespaceFactoryMapBinder(
final Binder binder
)
{
Expand All @@ -68,7 +68,7 @@ public static MapBinder<Class<? extends ExtractionNamespace>, ExtractionNamespac
new TypeLiteral<Class<? extends ExtractionNamespace>>()
{
},
new TypeLiteral<ExtractionNamespaceCacheFactory<?>>()
new TypeLiteral<CacheGenerator<?>>()
{
}
);
Expand All @@ -92,16 +92,16 @@ public void configure(Binder binder)
.in(LazySingleton.class);

getNamespaceFactoryMapBinder(binder)
.addBinding(JDBCExtractionNamespace.class)
.to(JDBCExtractionNamespaceCacheFactory.class)
.addBinding(JdbcExtractionNamespace.class)
.to(JdbcCacheGenerator.class)
.in(LazySingleton.class);
getNamespaceFactoryMapBinder(binder)
.addBinding(URIExtractionNamespace.class)
.to(URIExtractionNamespaceCacheFactory.class)
.addBinding(UriExtractionNamespace.class)
.to(UriCacheGenerator.class)
.in(LazySingleton.class);
getNamespaceFactoryMapBinder(binder)
.addBinding(StaticMapExtractionNamespace.class)
.to(StaticMapExtractionNamespaceCacheFactory.class)
.to(StaticMapCacheGenerator.class)
.in(LazySingleton.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

package io.druid.server.lookup.namespace;

import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
import io.druid.query.lookup.namespace.CacheGenerator;
import io.druid.query.lookup.namespace.StaticMapExtractionNamespace;
import io.druid.server.lookup.namespace.cache.CacheScheduler;

import javax.annotation.Nullable;
import java.util.UUID;

public final class StaticMapExtractionNamespaceCacheFactory implements ExtractionNamespaceCacheFactory<StaticMapExtractionNamespace>
public final class StaticMapCacheGenerator implements CacheGenerator<StaticMapExtractionNamespace>
{
private final String version = UUID.randomUUID().toString();

@Override
@Nullable
public CacheScheduler.VersionedCache populateCache(
public CacheScheduler.VersionedCache generateCache(
final StaticMapExtractionNamespace namespace,
final CacheScheduler.EntryImpl<StaticMapExtractionNamespace> id,
final String lastVersion,
Expand All @@ -43,7 +43,7 @@ public CacheScheduler.VersionedCache populateCache(
// Throwing AssertionError, because CacheScheduler doesn't suppress Errors and will stop trying to update
// the cache periodically.
throw new AssertionError(
"StaticMapExtractionNamespaceCacheFactory could only be configured for a namespace which is scheduled "
"StaticMapCacheGenerator could only be configured for a namespace which is scheduled "
+ "to be updated once, not periodically. Last version: `" + lastVersion + "`");
}
CacheScheduler.VersionedCache versionedCache = scheduler.createVersionedCache(id, version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import io.druid.java.util.common.IAE;
import io.druid.java.util.common.RetryUtils;
import io.druid.java.util.common.logger.Logger;
import io.druid.query.lookup.namespace.ExtractionNamespaceCacheFactory;
import io.druid.query.lookup.namespace.URIExtractionNamespace;
import io.druid.query.lookup.namespace.CacheGenerator;
import io.druid.query.lookup.namespace.UriExtractionNamespace;
import io.druid.segment.loading.URIDataPuller;
import io.druid.server.lookup.namespace.cache.CacheScheduler;

Expand All @@ -44,14 +44,14 @@
/**
*
*/
public final class URIExtractionNamespaceCacheFactory implements ExtractionNamespaceCacheFactory<URIExtractionNamespace>
public final class UriCacheGenerator implements CacheGenerator<UriExtractionNamespace>
{
private static final int DEFAULT_NUM_RETRIES = 3;
private static final Logger log = new Logger(URIExtractionNamespaceCacheFactory.class);
private static final Logger log = new Logger(UriCacheGenerator.class);
private final Map<String, SearchableVersionedDataFinder> pullers;

@Inject
public URIExtractionNamespaceCacheFactory(
public UriCacheGenerator(
Map<String, SearchableVersionedDataFinder> pullers
)
{
Expand All @@ -60,9 +60,9 @@ public URIExtractionNamespaceCacheFactory(

@Override
@Nullable
public CacheScheduler.VersionedCache populateCache(
final URIExtractionNamespace extractionNamespace,
final CacheScheduler.EntryImpl<URIExtractionNamespace> entryId,
public CacheScheduler.VersionedCache generateCache(
final UriExtractionNamespace extractionNamespace,
final CacheScheduler.EntryImpl<UriExtractionNamespace> entryId,
@Nullable final String lastVersion,
final CacheScheduler scheduler
) throws Exception
Expand Down
Loading

0 comments on commit ebabe14

Please sign in to comment.