Search in sources :

Example 1 with RegistryLCManager

use of org.wso2.carbon.apimgt.persistence.utils.RegistryLCManager in project carbon-apimgt by wso2.

the class LCManagerFactory method getLCManager.

public RegistryLCManager getLCManager() throws PersistenceException {
    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    String cacheName = tenantDomain + "_" + APIConstants.LC_CACHE_NAME;
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    Cache lcCache = Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER).getCache(APIConstants.LC_CACHE_NAME);
    RegistryLCManager lcManager = (RegistryLCManager) lcCache.get(cacheName);
    if (lcManager != null) {
        log.debug("Lifecycle info servered from Cache.");
        return lcManager;
    } else {
        try {
            log.debug("Lifecycle info not found in Cache.");
            lcManager = new RegistryLCManager(tenantId);
            lcCache.put(cacheName, lcManager);
            return lcManager;
        } catch (RegistryException | XMLStreamException | ParserConfigurationException | SAXException | IOException e) {
            throw new PersistenceException("Error while accessing the lifecycle resource ", e);
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) RegistryLCManager(org.wso2.carbon.apimgt.persistence.utils.RegistryLCManager) PersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) Cache(javax.cache.Cache) SAXException(org.xml.sax.SAXException)

Aggregations

IOException (java.io.IOException)1 Cache (javax.cache.Cache)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 PersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.PersistenceException)1 RegistryLCManager (org.wso2.carbon.apimgt.persistence.utils.RegistryLCManager)1 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)1 SAXException (org.xml.sax.SAXException)1