Search in sources :

Example 1 with UnlockHook

use of net.dv8tion.jda.internal.utils.UnlockHook in project JDA by DV8FromTheWorld.

the class AbstractCacheView method asList.

@Nonnull
@Override
public List<T> asList() {
    if (isEmpty())
        return Collections.emptyList();
    try (UnlockHook hook = readLock()) {
        List<T> list = getCachedList();
        if (list != null)
            return list;
        list = new ArrayList<>(elements.size());
        elements.forEachValue(list::add);
        return cache(list);
    }
}
Also used : UnlockHook(net.dv8tion.jda.internal.utils.UnlockHook) Nonnull(javax.annotation.Nonnull)

Example 2 with UnlockHook

use of net.dv8tion.jda.internal.utils.UnlockHook in project JDA by DV8FromTheWorld.

the class SortedSnowflakeCacheViewImpl method iterator.

@Nonnull
@Override
public Iterator<T> iterator() {
    try (UnlockHook hook = readLock()) {
        T[] arr = elements.values(emptyArray);
        Arrays.sort(arr, comparator);
        return new ObjectArrayIterator<>(arr);
    }
}
Also used : UnlockHook(net.dv8tion.jda.internal.utils.UnlockHook) ObjectArrayIterator(org.apache.commons.collections4.iterators.ObjectArrayIterator) Nonnull(javax.annotation.Nonnull)

Example 3 with UnlockHook

use of net.dv8tion.jda.internal.utils.UnlockHook in project JDA by DV8FromTheWorld.

the class SortedSnowflakeCacheViewImpl method asList.

@Nonnull
@Override
public List<T> asList() {
    if (isEmpty())
        return Collections.emptyList();
    try (UnlockHook hook = readLock()) {
        List<T> list = getCachedList();
        if (list != null)
            return list;
        list = new ArrayList<>(elements.size());
        elements.forEachValue(list::add);
        list.sort(comparator);
        return cache(list);
    }
}
Also used : UnlockHook(net.dv8tion.jda.internal.utils.UnlockHook) Nonnull(javax.annotation.Nonnull)

Example 4 with UnlockHook

use of net.dv8tion.jda.internal.utils.UnlockHook in project JDA by DV8FromTheWorld.

the class SortedSnowflakeCacheViewImpl method asSet.

@Nonnull
@Override
public NavigableSet<T> asSet() {
    if (isEmpty())
        return Collections.emptyNavigableSet();
    try (UnlockHook hook = readLock()) {
        NavigableSet<T> set = (NavigableSet<T>) getCachedSet();
        if (set != null)
            return set;
        set = new TreeSet<>(comparator);
        elements.forEachValue(set::add);
        return cache(set);
    }
}
Also used : UnlockHook(net.dv8tion.jda.internal.utils.UnlockHook) Nonnull(javax.annotation.Nonnull)

Example 5 with UnlockHook

use of net.dv8tion.jda.internal.utils.UnlockHook in project JDA by DV8FromTheWorld.

the class WebSocketClient method updateAudioManagerReferences.

protected void updateAudioManagerReferences() {
    AbstractCacheView<AudioManager> managerView = api.getAudioManagersView();
    try (UnlockHook hook = managerView.writeLock()) {
        final TLongObjectMap<AudioManager> managerMap = managerView.getMap();
        if (managerMap.size() > 0)
            LOG.trace("Updating AudioManager references");
        for (TLongObjectIterator<AudioManager> it = managerMap.iterator(); it.hasNext(); ) {
            it.advance();
            final long guildId = it.key();
            final AudioManagerImpl mng = (AudioManagerImpl) it.value();
            GuildImpl guild = (GuildImpl) api.getGuildById(guildId);
            if (guild == null) {
                // We no longer have access to the guild that this audio manager was for. Set the value to null.
                queuedAudioConnections.remove(guildId);
                mng.closeAudioConnection(ConnectionStatus.DISCONNECTED_REMOVED_DURING_RECONNECT);
                it.remove();
            }
        }
    }
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildImpl(net.dv8tion.jda.internal.entities.GuildImpl) AudioManagerImpl(net.dv8tion.jda.internal.managers.AudioManagerImpl) UnlockHook(net.dv8tion.jda.internal.utils.UnlockHook)

Aggregations

UnlockHook (net.dv8tion.jda.internal.utils.UnlockHook)32 CacheView (net.dv8tion.jda.api.utils.cache.CacheView)8 DataObject (net.dv8tion.jda.api.utils.data.DataObject)8 Nonnull (javax.annotation.Nonnull)6 JDAImpl (net.dv8tion.jda.internal.JDAImpl)5 DataArray (net.dv8tion.jda.api.utils.data.DataArray)4 GuildImpl (net.dv8tion.jda.internal.entities.GuildImpl)4 OnlineStatus (net.dv8tion.jda.api.OnlineStatus)3 AudioManager (net.dv8tion.jda.api.managers.AudioManager)3 AudioManagerImpl (net.dv8tion.jda.internal.managers.AudioManagerImpl)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 TLongSet (gnu.trove.set.TLongSet)2 ArrayList (java.util.ArrayList)2 LoginException (javax.security.auth.login.LoginException)2 ThreadMember (net.dv8tion.jda.api.entities.ThreadMember)2 User (net.dv8tion.jda.api.entities.User)2 TemplateRole (net.dv8tion.jda.api.entities.templates.TemplateRole)2 SnowflakeCacheViewImpl (net.dv8tion.jda.internal.utils.cache.SnowflakeCacheViewImpl)2 TLongObjectMap (gnu.trove.map.TLongObjectMap)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1