public void replaceAll(final Iterable<T> elements) { lock.withLock(new Runnable() { public void run() { set = ImmutableSortedSet.copyOf(elements); } }); }
public T add(final T t) { notNull("element", t); return lock.withLock(new Supplier<T>() { public T get() { set = ImmutableSortedSet.<T> naturalOrder().addAll(set).add(t).build(); return t; } }); }
@SuppressWarnings("unchecked") protected <K, V> ManagedCache createComputingCache(@Nonnull final String name, @Nonnull final CacheSettings settings, final CacheLoader<K, V> loader) { return cacheCreationLocks.get(name).withLock(new com.atlassian.util.concurrent.Supplier<ManagedCache>() { @Override public ManagedCache get() { Ehcache spCache = getLoadingCache(name, settings, new ValueProcessorAtlassianCacheLoaderDecorator(loader, valueProcessor)); DelegatingCache<K,V> cache = DelegatingCache.create(spCache, settings, valueProcessor); caches.put(name, new WeakSupplier<ManagedCache>(cache)); return cache; } }); }
public void remove(final T t) { notNull("element", t); lock.withLock(new Runnable() { public void run() { set = ImmutableSortedSet.<T> naturalOrder().addAll(Iterables.filter(set, new Predicate<T>() { public boolean apply(final T input) { return !t.equals(input); } })).build(); } }); }
@Override public void unregisterMBeans(@Nullable MBeanServer mBeanServer) { metricsLock.write().withLock(() -> { mbeansRegistrar.unregisterMBeans(); }); } }
@Override public void registerMBeans(@Nullable MBeanServer mBeanServer) { metricsLock.write().withLock(() -> { mbeansRegistrar.enableCollectingJMXMetrics(mBeanServer, JMXMemoryCacheManager.this); }); }
@Nonnull @Override public <V> CachedReference<V> getCachedReference(@Nonnull final String name, @Nonnull final Supplier<V> supplier, @Nonnull final CacheSettings settings) { checkSettingsAreCompatible(name, settings); return cacheCreationLocks.get(name).withLock(new com.atlassian.util.concurrent.Supplier<CachedReference<V>>() { @Override public CachedReference<V> get() { caches.put(name, new WeakSupplier<ManagedCache>((ManagedCache) doCreateCachedReference(name, supplier, settings))); //noinspection unchecked return (CachedReference<V>) caches.get(name).get(); } }); }
public void withLock(final T descriptor, final Runnable runnable) { lockFactory.get(stripeFunction.get(descriptor)).withLock(runnable); } }
@Override protected <K, V> ManagedCache createComputingCache(@Nonnull final String name, @Nonnull final CacheSettings settings, final CacheLoader<K, V> loader) { checkSettingsAreCompatible(name, settings); // when a loader is provided, always create a new ManagedCache to ensure the correct loader is being used. // if the cache already existed, the backing values will be reused return cacheCreationLocks.get(name).withLock(new com.atlassian.util.concurrent.Supplier<ManagedCache>() { @Override public ManagedCache get() { if (!caches.containsKey(name) || loader != null) { caches.put(name, new WeakSupplier<ManagedCache>((ManagedCache) doCreateCache(name, loader, settings))); } return caches.get(name).get(); } }); }
@Override protected void putCacheInMap(@Nonnull String name, @Nonnull Supplier<ManagedCache> supplier) { metricsLock.read().withLock(() -> { JMXMemoryCacheManager.super.putCacheInMap(name, supplier); mbeansRegistrar.registerMBean(name); }); }
/** * Gets all locks for ids and then after having acquired them executes the action. */ private void acquireLocksAndExecute(final Iterable<Long> ids, final WorkflowAction lockType, final Runnable action) { if (Iterables.isEmpty(ids)) { action.run(); } else { final Set<Long> sortedIds = Sets.newTreeSet(ids); ManagedLocks.manage(getLock(Iterables.getFirst(sortedIds, null), lockType)).withLock(new Runnable() { @Override public void run() { acquireLocksAndExecute(Iterables.skip(sortedIds, 1), lockType, action); } }); } }
@Override public void deleteScheme(final Long id) { if (id == null) { return; } ManagedLocks.manage(getLock(id, DELETE_SCHEME)).withLock(new Runnable() { @Override public void run() { final AssignableWorkflowScheme scheme = getWorkflowSchemeObj(id); doDeleteScheme(scheme); } }); }
public <R> R withLock(final T descriptor, final Supplier<R> supplier) { return lockFactory.get(stripeFunction.get(descriptor)).withLock(supplier); }
public <R> R withLock(final T descriptor, final Callable<R> callable) throws Exception { return lockFactory.get(stripeFunction.get(descriptor)).withLock(callable); }
private List<UserHistoryItem> removeAnonymousSession(final VelocityRequestSession session, final UserHistoryItem.Type type) { final String sessionKey = getSessionKeyForType(type); return lockManager.get(session).withLock(new Supplier<List<UserHistoryItem>>() { public List<UserHistoryItem> get() { @SuppressWarnings("unchecked") final List<UserHistoryItem> sessionHistory = (List<UserHistoryItem>) session.getAttribute(sessionKey); if (sessionHistory != null && !sessionHistory.isEmpty()) { session.removeAttribute(sessionKey); } return sessionHistory; } }); }
@Nonnull final DelegatingCache.CreateFunction createFunction) return cacheCreationLocks.get(name).withLock(new com.atlassian.util.concurrent.Supplier<ManagedCache>()
public void addHistoryItem(final ApplicationUser user, @Nonnull final UserHistoryItem historyItem) { notNull("user", user); notNull("historyItem", historyItem); final AddHistoryResult result = lockManager.get(user).withLock(new Supplier<AddHistoryResult>() { public AddHistoryResult get() { return addCachedHistoryItem(user, historyItem); } }); // JRADEV-15768 // Don't call the delegatingStore while the lock is held! Was causing deadlock between DB and JIRA. executor.get().submit(new UserHistoryWriter(result, user, historyItem)); }
private List<UserHistoryItem> getAnonymousSessionHistory(final VelocityRequestSession session, UserHistoryItem.Type type) { final String sessionKey = getSessionKeyForType(type); return lockManager.get(session).withLock(new Supplier<List<UserHistoryItem>>() { public List<UserHistoryItem> get() { @SuppressWarnings("unchecked") final List<UserHistoryItem> sessionHistory = (List<UserHistoryItem>) session.getAttribute(sessionKey); if (sessionHistory == null) { return Collections.emptyList(); } // Don't allow our not-thread-safe, mutable list to escape! return ImmutableList.copyOf(sessionHistory); } }); }
return cacheCreationLocks.get(name).withLock(new com.atlassian.util.concurrent.Supplier<ManagedCache>()
@Override protected ManagedCache createSimpleCache(@Nonnull final String name, @Nonnull final CacheSettings settings) { checkSettingsAreCompatible(name, settings); ManagedCache existing = getManagedCache(name); if (existing != null) { return existing; } return cacheCreationLocks.get(name).withLock(new com.atlassian.util.concurrent.Supplier<ManagedCache>() { @Override public ManagedCache get() { if (!caches.containsKey(name)) { caches.put(name, new StrongSupplier<ManagedCache>((ManagedCache) doCreateCache(name, null, settings))); } return caches.get(name).get(); } }); }