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);
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
}
}
}
Aggregations