use of org.apache.flink.shaded.guava30.com.google.common.cache.Cache in project gerrit by GerritCodeReview.
the class CacheModule method cache.
/**
* Declare a named in-memory cache.
*
* @param <K> type of key used to lookup entries.
* @param <V> type of value stored by the cache.
* @return binding to describe the cache.
*/
protected <K, V> CacheBinding<K, V> cache(String name, TypeLiteral<K> keyType, TypeLiteral<V> valType) {
Type type = Types.newParameterizedType(Cache.class, keyType.getType(), valType.getType());
@SuppressWarnings("unchecked") Key<Cache<K, V>> key = (Key<Cache<K, V>>) Key.get(type, Names.named(name));
CacheProvider<K, V> m = new CacheProvider<>(this, name, keyType, valType);
bind(key).toProvider(m).asEagerSingleton();
bind(ANY_CACHE).annotatedWith(Exports.named(name)).to(key);
return m.maximumWeight(1024);
}
use of org.apache.flink.shaded.guava30.com.google.common.cache.Cache in project meteo by pierre.
the class StreamResource method getSamplesByRoute.
/**
* Get the data points associated with a field in an Esper query.
* For this to work, you need to add ResourceListener as a publisher and configure it in a stream:
* {
* "name": "Jansky",
* "type": "com.ning.metrics.meteo.publishers.ResourceListener",
* "@class": "com.ning.metrics.meteo.publishers.ResourcePublisherConfig"
* }
*
* @param callback Javascript callback
* @param stream Stream name
* @param attribute the SQL alias of an Esper query
* @return jsonp representation of the data points in memory
*/
@GET
@Path("/{stream}/{attribute}")
@Produces(MediaType.APPLICATION_JSON)
public Response getSamplesByRoute(@QueryParam("callback") @DefaultValue("callback") final String callback, @PathParam("stream") final String stream, @PathParam("attribute") final String attribute) {
Cache<Object, Object> samplesCache = null;
final ResourceListener resourceListener = (ResourceListener) compiler.getPublisherInstances().get(stream);
if (resourceListener != null) {
final Map<String, Cache<Object, Object>> samples = resourceListener.getSamplesCache();
samplesCache = samples.get(attribute);
}
return buildJsonpResponse(attribute, samplesCache, callback);
}
use of org.apache.flink.shaded.guava30.com.google.common.cache.Cache in project uPortal by Jasig.
the class SearchPortletController method getPortalSearchResults.
/**
* Get the {@link PortalSearchResults} for the specified query id from the session. If there are
* no results null is returned.
*/
private PortalSearchResults getPortalSearchResults(PortletRequest request, String queryId) {
final PortletSession session = request.getPortletSession();
@SuppressWarnings("unchecked") final Cache<String, PortalSearchResults> searchResultsCache = (Cache<String, PortalSearchResults>) session.getAttribute(SEARCH_RESULTS_CACHE_NAME);
if (searchResultsCache == null) {
return null;
}
return searchResultsCache.getIfPresent(queryId);
}
use of org.apache.flink.shaded.guava30.com.google.common.cache.Cache in project bookkeeper by apache.
the class TestFileInfoBackingCache method testRefCountRace.
@Test
public void testRefCountRace() throws Exception {
AtomicBoolean done = new AtomicBoolean(false);
FileInfoBackingCache cache = new FileInfoBackingCache((ledgerId, createIfNotFound) -> {
File f = new File(baseDir, String.valueOf(ledgerId));
f.deleteOnExit();
return f;
});
Iterable<Future<Set<CachedFileInfo>>> futures = IntStream.range(0, 2).mapToObj((i) -> {
Callable<Set<CachedFileInfo>> c = () -> {
Set<CachedFileInfo> allFileInfos = new HashSet<>();
while (!done.get()) {
CachedFileInfo fi = cache.loadFileInfo(1, masterKey);
Assert.assertFalse(fi.isClosed());
allFileInfos.add(fi);
fi.release();
}
return allFileInfos;
};
return executor.submit(c);
}).collect(Collectors.toList());
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
done.set(true);
// ensure all threads are finished operating on cache, before checking any
for (Future<Set<CachedFileInfo>> f : futures) {
f.get();
}
for (Future<Set<CachedFileInfo>> f : futures) {
for (CachedFileInfo fi : f.get()) {
Assert.assertTrue(fi.isClosed());
Assert.assertEquals(FileInfoBackingCache.DEAD_REF, fi.getRefCount());
}
}
}
use of org.apache.flink.shaded.guava30.com.google.common.cache.Cache in project metasfresh-webui-api by metasfresh.
the class ADProcessInstancesRepository method createNewProcessInstance0.
/**
* @param request
* @param shadowParentDocumentEvaluatee optional shadowParentDocumentEvaluatee which will be
* @return
*/
private IProcessInstanceController createNewProcessInstance0(@NonNull final CreateProcessInstanceRequest request, @Nullable final IDocumentEvaluatee evalCtx) {
//
// Save process info together with it's parameters and get the the newly created AD_PInstance_ID
final ProcessInfo processInfo = createProcessInfo(request);
Services.get(IADPInstanceDAO.class).saveProcessInfo(processInfo);
final DocumentId adPInstanceId = DocumentId.of(processInfo.getAD_PInstance_ID());
final Object processClassInstance = processInfo.newProcessClassInstanceOrNull();
try (final IAutoCloseable c = JavaProcess.temporaryChangeCurrentInstance(processClassInstance)) {
//
// Build the parameters document
final ProcessDescriptor processDescriptor = getProcessDescriptor(request.getProcessId());
final DocumentEntityDescriptor parametersDescriptor = processDescriptor.getParametersDescriptor();
final Document parametersDoc = ADProcessParametersRepository.instance.createNewParametersDocument(parametersDescriptor, adPInstanceId, evalCtx);
final int windowNo = parametersDoc.getWindowNo();
// Set parameters's default values
ProcessDefaultParametersUpdater.newInstance().addDefaultParametersProvider(processClassInstance instanceof IProcessDefaultParametersProvider ? (IProcessDefaultParametersProvider) processClassInstance : null).onDefaultValue((parameter, value) -> parametersDoc.processValueChange(parameter.getColumnName(), value, () -> "default parameter value")).updateDefaultValue(parametersDoc.getFieldViews(), field -> DocumentFieldAsProcessDefaultParameter.of(windowNo, field));
//
// Create (webui) process instance and add it to our internal cache.
final ADProcessInstanceController pinstance = ADProcessInstanceController.builder().caption(processDescriptor.getCaption()).instanceId(adPInstanceId).parameters(parametersDoc).processClassInstance(processClassInstance).contextSingleDocumentPath(request.getSingleDocumentPath()).viewId(request.getViewRowIdsSelection() != null ? request.getViewRowIdsSelection().getViewId() : null).build();
processInstances.put(adPInstanceId, pinstance.copyReadonly());
return pinstance;
}
}
Aggregations