killbill-aplcache
Changes
account/src/main/java/org/killbill/billing/account/api/svcs/DefaultImmutableAccountInternalApi.java 6(+3 -3)
payment/src/main/java/org/killbill/billing/payment/caching/EhCacheStateMachineConfigCache.java 2(+1 -1)
util/src/main/java/org/killbill/billing/util/cache/CacheControllerDispatcherProvider.java 47(+17 -30)
util/src/main/java/org/killbill/billing/util/cache/TenantStateMachineConfigCacheLoader.java 18(+4 -14)
Details
diff --git a/account/src/main/java/org/killbill/billing/account/api/svcs/DefaultAccountInternalApi.java b/account/src/main/java/org/killbill/billing/account/api/svcs/DefaultAccountInternalApi.java
index c9cc74a..4f7b285 100644
--- a/account/src/main/java/org/killbill/billing/account/api/svcs/DefaultAccountInternalApi.java
+++ b/account/src/main/java/org/killbill/billing/account/api/svcs/DefaultAccountInternalApi.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -160,8 +160,8 @@ public class DefaultAccountInternalApi extends DefaultAccountApiBase implements
private CacheLoaderArgument createBCDCacheLoaderArgument(final InternalTenantContext context) {
final AccountBCDCacheLoader.LoaderCallback loaderCallback = new AccountBCDCacheLoader.LoaderCallback() {
@Override
- public Object loadAccountBCD(final UUID accountId, final InternalTenantContext context) {
- Object result = accountDao.getAccountBCD(accountId, context);
+ public Integer loadAccountBCD(final UUID accountId, final InternalTenantContext context) {
+ Integer result = accountDao.getAccountBCD(accountId, context);
if (result != null) {
// If the value is 0, then account BCD was not set so we don't want to create a cache entry
result = result.equals(DefaultMutableAccountData.DEFAULT_BILLING_CYCLE_DAY_LOCAL) ? null : result;
diff --git a/account/src/main/java/org/killbill/billing/account/api/svcs/DefaultImmutableAccountInternalApi.java b/account/src/main/java/org/killbill/billing/account/api/svcs/DefaultImmutableAccountInternalApi.java
index 250d47a..295a35a 100644
--- a/account/src/main/java/org/killbill/billing/account/api/svcs/DefaultImmutableAccountInternalApi.java
+++ b/account/src/main/java/org/killbill/billing/account/api/svcs/DefaultImmutableAccountInternalApi.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Groupon, Inc
- * Copyright 2016 The Billing Project, LLC
+ * Copyright 2016-2017 Groupon, Inc
+ * Copyright 2016-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -78,7 +78,7 @@ public class DefaultImmutableAccountInternalApi implements ImmutableAccountInter
private CacheLoaderArgument createImmutableAccountCacheLoaderArgument(final InternalTenantContext context) {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
- public Object loadAccount(final Long recordId, final InternalTenantContext context) {
+ public ImmutableAccountData loadAccount(final Long recordId, final InternalTenantContext context) {
final Account account = getAccountByRecordIdInternal(recordId, context);
return account != null ? new DefaultImmutableAccountData(account) : null;
}
diff --git a/catalog/src/main/java/org/killbill/billing/catalog/caching/EhCacheCatalogCache.java b/catalog/src/main/java/org/killbill/billing/catalog/caching/EhCacheCatalogCache.java
index ee21422..66986ea 100644
--- a/catalog/src/main/java/org/killbill/billing/catalog/caching/EhCacheCatalogCache.java
+++ b/catalog/src/main/java/org/killbill/billing/catalog/caching/EhCacheCatalogCache.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -27,6 +27,7 @@ import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.catalog.StandaloneCatalog;
import org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride;
import org.killbill.billing.catalog.VersionedCatalog;
+import org.killbill.billing.catalog.api.Catalog;
import org.killbill.billing.catalog.api.CatalogApiException;
import org.killbill.billing.catalog.io.VersionedCatalogLoader;
import org.killbill.billing.catalog.override.PriceOverride;
@@ -113,7 +114,7 @@ public class EhCacheCatalogCache implements CatalogCache {
final StandaloneCatalogWithPriceOverride curWithOverride = new StandaloneCatalogWithPriceOverride(cur, priceOverride, tenantContext.getTenantRecordId(), internalCallContextFactory);
tenantCatalog.add(curWithOverride);
}
- cacheController.add(tenantContext.getTenantRecordId(), tenantCatalog);
+ cacheController.putIfAbsent(tenantContext.getTenantRecordId(), tenantCatalog);
}
return tenantCatalog;
} catch (final IllegalStateException e) {
@@ -150,7 +151,7 @@ public class EhCacheCatalogCache implements CatalogCache {
private CacheLoaderArgument initializeCacheLoaderArgument(final boolean filterTemplateCatalog) {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
- public Object loadCatalog(final List<String> catalogXMLs, final Long tenantRecordId) throws CatalogApiException {
+ public Catalog loadCatalog(final List<String> catalogXMLs, final Long tenantRecordId) throws CatalogApiException {
return loader.load(catalogXMLs, filterTemplateCatalog, tenantRecordId);
}
};
diff --git a/catalog/src/main/java/org/killbill/billing/catalog/caching/EhCacheOverriddenPlanCache.java b/catalog/src/main/java/org/killbill/billing/catalog/caching/EhCacheOverriddenPlanCache.java
index f0b3f7c..bb3b7e3 100644
--- a/catalog/src/main/java/org/killbill/billing/catalog/caching/EhCacheOverriddenPlanCache.java
+++ b/catalog/src/main/java/org/killbill/billing/catalog/caching/EhCacheOverriddenPlanCache.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -58,7 +58,7 @@ public class EhCacheOverriddenPlanCache implements OverriddenPlanCache {
this.cacheController = cacheControllerDispatcher.getCacheController(CacheType.OVERRIDDEN_PLAN);
this.loaderCallback = new LoaderCallback() {
@Override
- public Object loadPlan(final String planName, final StaticCatalog catalog, final InternalTenantContext context) throws CatalogApiException {
+ public Plan loadPlan(final String planName, final StaticCatalog catalog, final InternalTenantContext context) throws CatalogApiException {
return loadOverriddenPlan(planName, catalog, context);
}
};
diff --git a/overdue/src/main/java/org/killbill/billing/overdue/caching/EhCacheOverdueConfigCache.java b/overdue/src/main/java/org/killbill/billing/overdue/caching/EhCacheOverdueConfigCache.java
index 7285e87..f36b9e5 100644
--- a/overdue/src/main/java/org/killbill/billing/overdue/caching/EhCacheOverdueConfigCache.java
+++ b/overdue/src/main/java/org/killbill/billing/overdue/caching/EhCacheOverdueConfigCache.java
@@ -114,7 +114,7 @@ public class EhCacheOverdueConfigCache implements OverdueConfigCache {
private CacheLoaderArgument initializeCacheLoaderArgument() {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
- public Object loadOverdueConfig(final String overdueConfigXML) throws OverdueApiException {
+ public OverdueConfig loadOverdueConfig(final String overdueConfigXML) throws OverdueApiException {
final InputStream overdueConfigStream = new ByteArrayInputStream(overdueConfigXML.getBytes());
final URI uri;
try {
diff --git a/payment/src/main/java/org/killbill/billing/payment/caching/EhCacheStateMachineConfigCache.java b/payment/src/main/java/org/killbill/billing/payment/caching/EhCacheStateMachineConfigCache.java
index ae76cb2..5fc9511 100644
--- a/payment/src/main/java/org/killbill/billing/payment/caching/EhCacheStateMachineConfigCache.java
+++ b/payment/src/main/java/org/killbill/billing/payment/caching/EhCacheStateMachineConfigCache.java
@@ -105,7 +105,7 @@ public class EhCacheStateMachineConfigCache implements StateMachineConfigCache {
// It means we are using the default state machine config in a multi-tenant deployment
if (pluginPaymentStateMachineConfig == null) {
pluginPaymentStateMachineConfig = defaultPaymentStateMachineConfig;
- cacheController.add(pluginConfigKey, pluginPaymentStateMachineConfig);
+ cacheController.putIfAbsent(pluginConfigKey, pluginPaymentStateMachineConfig);
}
return pluginPaymentStateMachineConfig;
} catch (final IllegalStateException e) {
diff --git a/util/src/main/java/org/killbill/billing/util/cache/AccountBCDCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/AccountBCDCacheLoader.java
index d88ea69..6e9955d 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/AccountBCDCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/AccountBCDCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -22,7 +22,7 @@ import java.util.UUID;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.util.cache.Cachable.CacheType;
-public class AccountBCDCacheLoader extends BaseCacheLoader {
+public class AccountBCDCacheLoader extends BaseCacheLoader<UUID, Integer> {
@Override
public CacheType getCacheType() {
@@ -30,30 +30,18 @@ public class AccountBCDCacheLoader extends BaseCacheLoader {
}
@Override
- public Object load(final Object key, final Object argument) {
-
- checkCacheLoaderStatus();
-
- if (!(key instanceof UUID)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
-
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected argument type of " + argument.getClass().getName());
- }
-
- final CacheLoaderArgument cacheLoaderArgument = (CacheLoaderArgument) argument;
-
+ public Integer compute(final UUID key, final CacheLoaderArgument cacheLoaderArgument) {
if (cacheLoaderArgument.getArgs() == null ||
!(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) {
throw new IllegalArgumentException("Missing LoaderCallback from the arguments ");
}
final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0];
- return callback.loadAccountBCD((UUID) key, cacheLoaderArgument.getInternalTenantContext());
+ return callback.loadAccountBCD(key, cacheLoaderArgument.getInternalTenantContext());
}
public interface LoaderCallback {
- Object loadAccountBCD(final UUID accountId, final InternalTenantContext context);
+
+ Integer loadAccountBCD(final UUID accountId, final InternalTenantContext context);
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/AccountRecordIdCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/AccountRecordIdCacheLoader.java
index 352a2d7..7cb8757 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/AccountRecordIdCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/AccountRecordIdCacheLoader.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -28,10 +28,8 @@ import org.killbill.billing.util.cache.Cachable.CacheType;
import org.killbill.billing.util.dao.NonEntityDao;
import org.skife.jdbi.v2.Handle;
-import net.sf.ehcache.loader.CacheLoader;
-
@Singleton
-public class AccountRecordIdCacheLoader extends BaseIdCacheLoader implements CacheLoader {
+public class AccountRecordIdCacheLoader extends BaseIdCacheLoader<Long> {
private final NonEntityDao nonEntityDao;
@@ -47,7 +45,7 @@ public class AccountRecordIdCacheLoader extends BaseIdCacheLoader implements Cac
}
@Override
- protected Object doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle) {
+ protected Long doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle) {
return nonEntityDao.retrieveAccountRecordIdFromObjectInTransaction(UUID.fromString(rawKey), objectType, null, handle);
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/AuditLogCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/AuditLogCacheLoader.java
index bc0761d..ac42ff0 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/AuditLogCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/AuditLogCacheLoader.java
@@ -1,7 +1,9 @@
/*
- * Copyright 2010-2012 Ning, Inc.
+ * Copyright 2010-2013 Ning, Inc.
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
- * Ning licenses this file to you under the Apache License, version 2.0
+ * The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
@@ -16,25 +18,24 @@
package org.killbill.billing.util.cache;
+import java.util.List;
+
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.skife.jdbi.v2.IDBI;
-
import org.killbill.billing.callcontext.InternalTenantContext;
+import org.killbill.billing.util.audit.dao.AuditLogModelDao;
import org.killbill.billing.util.cache.Cachable.CacheType;
import org.killbill.billing.util.dao.AuditSqlDao;
-import org.killbill.billing.util.dao.NonEntityDao;
-
-import net.sf.ehcache.loader.CacheLoader;
+import org.skife.jdbi.v2.IDBI;
@Singleton
-public class AuditLogCacheLoader extends BaseCacheLoader implements CacheLoader {
+public class AuditLogCacheLoader extends BaseCacheLoader<Object, List<AuditLogModelDao>> {
private final AuditSqlDao auditSqlDao;
@Inject
- public AuditLogCacheLoader(final IDBI dbi, final NonEntityDao nonEntityDao) {
+ public AuditLogCacheLoader(final IDBI dbi) {
super();
this.auditSqlDao = dbi.onDemand(AuditSqlDao.class);
}
@@ -45,17 +46,8 @@ public class AuditLogCacheLoader extends BaseCacheLoader implements CacheLoader
}
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof String)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName());
- }
-
- final Object[] args = ((CacheLoaderArgument) argument).getArgs();
+ public List<AuditLogModelDao> compute(final Object key, final CacheLoaderArgument cacheLoaderArgument) {
+ final Object[] args = cacheLoaderArgument.getArgs();
final String tableName = (String) args[0];
final Long targetRecordId = (Long) args[1];
final InternalTenantContext internalTenantContext = (InternalTenantContext) args[2];
diff --git a/util/src/main/java/org/killbill/billing/util/cache/AuditLogViaHistoryCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/AuditLogViaHistoryCacheLoader.java
index b819148..113779d 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/AuditLogViaHistoryCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/AuditLogViaHistoryCacheLoader.java
@@ -1,7 +1,9 @@
/*
- * Copyright 2010-2012 Ning, Inc.
+ * Copyright 2010-2013 Ning, Inc.
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
- * Ning licenses this file to you under the Apache License, version 2.0
+ * The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
@@ -16,25 +18,24 @@
package org.killbill.billing.util.cache;
+import java.util.List;
+
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.skife.jdbi.v2.IDBI;
-
import org.killbill.billing.callcontext.InternalTenantContext;
+import org.killbill.billing.util.audit.dao.AuditLogModelDao;
import org.killbill.billing.util.cache.Cachable.CacheType;
import org.killbill.billing.util.dao.AuditSqlDao;
-import org.killbill.billing.util.dao.NonEntityDao;
-
-import net.sf.ehcache.loader.CacheLoader;
+import org.skife.jdbi.v2.IDBI;
@Singleton
-public class AuditLogViaHistoryCacheLoader extends BaseCacheLoader implements CacheLoader {
+public class AuditLogViaHistoryCacheLoader extends BaseCacheLoader<Object, List<AuditLogModelDao>> {
private final AuditSqlDao auditSqlDao;
@Inject
- public AuditLogViaHistoryCacheLoader(final IDBI dbi, final NonEntityDao nonEntityDao) {
+ public AuditLogViaHistoryCacheLoader(final IDBI dbi) {
super();
this.auditSqlDao = dbi.onDemand(AuditSqlDao.class);
}
@@ -45,17 +46,8 @@ public class AuditLogViaHistoryCacheLoader extends BaseCacheLoader implements Ca
}
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof String)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName());
- }
-
- final Object[] args = ((CacheLoaderArgument) argument).getArgs();
+ public List<AuditLogModelDao> compute(final Object key, final CacheLoaderArgument cacheLoaderArgument) {
+ final Object[] args = cacheLoaderArgument.getArgs();
final String tableName = (String) args[0];
final String historyTableName = (String) args[1];
final Long targetRecordId = (Long) args[2];
diff --git a/util/src/main/java/org/killbill/billing/util/cache/BaseCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/BaseCacheLoader.java
index c0044c6..973f9f0 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/BaseCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/BaseCacheLoader.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -18,77 +18,13 @@
package org.killbill.billing.util.cache;
-import java.util.Collection;
-import java.util.Map;
-
-import javax.inject.Inject;
-
import org.killbill.billing.util.cache.Cachable.CacheType;
-import net.sf.ehcache.CacheException;
-import net.sf.ehcache.Ehcache;
-import net.sf.ehcache.Status;
-import net.sf.ehcache.loader.CacheLoader;
-
-public abstract class BaseCacheLoader implements CacheLoader {
+public abstract class BaseCacheLoader<K, V> {
static final String EMPTY_VALUE_PLACEHOLDER = "__#VALEUR!__";
- private Status cacheLoaderStatus;
-
- @Inject
- public BaseCacheLoader() {
- this.cacheLoaderStatus = Status.STATUS_UNINITIALISED;
- }
-
public abstract CacheType getCacheType();
- @Override
- public abstract Object load(final Object key, final Object argument);
-
- @Override
- public Object load(final Object key) throws CacheException {
- throw new IllegalStateException("Method load is not implemented ");
- }
-
- @Override
- public Map loadAll(final Collection keys) {
- throw new IllegalStateException("Method loadAll is not implemented ");
- }
-
- @Override
- public Map loadAll(final Collection keys, final Object argument) {
- throw new IllegalStateException("Method loadAll is not implemented ");
- }
-
- @Override
- public String getName() {
- return this.getClass().getName();
- }
-
- @Override
- public CacheLoader clone(final Ehcache cache) throws CloneNotSupportedException {
- throw new IllegalStateException("Method clone is not implemented ");
- }
-
- @Override
- public void init() {
- this.cacheLoaderStatus = Status.STATUS_ALIVE;
- }
-
- @Override
- public void dispose() throws CacheException {
- cacheLoaderStatus = Status.STATUS_SHUTDOWN;
- }
-
- @Override
- public Status getStatus() {
- return cacheLoaderStatus;
- }
-
- protected void checkCacheLoaderStatus() {
- if (getStatus() != Status.STATUS_ALIVE) {
- throw new CacheException("CacheLoader is not available!");
- }
- }
+ public abstract V compute(final K key, final CacheLoaderArgument cacheLoaderArgument);
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/BaseIdCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/BaseIdCacheLoader.java
index c0329ae..e2cb993 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/BaseIdCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/BaseIdCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -18,40 +18,28 @@
package org.killbill.billing.util.cache;
import org.killbill.billing.ObjectType;
-import org.killbill.billing.util.cache.Cachable.CacheType;
import org.skife.jdbi.v2.Handle;
-public abstract class BaseIdCacheLoader extends BaseCacheLoader {
+public abstract class BaseIdCacheLoader<V> extends BaseCacheLoader<String, V> {
protected BaseIdCacheLoader() {
super();
}
- @Override
- public abstract CacheType getCacheType();
-
- protected abstract Object doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle);
+ protected abstract V doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle);
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof String)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName());
- }
-
+ public V compute(final String key, final CacheLoaderArgument cacheLoaderArgument) {
final String rawKey;
if (getCacheType().isKeyPrefixedWithTableName()) {
- final String[] parts = ((String) key).split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR);
+ final String[] parts = key.split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR);
rawKey = parts[1];
} else {
- rawKey = (String) key;
+ rawKey = key;
}
- final ObjectType objectType = ((CacheLoaderArgument) argument).getObjectType();
- final Handle handle = ((CacheLoaderArgument) argument).getHandle();
+
+ final ObjectType objectType = cacheLoaderArgument.getObjectType();
+ final Handle handle = cacheLoaderArgument.getHandle();
return doRetrieveOperation(rawKey, objectType, handle);
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/CacheController.java b/util/src/main/java/org/killbill/billing/util/cache/CacheController.java
index 2c6be1e..b2a9673 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/CacheController.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/CacheController.java
@@ -20,12 +20,8 @@ import org.killbill.billing.util.cache.Cachable.CacheType;
public interface CacheController<K, V> {
- void add(K key, V value);
-
V get(K key, CacheLoaderArgument objectType);
- V get(K key);
-
boolean remove(K key);
void putIfAbsent(final K key, V value);
diff --git a/util/src/main/java/org/killbill/billing/util/cache/CacheControllerDispatcherProvider.java b/util/src/main/java/org/killbill/billing/util/cache/CacheControllerDispatcherProvider.java
index f980ad7..302176c 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/CacheControllerDispatcherProvider.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/CacheControllerDispatcherProvider.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -18,9 +18,9 @@
package org.killbill.billing.util.cache;
-import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Set;
import javax.inject.Inject;
import javax.inject.Provider;
@@ -29,12 +29,8 @@ import org.killbill.billing.util.cache.Cachable.CacheType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Function;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableList;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
-import net.sf.ehcache.loader.CacheLoader;
// Build the abstraction layer between EhCache and Kill Bill
public class CacheControllerDispatcherProvider implements Provider<CacheControllerDispatcher> {
@@ -42,40 +38,31 @@ public class CacheControllerDispatcherProvider implements Provider<CacheControll
private static final Logger logger = LoggerFactory.getLogger(CacheControllerDispatcherProvider.class);
private final CacheManager cacheManager;
+ private final Set<BaseCacheLoader> cacheLoaders;
@Inject
- public CacheControllerDispatcherProvider(final CacheManager cacheManager) {
+ public CacheControllerDispatcherProvider(final CacheManager cacheManager,
+ final Set<BaseCacheLoader> cacheLoaders) {
this.cacheManager = cacheManager;
+ this.cacheLoaders = cacheLoaders;
}
@Override
public CacheControllerDispatcher get() {
final Map<CacheType, CacheController<Object, Object>> cacheControllers = new LinkedHashMap<CacheType, CacheController<Object, Object>>();
- for (final String cacheName : cacheManager.getCacheNames()) {
- final CacheType cacheType = CacheType.findByName(cacheName);
+ for (final BaseCacheLoader cacheLoader : cacheLoaders) {
+ final CacheType cacheType = cacheLoader.getCacheType();
- final Collection<EhCacheBasedCacheController<Object, Object>> cacheControllersForCacheName = getCacheControllersForCacheName(cacheName, cacheType);
- // EhCache supports multiple cache loaders per type, but not Kill Bill - take the first one
- if (cacheControllersForCacheName.size() > 0) {
- final EhCacheBasedCacheController<Object, Object> ehCacheBasedCacheController = cacheControllersForCacheName.iterator().next();
- cacheControllers.put(cacheType, ehCacheBasedCacheController);
+ final Ehcache cache = cacheManager.getEhcache(cacheType.getCacheName());
+ if (cache == null) {
+ logger.warn("Cache for cacheName='{}' not configured - check your ehcache.xml", cacheLoader.getCacheType().getCacheName());
+ continue;
}
- }
- return new CacheControllerDispatcher(cacheControllers);
- }
- private Collection<EhCacheBasedCacheController<Object, Object>> getCacheControllersForCacheName(final String name, final CacheType cacheType) {
- final Ehcache cache = cacheManager.getEhcache(name);
- if (cache == null) {
- logger.warn("No cache configured for name {}", name);
- return ImmutableList.<EhCacheBasedCacheController<Object, Object>>of();
+ final CacheController<Object, Object> ehCacheBasedCacheController = new EhCacheBasedCacheController<Object, Object>(cache, cacheLoader);
+ cacheControllers.put(cacheType, ehCacheBasedCacheController);
}
- // The CacheLoaders were registered in EhCacheCacheManagerProvider
- return Collections2.transform(cache.getRegisteredCacheLoaders(), new Function<CacheLoader, EhCacheBasedCacheController<Object, Object>>() {
- @Override
- public EhCacheBasedCacheController<Object, Object> apply(final CacheLoader input) {
- return new EhCacheBasedCacheController<Object, Object>(cache, cacheType);
- }
- });
+
+ return new CacheControllerDispatcher(cacheControllers);
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/CacheLoaderArgument.java b/util/src/main/java/org/killbill/billing/util/cache/CacheLoaderArgument.java
index f559c0f..1724c59 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/CacheLoaderArgument.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/CacheLoaderArgument.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -18,6 +18,8 @@
package org.killbill.billing.util.cache;
+import java.util.Arrays;
+
import javax.annotation.Nullable;
import org.killbill.billing.ObjectType;
@@ -61,4 +63,14 @@ public class CacheLoaderArgument {
public Handle getHandle() {
return handle;
}
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("CacheLoaderArgument{");
+ sb.append("objectType=").append(objectType);
+ sb.append(", args=").append(Arrays.toString(args));
+ sb.append(", internalTenantContext=").append(internalTenantContext);
+ sb.append('}');
+ return sb.toString();
+ }
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/EhCacheBasedCacheController.java b/util/src/main/java/org/killbill/billing/util/cache/EhCacheBasedCacheController.java
index 08d04d2..298de85 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/EhCacheBasedCacheController.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/EhCacheBasedCacheController.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2012 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -18,69 +18,95 @@
package org.killbill.billing.util.cache;
-import javax.annotation.Nullable;
-
import org.killbill.billing.util.cache.Cachable.CacheType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import net.sf.ehcache.CacheException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
public class EhCacheBasedCacheController<K, V> implements CacheController<K, V> {
+ private static final Logger logger = LoggerFactory.getLogger(EhCacheBasedCacheController.class);
+
private final Ehcache cache;
- private final CacheType cacheType;
+ private final BaseCacheLoader<K, V> baseCacheLoader;
- public EhCacheBasedCacheController(final Ehcache cache, final CacheType cacheType) {
+ public EhCacheBasedCacheController(final Ehcache cache, final BaseCacheLoader<K, V> baseCacheLoader) {
this.cache = cache;
- this.cacheType = cacheType;
+ this.baseCacheLoader = baseCacheLoader;
}
@Override
- public void add(final K key, final V value) {
- cache.putIfAbsent(new Element(key, value));
- }
+ public V get(final K key, final CacheLoaderArgument cacheLoaderArgument) {
+ final V value;
+ if (!cache.isKeyInCache(key)) {
+ value = computeAndCacheValue(key, cacheLoaderArgument);
+ } else {
+ final Element element = cache.get(key);
+ if (element == null) {
+ value = null;
+ } else if (element.isExpired()) {
+ value = computeAndCacheValue(key, cacheLoaderArgument);
+ } else {
+ value = (V) element.getObjectValue();
+ }
+ }
- @Override
- public V get(final K key, @Nullable final CacheLoaderArgument cacheLoaderArgument) {
- return getWithOrWithoutCacheLoaderArgument(key, cacheLoaderArgument);
+ if (value == null || value.equals(BaseCacheLoader.EMPTY_VALUE_PLACEHOLDER)) {
+ return null;
+ } else {
+ return value;
+ }
}
@Override
- public V get(final K key) {
- return getWithOrWithoutCacheLoaderArgument(key, null);
- }
-
- public void putIfAbsent(final K key, V value) {
- final Element element = new Element(key, value);
- cache.putIfAbsent(element);
+ public void putIfAbsent(final K key, final V value) {
+ cache.putIfAbsent(new Element(key, value));
}
@Override
public boolean remove(final K key) {
- return cache.remove(key);
+ if (cache.isKeyInCache(key)) {
+ cache.remove(key);
+ return true;
+ } else {
+ return false;
+ }
}
@Override
- public int size() {
- return cache.getSize();
+ public void removeAll() {
+ cache.removeAll();
}
@Override
- public void removeAll() {
- cache.removeAll();
+ public int size() {
+ return cache.getSize();
}
@Override
public CacheType getCacheType() {
- return cacheType;
+ return baseCacheLoader.getCacheType();
}
- private V getWithOrWithoutCacheLoaderArgument(final K key, @Nullable final CacheLoaderArgument cacheLoaderArgument) {
- final Element element = cacheLoaderArgument != null ? cache.getWithLoader(key, null, cacheLoaderArgument) : cache.get(key);
- if (element == null || element.getObjectValue() == null || element.getObjectValue().equals(BaseCacheLoader.EMPTY_VALUE_PLACEHOLDER)) {
+ private V computeAndCacheValue(final K key, final CacheLoaderArgument cacheLoaderArgument) {
+ final V value;
+ try {
+ value = baseCacheLoader.compute(key, cacheLoaderArgument);
+ } catch (final Exception e) {
+ logger.warn("Unable to compute cached value for key='{}' and cacheLoaderArgument='{}'", key, cacheLoaderArgument);
+ throw new CacheException(e);
+ }
+
+ if (value == null) {
return null;
}
- return (V) element.getObjectValue();
- }
+ // Race condition, we may compute it for nothing
+ cache.putIfAbsent(new Element(key, value));
+
+ return value;
+ }
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/EhCacheCacheManagerProvider.java b/util/src/main/java/org/killbill/billing/util/cache/EhCacheCacheManagerProvider.java
index 305e6f2..9ecb6bb 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/EhCacheCacheManagerProvider.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/EhCacheCacheManagerProvider.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2012 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -21,8 +21,7 @@ package org.killbill.billing.util.cache;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.LinkedList;
+import java.util.Set;
import javax.inject.Inject;
import javax.inject.Provider;
@@ -37,7 +36,6 @@ import com.codahale.metrics.ehcache.InstrumentedEhcache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
-import net.sf.ehcache.loader.CacheLoader;
// EhCache specific provider
public class EhCacheCacheManagerProvider implements Provider<CacheManager> {
@@ -46,43 +44,15 @@ public class EhCacheCacheManagerProvider implements Provider<CacheManager> {
private final MetricRegistry metricRegistry;
private final EhCacheConfig cacheConfig;
- private final Collection<BaseCacheLoader> cacheLoaders = new LinkedList<BaseCacheLoader>();
+ private final Set<BaseCacheLoader> cacheLoaders;
@Inject
public EhCacheCacheManagerProvider(final MetricRegistry metricRegistry,
final EhCacheConfig cacheConfig,
- final ImmutableAccountCacheLoader accountCacheLoader,
- final AccountBCDCacheLoader accountBCDCacheLoader,
- final RecordIdCacheLoader recordIdCacheLoader,
- final AccountRecordIdCacheLoader accountRecordIdCacheLoader,
- final TenantRecordIdCacheLoader tenantRecordIdCacheLoader,
- final ObjectIdCacheLoader objectIdCacheLoader,
- final AuditLogCacheLoader auditLogCacheLoader,
- final AuditLogViaHistoryCacheLoader auditLogViaHistoryCacheLoader,
- final TenantCatalogCacheLoader tenantCatalogCacheLoader,
- final TenantConfigCacheLoader tenantConfigCacheLoader,
- final TenantOverdueConfigCacheLoader tenantOverdueConfigCacheLoader,
- final TenantKVCacheLoader tenantKVCacheLoader,
- final TenantCacheLoader tenantCacheLoader,
- final OverriddenPlanCacheLoader overriddenPlanCacheLoader,
- final TenantStateMachineConfigCacheLoader tenantStateMachineConfigCacheLoader) {
+ final Set<BaseCacheLoader> cacheLoaders) {
this.metricRegistry = metricRegistry;
this.cacheConfig = cacheConfig;
- cacheLoaders.add(accountCacheLoader);
- cacheLoaders.add(accountBCDCacheLoader);
- cacheLoaders.add(recordIdCacheLoader);
- cacheLoaders.add(accountRecordIdCacheLoader);
- cacheLoaders.add(tenantRecordIdCacheLoader);
- cacheLoaders.add(objectIdCacheLoader);
- cacheLoaders.add(auditLogCacheLoader);
- cacheLoaders.add(auditLogViaHistoryCacheLoader);
- cacheLoaders.add(tenantCatalogCacheLoader);
- cacheLoaders.add(tenantConfigCacheLoader);
- cacheLoaders.add(tenantOverdueConfigCacheLoader);
- cacheLoaders.add(tenantKVCacheLoader);
- cacheLoaders.add(tenantCacheLoader);
- cacheLoaders.add(overriddenPlanCacheLoader);
- cacheLoaders.add(tenantStateMachineConfigCacheLoader);
+ this.cacheLoaders = cacheLoaders;
}
@Override
@@ -98,8 +68,6 @@ public class EhCacheCacheManagerProvider implements Provider<CacheManager> {
}
for (final BaseCacheLoader cacheLoader : cacheLoaders) {
- cacheLoader.init();
-
final Ehcache cache = cacheManager.getEhcache(cacheLoader.getCacheType().getCacheName());
if (cache == null) {
@@ -107,12 +75,6 @@ public class EhCacheCacheManagerProvider implements Provider<CacheManager> {
continue;
}
- // Make sure we start from a clean state - this is mainly useful for tests
- for (final CacheLoader existingCacheLoader : cache.getRegisteredCacheLoaders()) {
- cache.unregisterCacheLoader(existingCacheLoader);
- }
- cache.registerCacheLoader(cacheLoader);
-
// Instrument the cache
final Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
try {
@@ -121,6 +83,7 @@ public class EhCacheCacheManagerProvider implements Provider<CacheManager> {
logger.warn("Unable to instrument cache {}: {}", cache.getName(), e.getMessage());
}
}
+
return cacheManager;
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/ImmutableAccountCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/ImmutableAccountCacheLoader.java
index 866c44e..8634a01 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/ImmutableAccountCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/ImmutableAccountCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -17,10 +17,11 @@
package org.killbill.billing.util.cache;
+import org.killbill.billing.account.api.ImmutableAccountData;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.util.cache.Cachable.CacheType;
-public class ImmutableAccountCacheLoader extends BaseCacheLoader {
+public class ImmutableAccountCacheLoader extends BaseCacheLoader<Long, ImmutableAccountData> {
@Override
public CacheType getCacheType() {
@@ -28,30 +29,18 @@ public class ImmutableAccountCacheLoader extends BaseCacheLoader {
}
@Override
- public Object load(final Object key, final Object argument) {
-
- checkCacheLoaderStatus();
-
- if (!(key instanceof Long)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
-
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected argument type of " + argument.getClass().getName());
- }
-
- final CacheLoaderArgument cacheLoaderArgument = (CacheLoaderArgument) argument;
-
+ public ImmutableAccountData compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) {
if (cacheLoaderArgument.getArgs() == null ||
!(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) {
throw new IllegalArgumentException("Missing LoaderCallback from the arguments ");
}
final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0];
- return callback.loadAccount((Long) key, cacheLoaderArgument.getInternalTenantContext());
+ return callback.loadAccount(key, cacheLoaderArgument.getInternalTenantContext());
}
public interface LoaderCallback {
- Object loadAccount(final Long recordId, final InternalTenantContext context);
+
+ ImmutableAccountData loadAccount(final Long recordId, final InternalTenantContext context);
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/ObjectIdCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/ObjectIdCacheLoader.java
index fd357ab..cda30b6 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/ObjectIdCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/ObjectIdCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -17,6 +17,8 @@
package org.killbill.billing.util.cache;
+import java.util.UUID;
+
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -25,10 +27,8 @@ import org.killbill.billing.util.cache.Cachable.CacheType;
import org.killbill.billing.util.dao.NonEntityDao;
import org.skife.jdbi.v2.Handle;
-import net.sf.ehcache.loader.CacheLoader;
-
@Singleton
-public class ObjectIdCacheLoader extends BaseIdCacheLoader implements CacheLoader {
+public class ObjectIdCacheLoader extends BaseIdCacheLoader<UUID> {
private final NonEntityDao nonEntityDao;
@@ -44,7 +44,7 @@ public class ObjectIdCacheLoader extends BaseIdCacheLoader implements CacheLoade
}
@Override
- protected Object doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle) {
+ protected UUID doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle) {
final Long recordId = Long.valueOf(rawKey);
return nonEntityDao.retrieveIdFromObjectInTransaction(recordId, objectType, null, handle);
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/OverriddenPlanCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/OverriddenPlanCacheLoader.java
index 52c4a07..79d73b8 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/OverriddenPlanCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/OverriddenPlanCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -22,13 +22,14 @@ import javax.inject.Singleton;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.catalog.api.CatalogApiException;
+import org.killbill.billing.catalog.api.Plan;
import org.killbill.billing.catalog.api.StaticCatalog;
import org.killbill.billing.util.cache.Cachable.CacheType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
-public class OverriddenPlanCacheLoader extends BaseCacheLoader {
+public class OverriddenPlanCacheLoader extends BaseCacheLoader<String, Plan> {
private final Logger log = LoggerFactory.getLogger(OverriddenPlanCacheLoader.class);
@@ -43,18 +44,7 @@ public class OverriddenPlanCacheLoader extends BaseCacheLoader {
}
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof String)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected argument type of " + argument.getClass().getName());
- }
-
-
- final CacheLoaderArgument cacheLoaderArgument = (CacheLoaderArgument) argument;
+ public Plan compute(final String key, final CacheLoaderArgument cacheLoaderArgument) {
if (cacheLoaderArgument.getArgs() == null || cacheLoaderArgument.getArgs().length != 2) {
throw new IllegalArgumentException("Invalid arguments for overridden plans");
}
@@ -66,11 +56,10 @@ public class OverriddenPlanCacheLoader extends BaseCacheLoader {
throw new IllegalArgumentException("Invalid arguments for overridden plans: missing catalog from argument");
}
-
- final String planName = (String) key;
+ final String planName = key;
final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0];
final StaticCatalog catalog = (StaticCatalog) cacheLoaderArgument.getArgs()[1];
- final InternalTenantContext internalTenantContext = ((CacheLoaderArgument) argument).getInternalTenantContext();
+ final InternalTenantContext internalTenantContext = cacheLoaderArgument.getInternalTenantContext();
try {
log.info("Loading overridden plan {} for tenant {}", planName, internalTenantContext.getTenantRecordId());
@@ -82,6 +71,7 @@ public class OverriddenPlanCacheLoader extends BaseCacheLoader {
}
public interface LoaderCallback {
- public Object loadPlan(final String planName, final StaticCatalog catalog, final InternalTenantContext context) throws CatalogApiException;
+
+ public Plan loadPlan(final String planName, final StaticCatalog catalog, final InternalTenantContext context) throws CatalogApiException;
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/RecordIdCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/RecordIdCacheLoader.java
index 08efe2e..a7027a8 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/RecordIdCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/RecordIdCacheLoader.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2012 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -28,10 +28,8 @@ import org.killbill.billing.util.cache.Cachable.CacheType;
import org.killbill.billing.util.dao.NonEntityDao;
import org.skife.jdbi.v2.Handle;
-import net.sf.ehcache.loader.CacheLoader;
-
@Singleton
-public class RecordIdCacheLoader extends BaseIdCacheLoader implements CacheLoader {
+public class RecordIdCacheLoader extends BaseIdCacheLoader<Long> {
private final NonEntityDao nonEntityDao;
@@ -47,7 +45,7 @@ public class RecordIdCacheLoader extends BaseIdCacheLoader implements CacheLoade
}
@Override
- protected Object doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle) {
+ protected Long doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle) {
return nonEntityDao.retrieveRecordIdFromObjectInTransaction(UUID.fromString(rawKey), objectType, null, handle);
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/TenantCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/TenantCacheLoader.java
index bacafa8..1ed03a5 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/TenantCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/TenantCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -26,7 +26,7 @@ import org.killbill.billing.tenant.api.TenantInternalApi;
import org.killbill.billing.util.cache.Cachable.CacheType;
@Singleton
-public class TenantCacheLoader extends BaseCacheLoader {
+public class TenantCacheLoader extends BaseCacheLoader<String, Tenant> {
private final TenantInternalApi tenantApi;
@@ -42,19 +42,10 @@ public class TenantCacheLoader extends BaseCacheLoader {
}
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof String)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName());
- }
-
+ public Tenant compute(final String key, final CacheLoaderArgument cacheLoaderArgument) {
try {
- return tenantApi.getTenantByApiKey((String) key);
- } catch (TenantApiException e) {
+ return tenantApi.getTenantByApiKey(key);
+ } catch (final TenantApiException e) {
throw new IllegalStateException("TenantCacheLoader cannot find value for key " + key);
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/TenantCatalogCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/TenantCatalogCacheLoader.java
index b3f9305..03a4ee3 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/TenantCatalogCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/TenantCatalogCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -23,6 +23,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.killbill.billing.callcontext.InternalTenantContext;
+import org.killbill.billing.catalog.api.Catalog;
import org.killbill.billing.catalog.api.CatalogApiException;
import org.killbill.billing.tenant.api.TenantInternalApi;
import org.killbill.billing.util.cache.Cachable.CacheType;
@@ -30,7 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
-public class TenantCatalogCacheLoader extends BaseCacheLoader {
+public class TenantCatalogCacheLoader extends BaseCacheLoader<Long, Catalog> {
private final Logger log = LoggerFactory.getLogger(TenantCatalogCacheLoader.class);
@@ -48,19 +49,9 @@ public class TenantCatalogCacheLoader extends BaseCacheLoader {
}
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof Long)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected argument type of " + argument.getClass().getName());
- }
-
- final Long tenantRecordId = (Long) key;
+ public Catalog compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) {
+ final Long tenantRecordId = key;
final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId);
- final CacheLoaderArgument cacheLoaderArgument = (CacheLoaderArgument) argument;
if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) {
throw new IllegalArgumentException("Missing LoaderCallback from the arguments ");
@@ -80,6 +71,7 @@ public class TenantCatalogCacheLoader extends BaseCacheLoader {
}
public interface LoaderCallback {
- public Object loadCatalog(final List<String> catalogXMLs, final Long tenantRecordId) throws CatalogApiException;
+
+ public Catalog loadCatalog(final List<String> catalogXMLs, final Long tenantRecordId) throws CatalogApiException;
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/TenantConfigCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/TenantConfigCacheLoader.java
index caced95..d71ad0d 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/TenantConfigCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/TenantConfigCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -25,11 +25,12 @@ import javax.inject.Singleton;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.tenant.api.TenantInternalApi;
import org.killbill.billing.util.cache.Cachable.CacheType;
+import org.killbill.billing.util.config.tenant.PerTenantConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
-public class TenantConfigCacheLoader extends BaseCacheLoader {
+public class TenantConfigCacheLoader extends BaseCacheLoader<Long, PerTenantConfig> {
private final Logger log = LoggerFactory.getLogger(TenantConfigCacheLoader.class);
@@ -47,19 +48,9 @@ public class TenantConfigCacheLoader extends BaseCacheLoader {
}
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof Long)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected argument type of " + argument.getClass().getName());
- }
-
- final Long tenantRecordId = (Long) key;
+ public PerTenantConfig compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) {
+ final Long tenantRecordId = key;
final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId);
- final CacheLoaderArgument cacheLoaderArgument = (CacheLoaderArgument) argument;
if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) {
throw new IllegalArgumentException("Missing LoaderCallback from the arguments ");
@@ -77,7 +68,7 @@ public class TenantConfigCacheLoader extends BaseCacheLoader {
}
public interface LoaderCallback {
- public Object loadConfig(final String inputJson) throws IOException;
- }
+ public PerTenantConfig loadConfig(final String inputJson) throws IOException;
+ }
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/TenantKVCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/TenantKVCacheLoader.java
index a949445..5dcbca5 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/TenantKVCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/TenantKVCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -27,7 +27,7 @@ import org.killbill.billing.tenant.api.TenantInternalApi;
import org.killbill.billing.util.cache.Cachable.CacheType;
@Singleton
-public class TenantKVCacheLoader extends BaseCacheLoader {
+public class TenantKVCacheLoader extends BaseCacheLoader<String, String> {
private final TenantInternalApi tenantApi;
@@ -43,16 +43,8 @@ public class TenantKVCacheLoader extends BaseCacheLoader {
}
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof String)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName());
- }
- final String[] parts = ((String) key).split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR);
+ public String compute(final String key, final CacheLoaderArgument cacheLoaderArgument) {
+ final String[] parts = key.split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR);
final String rawKey = parts[0];
final String tenantRecordId = parts[1];
diff --git a/util/src/main/java/org/killbill/billing/util/cache/TenantOverdueConfigCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/TenantOverdueConfigCacheLoader.java
index 81ebe00..6c95814 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/TenantOverdueConfigCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/TenantOverdueConfigCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -22,13 +22,14 @@ import javax.inject.Singleton;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.overdue.api.OverdueApiException;
+import org.killbill.billing.overdue.api.OverdueConfig;
import org.killbill.billing.tenant.api.TenantInternalApi;
import org.killbill.billing.util.cache.Cachable.CacheType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
-public class TenantOverdueConfigCacheLoader extends BaseCacheLoader {
+public class TenantOverdueConfigCacheLoader extends BaseCacheLoader<Long, Object> {
private static final Logger log = LoggerFactory.getLogger(TenantOverdueConfigCacheLoader.class);
@@ -46,19 +47,9 @@ public class TenantOverdueConfigCacheLoader extends BaseCacheLoader {
}
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof Long)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected argument type of " + argument.getClass().getName());
- }
-
- final Long tenantRecordId = (Long) key;
+ public Object compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) {
+ final Long tenantRecordId = key;
final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId);
- final CacheLoaderArgument cacheLoaderArgument = (CacheLoaderArgument) argument;
if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) {
throw new IllegalArgumentException("Missing LoaderCallback from the arguments");
@@ -81,6 +72,6 @@ public class TenantOverdueConfigCacheLoader extends BaseCacheLoader {
public interface LoaderCallback {
- public Object loadOverdueConfig(final String overdueConfigXML) throws OverdueApiException;
+ public OverdueConfig loadOverdueConfig(final String overdueConfigXML) throws OverdueApiException;
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/TenantRecordIdCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/TenantRecordIdCacheLoader.java
index 17a62af..1144e59 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/TenantRecordIdCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/TenantRecordIdCacheLoader.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -28,10 +28,8 @@ import org.killbill.billing.util.cache.Cachable.CacheType;
import org.killbill.billing.util.dao.NonEntityDao;
import org.skife.jdbi.v2.Handle;
-import net.sf.ehcache.loader.CacheLoader;
-
@Singleton
-public class TenantRecordIdCacheLoader extends BaseIdCacheLoader implements CacheLoader {
+public class TenantRecordIdCacheLoader extends BaseIdCacheLoader<Long> {
private final NonEntityDao nonEntityDao;
@@ -47,7 +45,7 @@ public class TenantRecordIdCacheLoader extends BaseIdCacheLoader implements Cach
}
@Override
- protected Object doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle) {
+ protected Long doRetrieveOperation(final String rawKey, final ObjectType objectType, final Handle handle) {
return nonEntityDao.retrieveTenantRecordIdFromObjectInTransaction(UUID.fromString(rawKey), objectType, null, handle);
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/cache/TenantStateMachineConfigCacheLoader.java b/util/src/main/java/org/killbill/billing/util/cache/TenantStateMachineConfigCacheLoader.java
index c6d5489..a05db1f 100644
--- a/util/src/main/java/org/killbill/billing/util/cache/TenantStateMachineConfigCacheLoader.java
+++ b/util/src/main/java/org/killbill/billing/util/cache/TenantStateMachineConfigCacheLoader.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Groupon, Inc
- * Copyright 2016 The Billing Project, LLC
+ * Copyright 2016-2017 Groupon, Inc
+ * Copyright 2016-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -32,7 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
-public class TenantStateMachineConfigCacheLoader extends BaseCacheLoader {
+public class TenantStateMachineConfigCacheLoader extends BaseCacheLoader<String, Object> {
private static final Pattern PATTERN = Pattern.compile(TenantKey.PLUGIN_PAYMENT_STATE_MACHINE_.toString() + "(.*)");
private static final Logger log = LoggerFactory.getLogger(TenantStateMachineConfigCacheLoader.class);
@@ -51,16 +51,7 @@ public class TenantStateMachineConfigCacheLoader extends BaseCacheLoader {
}
@Override
- public Object load(final Object key, final Object argument) {
- checkCacheLoaderStatus();
-
- if (!(key instanceof String)) {
- throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
- }
- if (!(argument instanceof CacheLoaderArgument)) {
- throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName());
- }
-
+ public Object compute(final String key, final CacheLoaderArgument cacheLoaderArgument) {
final String[] parts = ((String) key).split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR);
final String rawKey = parts[0];
final Matcher matcher = PATTERN.matcher(rawKey);
@@ -70,7 +61,6 @@ public class TenantStateMachineConfigCacheLoader extends BaseCacheLoader {
final String pluginName = matcher.group(1);
final String tenantRecordId = parts[1];
- final CacheLoaderArgument cacheLoaderArgument = (CacheLoaderArgument) argument;
final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0];
final InternalTenantContext internalTenantContext = new InternalTenantContext(Long.valueOf(tenantRecordId));
diff --git a/util/src/main/java/org/killbill/billing/util/config/tenant/CacheConfig.java b/util/src/main/java/org/killbill/billing/util/config/tenant/CacheConfig.java
index 1338b65..a1956d2 100644
--- a/util/src/main/java/org/killbill/billing/util/config/tenant/CacheConfig.java
+++ b/util/src/main/java/org/killbill/billing/util/config/tenant/CacheConfig.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2016 Groupon, Inc
- * Copyright 2014-2016 The Billing Project, LLC
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
@@ -59,7 +59,7 @@ public class CacheConfig {
private CacheLoaderArgument initializeCacheLoaderArgument() {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
- public Object loadConfig(@Nullable final String inputJson) throws IOException {
+ public PerTenantConfig loadConfig(@Nullable final String inputJson) throws IOException {
return inputJson != null ? objectMapper.readValue(inputJson, PerTenantConfig.class) : new PerTenantConfig();
}
};
@@ -69,5 +69,4 @@ public class CacheConfig {
final InternalTenantContext notUsed = null;
return new CacheLoaderArgument(irrelevant, args, notUsed);
}
-
}
diff --git a/util/src/main/java/org/killbill/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java b/util/src/main/java/org/killbill/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java
index 872ba10..e4acb71 100644
--- a/util/src/main/java/org/killbill/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java
+++ b/util/src/main/java/org/killbill/billing/util/entity/dao/EntitySqlDaoWrapperInvocationHandler.java
@@ -345,19 +345,19 @@ public class EntitySqlDaoWrapperInvocationHandler<S extends EntitySqlDao<M, E>,
private void populateCacheOnGetByIdInvocation(M model) {
final CacheController<Object, Object> cacheRecordId = cacheControllerDispatcher.getCacheController(CacheType.RECORD_ID);
- cacheRecordId.add(getKey(model.getId().toString(), CacheType.RECORD_ID, model.getTableName()), model.getRecordId());
+ cacheRecordId.putIfAbsent(getKey(model.getId().toString(), CacheType.RECORD_ID, model.getTableName()), model.getRecordId());
final CacheController<Object, Object> cacheObjectId = cacheControllerDispatcher.getCacheController(CacheType.OBJECT_ID);
- cacheObjectId.add(getKey(model.getRecordId().toString(), CacheType.OBJECT_ID, model.getTableName()), model.getId());
+ cacheObjectId.putIfAbsent(getKey(model.getRecordId().toString(), CacheType.OBJECT_ID, model.getTableName()), model.getId());
if (model.getTenantRecordId() != null) {
final CacheController<Object, Object> cacheTenantRecordId = cacheControllerDispatcher.getCacheController(CacheType.TENANT_RECORD_ID);
- cacheTenantRecordId.add(getKey(model.getId().toString(), CacheType.TENANT_RECORD_ID, model.getTableName()), model.getTenantRecordId());
+ cacheTenantRecordId.putIfAbsent(getKey(model.getId().toString(), CacheType.TENANT_RECORD_ID, model.getTableName()), model.getTenantRecordId());
}
if (model.getAccountRecordId() != null) {
final CacheController<Object, Object> cacheAccountRecordId = cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID);
- cacheAccountRecordId.add(getKey(model.getId().toString(), CacheType.ACCOUNT_RECORD_ID, model.getTableName()), model.getAccountRecordId());
+ cacheAccountRecordId.putIfAbsent(getKey(model.getId().toString(), CacheType.ACCOUNT_RECORD_ID, model.getTableName()), model.getAccountRecordId());
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/glue/CacheModule.java b/util/src/main/java/org/killbill/billing/util/glue/CacheModule.java
index 5a3b660..4ea728c 100644
--- a/util/src/main/java/org/killbill/billing/util/glue/CacheModule.java
+++ b/util/src/main/java/org/killbill/billing/util/glue/CacheModule.java
@@ -19,12 +19,29 @@
package org.killbill.billing.util.glue;
import org.killbill.billing.platform.api.KillbillConfigSource;
+import org.killbill.billing.util.cache.AccountBCDCacheLoader;
+import org.killbill.billing.util.cache.AccountRecordIdCacheLoader;
+import org.killbill.billing.util.cache.AuditLogCacheLoader;
+import org.killbill.billing.util.cache.AuditLogViaHistoryCacheLoader;
+import org.killbill.billing.util.cache.BaseCacheLoader;
import org.killbill.billing.util.cache.CacheControllerDispatcher;
import org.killbill.billing.util.cache.CacheControllerDispatcherProvider;
import org.killbill.billing.util.cache.EhCacheCacheManagerProvider;
+import org.killbill.billing.util.cache.ImmutableAccountCacheLoader;
+import org.killbill.billing.util.cache.ObjectIdCacheLoader;
+import org.killbill.billing.util.cache.OverriddenPlanCacheLoader;
+import org.killbill.billing.util.cache.RecordIdCacheLoader;
+import org.killbill.billing.util.cache.TenantCacheLoader;
+import org.killbill.billing.util.cache.TenantCatalogCacheLoader;
+import org.killbill.billing.util.cache.TenantConfigCacheLoader;
+import org.killbill.billing.util.cache.TenantKVCacheLoader;
+import org.killbill.billing.util.cache.TenantOverdueConfigCacheLoader;
+import org.killbill.billing.util.cache.TenantRecordIdCacheLoader;
+import org.killbill.billing.util.cache.TenantStateMachineConfigCacheLoader;
import org.killbill.billing.util.config.definition.EhCacheConfig;
import org.skife.config.ConfigurationObjectFactory;
+import com.google.inject.multibindings.Multibinder;
import net.sf.ehcache.CacheManager;
public class CacheModule extends KillBillModule {
@@ -43,5 +60,22 @@ public class CacheModule extends KillBillModule {
// Kill Bill generic cache dispatcher
bind(CacheControllerDispatcher.class).toProvider(CacheControllerDispatcherProvider.class).asEagerSingleton();
+
+ final Multibinder<BaseCacheLoader> resultSetMapperSetBinder = Multibinder.newSetBinder(binder(), BaseCacheLoader.class);
+ resultSetMapperSetBinder.addBinding().to(ImmutableAccountCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(AccountBCDCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(RecordIdCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(AccountRecordIdCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(TenantRecordIdCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(ObjectIdCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(AuditLogCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(AuditLogViaHistoryCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(TenantCatalogCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(TenantConfigCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(TenantOverdueConfigCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(TenantKVCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(TenantCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(OverriddenPlanCacheLoader.class).asEagerSingleton();
+ resultSetMapperSetBinder.addBinding().to(TenantStateMachineConfigCacheLoader.class).asEagerSingleton();
}
}