use of org.killbill.billing.util.cache.CacheLoaderArgument in project killbill by killbill.
the class CacheConfig method initializeCacheLoaderArgument.
private CacheLoaderArgument initializeCacheLoaderArgument() {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
public Object loadConfig(@Nullable final String inputJson) throws IOException {
return inputJson != null ? objectMapper.readValue(inputJson, PerTenantConfig.class) : new PerTenantConfig();
}
};
final Object[] args = new Object[1];
args[0] = loaderCallback;
final ObjectType irrelevant = null;
final InternalTenantContext notUsed = null;
return new CacheLoaderArgument(irrelevant, args, notUsed);
}
use of org.killbill.billing.util.cache.CacheLoaderArgument in project killbill by killbill.
the class EntitySqlDaoWrapperInvocationHandler method invokeWithCaching.
private Object invokeWithCaching(final Cachable cachableAnnotation, final Method method, final Object[] args) throws Throwable {
final ObjectType objectType = getObjectType();
final CacheType cacheType = cachableAnnotation.value();
final CacheController<Object, Object> cache = cacheControllerDispatcher.getCacheController(cacheType);
Object result = null;
if (cache != null) {
// Find all arguments marked with @CachableKey
final Map<Integer, Object> keyPieces = new LinkedHashMap<Integer, Object>();
final Annotation[][] annotations = method.getParameterAnnotations();
for (int i = 0; i < annotations.length; i++) {
for (int j = 0; j < annotations[i].length; j++) {
final Annotation annotation = annotations[i][j];
if (CachableKey.class.equals(annotation.annotationType())) {
// CachableKey position starts at 1
keyPieces.put(((CachableKey) annotation).value() - 1, args[i]);
break;
}
}
}
// Build the Cache key
final String cacheKey = buildCacheKey(keyPieces);
final InternalTenantContext internalTenantContext = (InternalTenantContext) Iterables.find(ImmutableList.copyOf(args), new Predicate<Object>() {
@Override
public boolean apply(final Object input) {
return input instanceof InternalTenantContext;
}
}, null);
final CacheLoaderArgument cacheLoaderArgument = new CacheLoaderArgument(objectType, args, internalTenantContext, handle);
return cache.get(cacheKey, cacheLoaderArgument);
}
if (result == null) {
result = prof.executeWithProfiling(ProfilingFeatureType.DAO_DETAILS, sqlDaoClass.getSimpleName() + "(raw) :" + method.getName(), new WithProfilingCallback() {
@Override
public Object execute() throws Throwable {
return method.invoke(sqlDao, args);
}
});
}
return result;
}
use of org.killbill.billing.util.cache.CacheLoaderArgument in project killbill by killbill.
the class EhCacheCatalogCache method initializeCacheLoaderArgument.
//
// Build the LoaderCallback that is required to build the catalog from the xml from a module that knows
// nothing about catalog.
//
// This is a contract between the TenantCatalogCacheLoader and the EhCacheCatalogCache
private CacheLoaderArgument initializeCacheLoaderArgument(final boolean filterTemplateCatalog) {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
public Object loadCatalog(final List<String> catalogXMLs, final Long tenantRecordId) throws CatalogApiException {
return loader.load(catalogXMLs, filterTemplateCatalog, tenantRecordId);
}
};
final Object[] args = new Object[1];
args[0] = loaderCallback;
final ObjectType irrelevant = null;
final InternalTenantContext notUsed = null;
return new CacheLoaderArgument(irrelevant, args, notUsed);
}
use of org.killbill.billing.util.cache.CacheLoaderArgument in project killbill by killbill.
the class EhCacheStateMachineConfigCache method getPaymentStateMachineConfig.
@Override
public StateMachineConfig getPaymentStateMachineConfig(final String pluginName, final InternalTenantContext tenantContext) throws PaymentApiException {
if (tenantContext.getTenantRecordId() == InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID || cacheController == null) {
return defaultPaymentStateMachineConfig;
}
final String pluginConfigKey = getCacheKeyName(pluginName, tenantContext);
final CacheLoaderArgument cacheLoaderArgument = createCacheLoaderArgument(pluginName);
try {
StateMachineConfig pluginPaymentStateMachineConfig = (StateMachineConfig) cacheController.get(pluginConfigKey, cacheLoaderArgument);
// It means we are using the default state machine config in a multi-tenant deployment
if (pluginPaymentStateMachineConfig == null) {
pluginPaymentStateMachineConfig = defaultPaymentStateMachineConfig;
cacheController.add(pluginConfigKey, pluginPaymentStateMachineConfig);
}
return pluginPaymentStateMachineConfig;
} catch (final IllegalStateException e) {
// TODO 0.17 proper error code
throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, "Invalid payment state machine");
}
}
use of org.killbill.billing.util.cache.CacheLoaderArgument in project killbill by killbill.
the class DefaultTenantUserApi method getCachedTenantValuesForKey.
private List<String> getCachedTenantValuesForKey(final String key, final InternalTenantContext internalContext) {
final String tenantKey = getCacheKeyName(key, internalContext);
final Object cachedTenantValues = tenantKVCache.get(tenantKey, new CacheLoaderArgument(ObjectType.TENANT_KVS));
if (cachedTenantValues == null) {
return ImmutableList.<String>of();
} else {
// Current, we only cache single-value keys
return ImmutableList.<String>of((String) cachedTenantValues);
}
}
Aggregations