Tabnine Logo
ManagedLock
Code IndexAdd Tabnine to your IDE (free)

How to use
ManagedLock
in
com.atlassian.util.concurrent

Best Java code snippets using com.atlassian.util.concurrent.ManagedLock (Showing top 20 results out of 315)

origin: com.atlassian.jira/jira-core

public void replaceAll(final Iterable<T> elements)
{
  lock.withLock(new Runnable()
  {
    public void run()
    {
      set = ImmutableSortedSet.copyOf(elements);
    }
  });
}
origin: com.atlassian.jira/jira-core

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;
    }
  });
}
origin: com.atlassian.cache/atlassian-cache-ehcache

@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;
    }
  });
}
origin: com.atlassian.jira/jira-core

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();
    }
  });
}
origin: com.atlassian.cache/atlassian-cache-memory

  @Override
  public void unregisterMBeans(@Nullable MBeanServer mBeanServer)
  {
    metricsLock.write().withLock(() ->
    {
      mbeansRegistrar.unregisterMBeans();
    });
  }
}
origin: com.atlassian.cache/atlassian-cache-memory

@Override
public void registerMBeans(@Nullable MBeanServer mBeanServer)
{
  metricsLock.write().withLock(() ->
  {
    mbeansRegistrar.enableCollectingJMXMetrics(mBeanServer, JMXMemoryCacheManager.this);
  });
}
origin: com.atlassian.cache/atlassian-cache-hazelcast

@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();
    }
  });
}
origin: com.atlassian.util.concurrent/atlassian-util-concurrent

 public void withLock(final T descriptor, final Runnable runnable) {
  lockFactory.get(stripeFunction.get(descriptor)).withLock(runnable);
 }
}
origin: com.atlassian.cache/atlassian-cache-hazelcast

@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();
    }
  });
}
origin: com.atlassian.cache/atlassian-cache-memory

@Override
protected void putCacheInMap(@Nonnull String name, @Nonnull Supplier<ManagedCache> supplier)
{
  metricsLock.read().withLock(() ->
  {
    JMXMemoryCacheManager.super.putCacheInMap(name, supplier);
    mbeansRegistrar.registerMBean(name);
  });
}
origin: com.atlassian.jira/jira-core

/**
 * 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);
      }
    });
  }
}
origin: com.atlassian.jira/jira-core

@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);
    }
  });
}
origin: com.atlassian.util.concurrent/atlassian-util-concurrent

public <R> R withLock(final T descriptor, final Supplier<R> supplier) {
 return lockFactory.get(stripeFunction.get(descriptor)).withLock(supplier);
}
origin: com.atlassian.util.concurrent/atlassian-util-concurrent

public <R> R withLock(final T descriptor, final Callable<R> callable) throws Exception {
 return lockFactory.get(stripeFunction.get(descriptor)).withLock(callable);
}
origin: com.atlassian.jira/jira-core

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;
    }
  });
}
origin: com.atlassian.cache/atlassian-cache-memory

                        @Nonnull final DelegatingCache.CreateFunction createFunction)
return cacheCreationLocks.get(name).withLock(new com.atlassian.util.concurrent.Supplier<ManagedCache>()
origin: com.atlassian.jira/jira-core

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));
}
origin: com.atlassian.jira/jira-core

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);
    }
  });
}
origin: com.atlassian.cache/atlassian-cache-memory

return cacheCreationLocks.get(name).withLock(new com.atlassian.util.concurrent.Supplier<ManagedCache>()
origin: com.atlassian.cache/atlassian-cache-hazelcast

@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();
    }
  });
}
com.atlassian.util.concurrentManagedLock

Javadoc

ManagedLock allows Callable, Runnable and Supplier to be run under a lock that is resolved against an input object.

Most used methods

  • withLock
    Execute the supplied Callable under a lock determined by the descriptor.

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setRequestProperty (URLConnection)
  • getSharedPreferences (Context)
  • runOnUiThread (Activity)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now