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

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

Best Java code snippets using com.atlassian.util.concurrent.ManagedLock.withLock (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

@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.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-ehcache

@Nonnull
@SuppressWarnings("unchecked")
@Override
public <V> CachedReference<V> getCachedReference(@Nonnull final String name,
                         @Nonnull final com.atlassian.cache.Supplier<V> supplier,
                         @Nonnull final CacheSettings settings)
{
  // Force the cache settings to be flushable and a maximum size of one.
  final CacheSettings overridenSettings = settings.override(
      new CacheSettingsBuilder().flushable().maxEntries(1).build());
  return cacheCreationLocks.get(name).withLock(new com.atlassian.util.concurrent.Supplier<DelegatingCachedReference<V>>()
    {
      @Override
      public DelegatingCachedReference<V> get()
      {
        final Ehcache spCache = getLoadingCache(name, overridenSettings, new ValueProcessorAtlassianCacheLoaderDecorator(new SupplierAdapter<>(supplier), valueProcessor));
        final DelegatingCachedReference<V> cache = DelegatingCachedReference.create(spCache, overridenSettings, valueProcessor);
        caches.put(name, new WeakSupplier<ManagedCache>(cache));
        return cache;
      }
    });
}
origin: com.atlassian.cache/atlassian-cache-ehcache

private ManagedCache createManagedCacheInternal(@Nonnull final String name, @Nonnull final CacheSettings settings) {
  return cacheCreationLocks.get(name).withLock(new Supplier<ManagedCache>()
    {
      @Override
      public ManagedCache get()
      {
        final ManagedCache result = caches.get(name) == null ? null : caches.get(name).get();
        if (result == null)
        {
          final Ehcache simpleCache = createCache(name, settings, false);
          DelegatingCache<?,?> cache = DelegatingCache.create(simpleCache, settings, valueProcessor);
          caches.put(name,  new StrongSupplier<ManagedCache>(cache));
          return cache;
        }
        return result;
      }
    });
}
origin: com.atlassian.jira/jira-core

@Override
public void updateScheme(final Scheme scheme) throws DataAccessException
{
  ManagedLocks.manage(getLock(scheme.getId(), UPDATE_SCHEME)).withLock(new Runnable()
  {
    @Override
    public void run()
    {
      final AssignableWorkflowScheme schemeObj = toWorkflowScheme(getScheme(scheme.getId()));
      checkMigration(schemeObj);
      doUpdateScheme(scheme);
    }
  });
}
origin: com.atlassian.jira/jira-core

public void addHistoryItem(final ApplicationUser user, @Nonnull final UserHistoryItem historyItem)
{
  notNull("historyItem", historyItem);
  if (user != null)
  {
    moveAnonymousSessionLeftoversToUserStore(user, historyItem.getType());
    // JRADEV-15768
    // Don't call the delegatingStore while the lock is held!  Was causing deadlock between DB and JIRA.
    delegatingStore.addHistoryItem(user, historyItem);
    return;
  }
  final VelocityRequestSession session = getSession();
  if (session != null)
  {
    lockManager.get(session).withLock(new Runnable()
    {
      public void run()
      {
        addAnonymousSessionHistoryItem(session, historyItem);
      }
    });
  }
}
com.atlassian.util.concurrentManagedLockwithLock

Javadoc

Execute the supplied Supplier under a lock determined by the descriptor.

Unlike #withLock(Callable) this version returns a result and does not declare a checked exception.

Popular methods of ManagedLock

    Popular in Java

    • Reading from database using SQL prepared statement
    • getSupportFragmentManager (FragmentActivity)
    • findViewById (Activity)
    • addToBackStack (FragmentTransaction)
    • BufferedInputStream (java.io)
      A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
    • Enumeration (java.util)
      A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
    • UUID (java.util)
      UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
    • Executors (java.util.concurrent)
      Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
    • HttpServletRequest (javax.servlet.http)
      Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
    • Join (org.hibernate.mapping)
    • Top plugins for WebStorm
    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