Search in sources :

Example 1 with CacheResource

use of com.google.gerrit.server.config.CacheResource in project gerrit by GerritCodeReview.

the class PostCaches method flush.

private void flush(List<String> cacheNames) throws UnprocessableEntityException, AuthException, PermissionBackendException {
    List<CacheResource> cacheResources = new ArrayList<>(cacheNames.size());
    for (String n : cacheNames) {
        String pluginName = PluginName.GERRIT;
        String cacheName = n;
        int i = cacheName.lastIndexOf('-');
        if (i != -1) {
            pluginName = cacheName.substring(0, i);
            cacheName = cacheName.length() > i + 1 ? cacheName.substring(i + 1) : "";
        }
        Cache<?, ?> cache = cacheMap.get(pluginName, cacheName);
        if (cache != null) {
            cacheResources.add(new CacheResource(pluginName, cacheName, cache));
        } else {
            throw new UnprocessableEntityException(String.format("cache %s not found", n));
        }
    }
    for (CacheResource rsrc : cacheResources) {
        flushCache.apply(rsrc, null);
    }
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) CacheResource(com.google.gerrit.server.config.CacheResource) ArrayList(java.util.ArrayList)

Example 2 with CacheResource

use of com.google.gerrit.server.config.CacheResource in project gerrit by GerritCodeReview.

the class CachesCollection method parse.

@Override
public CacheResource parse(ConfigResource parent, IdString id) throws AuthException, ResourceNotFoundException, PermissionBackendException {
    permissionBackend.currentUser().check(GlobalPermission.VIEW_CACHES);
    String cacheName = id.get();
    String pluginName = PluginName.GERRIT;
    int i = cacheName.lastIndexOf('-');
    if (i != -1) {
        pluginName = cacheName.substring(0, i);
        cacheName = cacheName.length() > i + 1 ? cacheName.substring(i + 1) : "";
    }
    Provider<Cache<?, ?>> cacheProvider = cacheMap.byPlugin(pluginName).get(cacheName);
    if (cacheProvider == null) {
        throw new ResourceNotFoundException(id);
    }
    return new CacheResource(pluginName, cacheName, cacheProvider);
}
Also used : CacheResource(com.google.gerrit.server.config.CacheResource) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Cache(com.google.common.cache.Cache)

Example 3 with CacheResource

use of com.google.gerrit.server.config.CacheResource in project gerrit by GerritCodeReview.

the class PostCaches method flushAll.

private void flushAll() throws AuthException, PermissionBackendException {
    for (Extension<Cache<?, ?>> e : cacheMap) {
        CacheResource cacheResource = new CacheResource(e.getPluginName(), e.getExportName(), e.getProvider());
        if (FlushCache.WEB_SESSIONS.equals(cacheResource.getName())) {
            continue;
        }
        flushCache.apply(cacheResource, null);
    }
}
Also used : CacheResource(com.google.gerrit.server.config.CacheResource) Cache(com.google.common.cache.Cache)

Aggregations

CacheResource (com.google.gerrit.server.config.CacheResource)3 Cache (com.google.common.cache.Cache)2 IdString (com.google.gerrit.extensions.restapi.IdString)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)1 ArrayList (java.util.ArrayList)1