diff --git a/tenant/src/main/java/org/killbill/billing/tenant/api/user/DefaultTenantUserApi.java b/tenant/src/main/java/org/killbill/billing/tenant/api/user/DefaultTenantUserApi.java
index 6b13626..9ff60e6 100644
--- a/tenant/src/main/java/org/killbill/billing/tenant/api/user/DefaultTenantUserApi.java
+++ b/tenant/src/main/java/org/killbill/billing/tenant/api/user/DefaultTenantUserApi.java
@@ -1,7 +1,9 @@
/*
* Copyright 2010-2013 Ning, Inc.
+ * Copyright 2014-2015 Groupon, Inc
+ * Copyright 2014-2015 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:
*
@@ -49,18 +51,18 @@ public class DefaultTenantUserApi implements TenantUserApi {
//
// Most System TenantKey are cached in the 'tenant-kv' cache owned by the Tenant module; however
// - xml value keys such as OVERDUE_CONFIG, CATALOG are cached at a higher level to avoid reconstruct the objects from xml
- // - any keys that require multiple values would not be cached (today we only have CATALOG and this is not cached in 'tenant-kv' cache,
- // so that means all other TenantKey could be cached at this level.
+ // - any keys that require multiple values would not be cached (today we only have CATALOG and this is not cached in 'tenant-kv' cache),
+ // so that means all other TenantKey could be cached at this level
//
// CACHED_TENANT_KEY is not exposed in the API and is hardcoded here since this is really a implementation choice.
//
public static final Iterable<TenantKey> CACHED_TENANT_KEY = ImmutableList.<TenantKey>builder()
- .add(TenantKey.CATALOG_TRANSLATION_)
- .add(TenantKey.INVOICE_MP_TEMPLATE)
- .add(TenantKey.INVOICE_TEMPLATE)
- .add(TenantKey.INVOICE_TRANSLATION_)
- .add(TenantKey.PLUGIN_CONFIG_)
- .add(TenantKey.PUSH_NOTIFICATION_CB).build();
+ .add(TenantKey.CATALOG_TRANSLATION_)
+ .add(TenantKey.INVOICE_MP_TEMPLATE)
+ .add(TenantKey.INVOICE_TEMPLATE)
+ .add(TenantKey.INVOICE_TRANSLATION_)
+ .add(TenantKey.PLUGIN_CONFIG_)
+ .add(TenantKey.PUSH_NOTIFICATION_CB).build();
private final TenantDao tenantDao;
private final InternalCallContextFactory internalCallContextFactory;
@@ -71,7 +73,6 @@ public class DefaultTenantUserApi implements TenantUserApi {
this.tenantDao = tenantDao;
this.internalCallContextFactory = internalCallContextFactory;
this.tenantKVCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_KV);
-
}
@Override
@@ -107,9 +108,7 @@ public class DefaultTenantUserApi implements TenantUserApi {
}
@Override
- public List<String> getTenantValuesForKey(final String key, final TenantContext context)
- throws TenantApiException {
-
+ public List<String> getTenantValuesForKey(final String key, final TenantContext context) throws TenantApiException {
final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(context);
final String value = getCachedTenantValueForKey(key, internalContext);
if (value != null) {
@@ -119,21 +118,17 @@ public class DefaultTenantUserApi implements TenantUserApi {
}
@Override
- public void addTenantKeyValue(final String key, final String value, final CallContext context)
- throws TenantApiException {
-
+ public void addTenantKeyValue(final String key, final String value, final CallContext context) throws TenantApiException {
+ // Invalidate tenantKVCache after we store (to avoid race conditions). Multi-node invalidation will follow the TenantBroadcast pattern
final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(context);
final String tenantKey = getCacheKeyName(key, internalContext);
tenantDao.addTenantKeyValue(key, value, isSingleValueKey(key), internalContext);
- // Invalidate tenantKVCache before we store. Multi-node invalidation will follow the TenantBroadcast pattern
tenantKVCache.remove(tenantKey);
}
@Override
- public void deleteTenantKey(final String key, final CallContext context)
- throws TenantApiException {
-
- // Invalidate tenantKVCache before we store. Multi-node invalidation will follow the TenantBroadcast pattern
+ public void deleteTenantKey(final String key, final CallContext context) throws TenantApiException {
+ // Invalidate tenantKVCache after we delete (to avoid race conditions). Multi-node invalidation will follow the TenantBroadcast pattern
final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(context);
final String tenantKey = getCacheKeyName(key, internalContext);
tenantDao.deleteTenantKey(key, internalContext);
@@ -141,7 +136,6 @@ public class DefaultTenantUserApi implements TenantUserApi {
}
private String getCachedTenantValueForKey(final String key, final InternalTenantContext internalContext) {
-
if (!isCachedInTenantKVCache(key)) {
return null;
}
@@ -165,7 +159,6 @@ public class DefaultTenantUserApi implements TenantUserApi {
}).orNull() != null;
}
-
private boolean isCachedInTenantKVCache(final String key) {
return Iterables.tryFind(CACHED_TENANT_KEY, new Predicate<TenantKey>() {
@Override
diff --git a/tenant/src/test/java/org/killbill/billing/tenant/api/user/TestDefaultTenantUserApi.java b/tenant/src/test/java/org/killbill/billing/tenant/api/user/TestDefaultTenantUserApi.java
index 8903d88..b39f4b4 100644
--- a/tenant/src/test/java/org/killbill/billing/tenant/api/user/TestDefaultTenantUserApi.java
+++ b/tenant/src/test/java/org/killbill/billing/tenant/api/user/TestDefaultTenantUserApi.java
@@ -48,7 +48,6 @@ public class TestDefaultTenantUserApi extends TenantTestSuiteWithEmbeddedDb {
@Test(groups = "slow")
public void testSystemKeySingleValue() throws Exception {
-
final String tenantKey = TenantKey.PLUGIN_CONFIG_.toString() + "MyPluginName";
tenantUserApi.addTenantKeyValue(tenantKey, "TheValue", callContext);
@@ -79,7 +78,6 @@ public class TestDefaultTenantUserApi extends TenantTestSuiteWithEmbeddedDb {
@Test(groups = "slow")
public void testSystemKeyMultipleValue() throws Exception {
-
final String tenantKey = TenantKey.CATALOG.toString();
tenantUserApi.addTenantKeyValue(tenantKey, "TheValue", callContext);
@@ -96,5 +94,4 @@ public class TestDefaultTenantUserApi extends TenantTestSuiteWithEmbeddedDb {
value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext);
Assert.assertEquals(value.size(), 0);
}
-
}
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 706d451..02b709f 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
@@ -25,13 +25,10 @@ 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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
@Singleton
public class TenantKVCacheLoader extends BaseCacheLoader {
- private static final Logger logger = LoggerFactory.getLogger(TenantKVCacheLoader.class);
private final TenantInternalApi tenantApi;
@Inject
@@ -47,7 +44,6 @@ public class TenantKVCacheLoader extends BaseCacheLoader {
@Override
public Object load(final Object key, final Object argument) {
-
checkCacheLoaderStatus();
if (!(key instanceof String)) {
@@ -62,7 +58,7 @@ public class TenantKVCacheLoader extends BaseCacheLoader {
final InternalTenantContext internalTenantContext = new InternalTenantContext(Long.valueOf(tenantRecordId));
final List<String> valuesForKey = tenantApi.getTenantValuesForKey(rawKey, internalTenantContext);
- if (valuesForKey == null || valuesForKey.size() == 0) {
+ if (valuesForKey == null || valuesForKey.isEmpty()) {
return null;
}
if (valuesForKey.size() > 1) {