Search in sources :

Example 1 with ApplicationKeyMappingCacheKey

use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMappingCacheKey in project carbon-apimgt by wso2.

the class SubscriptionDataStoreImpl method getKeyMappingByKeyAndKeyManager.

@Override
public ApplicationKeyMapping getKeyMappingByKeyAndKeyManager(String key, String keyManager) {
    ApplicationKeyMappingCacheKey applicationKeyMappingCacheKey = new ApplicationKeyMappingCacheKey(key, keyManager);
    String synchronizeKey = "SubscriptionDataStoreImpl-KeyMapping-" + applicationKeyMappingCacheKey;
    ApplicationKeyMapping applicationKeyMapping = applicationKeyMappingMap.get(applicationKeyMappingCacheKey);
    if (applicationKeyMapping == null) {
        synchronized (synchronizeKey.intern()) {
            applicationKeyMapping = applicationKeyMappingMap.get(applicationKeyMappingCacheKey);
            if (applicationKeyMapping != null) {
                return applicationKeyMapping;
            }
            try {
                applicationKeyMapping = new SubscriptionDataLoaderImpl().getKeyMapping(key, keyManager, tenantDomain);
            } catch (DataLoadingException e) {
                log.error("Error while Loading KeyMapping Information from Internal API.", e);
            }
            if (applicationKeyMapping != null && !StringUtils.isEmpty(applicationKeyMapping.getConsumerKey())) {
                // load to the memory
                log.debug("Loading Keymapping to the in-memory datastore.");
                addOrUpdateApplicationKeyMapping(applicationKeyMapping);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieving Application information with Consumer Key : " + key + " and keymanager : " + keyManager);
        if (applicationKeyMapping != null) {
            log.debug("Retrieved Application information with Consumer Key : " + key + " and keymanager : " + keyManager + " is " + applicationKeyMapping.toString());
        } else {
            log.debug("Retrieving Application information with Consumer Key : " + key + " and keymanager : " + keyManager + " is empty");
        }
    }
    return applicationKeyMapping;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) ApplicationKeyMappingCacheKey(org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMappingCacheKey) ApplicationKeyMapping(org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMapping)

Aggregations

ApplicationKeyMapping (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMapping)1 ApplicationKeyMappingCacheKey (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMappingCacheKey)1 DataLoadingException (org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException)1