Search in sources :

Example 1 with SubscriptionDataStoreImpl

use of org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataStoreImpl in project carbon-apimgt by wso2.

the class SubscriptionDataHolder method registerTenantSubscriptionStore.

public SubscriptionDataStore registerTenantSubscriptionStore(String tenantDomain) {
    SubscriptionDataStore tenantStore = subscriptionStore.get(tenantDomain);
    if (tenantStore == null) {
        tenantStore = new SubscriptionDataStoreImpl(tenantDomain);
    }
    subscriptionStore.put(tenantDomain, tenantStore);
    return tenantStore;
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) SubscriptionDataStoreImpl(org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataStoreImpl)

Example 2 with SubscriptionDataStoreImpl

use of org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataStoreImpl in project carbon-apimgt by wso2.

the class SubscriptionDataStoreImpl method getApplicationById.

@Override
public Application getApplicationById(int appId) {
    String synchronizeKey = "SubscriptionDataStoreImpl-Application-" + appId;
    Application application = applicationMap.get(appId);
    if (application == null) {
        synchronized (synchronizeKey.intern()) {
            application = applicationMap.get(appId);
            if (application != null) {
                return application;
            }
        }
        try {
            application = new SubscriptionDataLoaderImpl().getApplicationById(appId);
        } catch (DataLoadingException e) {
            log.error("Error while Retrieving Application Metadata From Internal API.", e);
        }
        if (application != null && application.getId() != null && application.getId() != 0) {
            // load to the memory
            log.debug("Loading Application to the in-memory datastore. applicationId = " + application.getId());
            addOrUpdateApplication(application);
        } else {
            log.debug("Application not found. applicationId = " + appId);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieving Application information with Application Id : " + appId);
        if (application != null) {
            log.debug("Retrieved Application :" + application.toString());
        } else {
            log.debug("Retrieved Application information with Application Id : " + appId + " is empty");
        }
    }
    return application;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) Application(org.wso2.carbon.apimgt.keymgt.model.entity.Application)

Example 3 with SubscriptionDataStoreImpl

use of org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataStoreImpl in project carbon-apimgt by wso2.

the class SubscriptionDataStoreImpl method addOrUpdateSubscription.

@Override
public void addOrUpdateSubscription(Subscription subscription) {
    String synchronizeKey = "SubscriptionDataStoreImpl-API-" + subscription.getCacheKey();
    synchronized (synchronizeKey.intern()) {
        Subscription retrievedSubscription = subscriptionMap.get(subscription.getCacheKey());
        if (retrievedSubscription == null) {
            subscriptionMap.put(subscription.getCacheKey(), subscription);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Retrieved Subscription from Map :" + retrievedSubscription.toString());
            }
            if (subscription.getTimeStamp() < retrievedSubscription.getTimeStamp()) {
                if (log.isDebugEnabled()) {
                    log.debug("Drop the Event " + subscription.toString() + " since the event timestamp was old");
                }
            } else {
                if (!APIConstants.SubscriptionStatus.ON_HOLD.equals(subscription.getSubscriptionState())) {
                    subscriptionMap.put(subscription.getCacheKey(), subscription);
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Drop the Event " + subscription.toString() + " since the event was marked as " + "ON_HOLD");
                    }
                }
            }
        }
        if (log.isDebugEnabled()) {
            Subscription updatedSubscription = subscriptionMap.get(subscription.getCacheKey());
            log.debug("Updated Subscription From map :" + updatedSubscription.toString());
        }
    }
}
Also used : Subscription(org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)

Example 4 with SubscriptionDataStoreImpl

use of org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataStoreImpl in project carbon-apimgt by wso2.

the class SubscriptionDataStoreImpl method getApiByContextAndVersion.

@Override
public API getApiByContextAndVersion(String context, String version) {
    String key = context + DELEM_PERIOD + version;
    String synchronizeKey = "SubscriptionDataStoreImpl-API-" + key;
    API api = apiMap.get(key);
    if (api == null) {
        synchronized (synchronizeKey.intern()) {
            api = apiMap.get(key);
            if (api != null) {
                return api;
            }
            try {
                api = new SubscriptionDataLoaderImpl().getApi(context, version);
            } catch (DataLoadingException e) {
                log.error("Error while Retrieving Data From Internal Rest API", e);
            }
            if (api != null && api.getApiId() != 0) {
                // load to the memory
                log.debug("Loading API to the in-memory datastore.");
                addOrUpdateAPI(api);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieving API information with Context " + context + " and Version : " + version);
        if (api != null) {
            log.debug("Retrieved API information with Context  : " + context + " and Version : " + version + " is" + " " + api.toString());
        } else {
            log.debug("Retrieved API information with Context  : " + context + " and Version : " + version + " is" + " empty");
        }
    }
    return api;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) API(org.wso2.carbon.apimgt.keymgt.model.entity.API)

Example 5 with SubscriptionDataStoreImpl

use of org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataStoreImpl in project carbon-apimgt by wso2.

the class SubscriptionDataStoreImpl method getSubscriptionById.

@Override
public Subscription getSubscriptionById(int appId, int apiId) {
    String subscriptionCacheKey = SubscriptionDataStoreUtil.getSubscriptionCacheKey(appId, apiId);
    String synchronizeKey = "SubscriptionDataStoreImpl-Subscription-" + subscriptionCacheKey;
    Subscription subscription = subscriptionMap.get(subscriptionCacheKey);
    if (subscription == null) {
        synchronized (synchronizeKey.intern()) {
            subscription = subscriptionMap.get(subscriptionCacheKey);
            if (subscription != null) {
                return subscription;
            }
            try {
                subscription = new SubscriptionDataLoaderImpl().getSubscriptionById(Integer.toString(apiId), Integer.toString(appId));
            } catch (DataLoadingException e) {
                log.error("Error while Retrieving Subscription Data From Internal API", e);
            }
            if (subscription != null && !StringUtils.isEmpty(subscription.getSubscriptionId())) {
                // load to the memory
                log.debug("Loading Subscription to the in-memory datastore.");
                subscriptionMap.put(subscription.getCacheKey(), subscription);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieving API Subscription with Application " + appId + " and APIId : " + apiId);
        if (subscription != null) {
            log.debug("Retrieved API Subscription with Application " + appId + " and APIId : " + apiId + " is " + subscription.toString());
        } else {
            log.debug("Retrieved API Subscription with Application " + appId + " and APIId : " + apiId + " is " + "empty.");
        }
    }
    return subscription;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) Subscription(org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)

Aggregations

DataLoadingException (org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException)4 Subscription (org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)2 SubscriptionDataStore (org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)1 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)1 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)1 ApplicationKeyMapping (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMapping)1 ApplicationKeyMappingCacheKey (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMappingCacheKey)1 SubscriptionDataStoreImpl (org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataStoreImpl)1