Search in sources :

Example 6 with ICacheManager

use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.

the class NonPooledDatasourceSystemListener method startup.

public boolean startup(final IPentahoSession session) {
    try {
        // $NON-NLS-1$
        Logger.debug(this, "DatasourceSystemListener: called for startup ...");
        ICacheManager cacheManager = addCacheRegions();
        List<IDatabaseConnection> databaseConnections = getListOfDatabaseConnections(session);
        String dsName = "";
        DataSource ds = null;
        for (IDatabaseConnection databaseConnection : databaseConnections) {
            if (databaseConnection != null) {
                // $NON-NLS-1$
                Logger.debug(this, "  Setting up datasource - " + databaseConnection);
                dsName = databaseConnection.getName();
                // http://jira.pentaho.com/browse/BISERVER-12244
                if (!databaseConnection.getAccessType().equals(DatabaseAccessType.JNDI)) {
                    // if connection's port used by server there is no sense to get DataSource for this
                    ds = isPortUsedByServer(databaseConnection) ? null : setupDataSourceForConnection(databaseConnection);
                } else {
                    Logger.debug(this, // $NON-NLS-1$
                    "(Datasource \"" + IDBDatasourceService.JDBC_DATASOURCE + dsName + // $NON-NLS-1$
                    "\" not cached)");
                    continue;
                }
                cacheManager.putInRegionCache(IDBDatasourceService.JDBC_DATASOURCE, dsName, ds);
                Logger.debug(this, // $NON-NLS-1$
                "(Storing datasource under key \"" + IDBDatasourceService.JDBC_DATASOURCE + dsName + // $NON-NLS-1$
                "\")");
            }
        }
        // $NON-NLS-1$
        Logger.debug(this, "DatasourceSystemListener: Completed startup.");
        return true;
    } catch (ObjectFactoryException objface) {
        Logger.error(this, Messages.getInstance().getErrorString("DatasourceSystemListener.ERROR_0001_UNABLE_TO_INSTANTIATE_OBJECT"), // $NON-NLS-1$
        objface);
        return false;
    } catch (DatasourceMgmtServiceException dmse) {
        Logger.error(this, Messages.getInstance().getErrorString("DatasourceSystemListener.ERROR_0002_UNABLE_TO_GET_DATASOURCE"), // $NON-NLS-1$
        dmse);
        return false;
    }
}
Also used : ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 7 with ICacheManager

use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.

the class NonPooledDatasourceSystemListener method shutdown.

public void shutdown() {
    ICacheManager cacheManager = PentahoSystem.getCacheManager(null);
    // $NON-NLS-1$
    Logger.debug(this, "DatasourceSystemListener: Called for shutdown ...");
    cacheManager.removeRegionCache(IDBDatasourceService.JDBC_DATASOURCE);
    // $NON-NLS-1$
    Logger.debug(this, "DatasourceSystemListener: Completed shutdown.");
}
Also used : ICacheManager(org.pentaho.platform.api.engine.ICacheManager)

Example 8 with ICacheManager

use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.

the class NonPooledDatasourceSystemListener method addCacheRegions.

protected ICacheManager addCacheRegions() {
    ICacheManager cacheManager = PentahoSystem.getCacheManager(null);
    // $NON-NLS-1$
    Logger.debug(this, "Adding caching regions ...");
    if (!cacheManager.cacheEnabled(IDBDatasourceService.JDBC_DATASOURCE)) {
        cacheManager.addCacheRegion(IDBDatasourceService.JDBC_DATASOURCE);
    }
    return cacheManager;
}
Also used : ICacheManager(org.pentaho.platform.api.engine.ICacheManager)

Example 9 with ICacheManager

use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.

the class SystemRefreshResource method purgeReportingDataCache.

/**
 * @deprecated use org.pentaho.reporting.platform.plugin.CacheManagerEndpoint instead
 */
@Deprecated
@GET
@Path("/reportingDataCache")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Facet(name = "Unsupported")
public Response purgeReportingDataCache() {
    if (canAdminister()) {
        ICacheManager cacheManager = PentahoSystem.get(ICacheManager.class);
        cacheManager.clearRegionCache("report-dataset-cache");
        cacheManager.clearRegionCache("report-output-handlers");
        Runnable clearCacheAction = PentahoSystem.get(Runnable.class, "_ClearCacheAction", PentahoSessionHolder.getSession());
        if (clearCacheAction != null) {
            clearCacheAction.run();
        }
        return Response.ok().type(MediaType.TEXT_PLAIN).build();
    } else {
        return Response.status(UNAUTHORIZED).build();
    }
}
Also used : ICacheManager(org.pentaho.platform.api.engine.ICacheManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 10 with ICacheManager

use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.

the class PentahoWebContextFilterTest method testWebContextCachedWaitSecondVariable.

@Test
public void testWebContextCachedWaitSecondVariable() throws Exception {
    ICacheManager cacheManager = Mockito.mock(ICacheManager.class);
    when(cacheManager.getFromGlobalCache(PentahoSystem.WAIT_SECONDS)).thenReturn(null).thenReturn(30);
    PentahoWebContextFilter filter = new PentahoWebContextFilter();
    PentahoWebContextFilter.cache = cacheManager;
    filter.getRequireWaitTime();
    filter.getRequireWaitTime();
    verify(cacheManager, times(2)).getFromGlobalCache(eq(PentahoSystem.WAIT_SECONDS));
    verify(cacheManager, times(1)).putInGlobalCache(eq(PentahoSystem.WAIT_SECONDS), anyObject());
}
Also used : ICacheManager(org.pentaho.platform.api.engine.ICacheManager) Test(org.junit.Test)

Aggregations

ICacheManager (org.pentaho.platform.api.engine.ICacheManager)24 Test (org.junit.Test)6 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 DataSource (javax.sql.DataSource)2 DataSourcesConfig (mondrian.xmla.DataSourcesConfig)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 Domain (org.pentaho.metadata.model.Domain)2 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)2 MockSessionAwareMetadataDomainRepository (org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1