Use Guava to initialize concurrent linked queues

This commit is contained in:
Felix Cravic 2020-12-08 09:36:19 +01:00
parent fec23a9783
commit 42cedf3fbf
6 changed files with 21 additions and 14 deletions

View File

@ -1,5 +1,6 @@
package net.minestom.server;
import com.google.common.collect.Queues;
import net.minestom.server.entity.EntityManager;
import net.minestom.server.instance.Instance;
import net.minestom.server.instance.InstanceManager;
@ -9,7 +10,11 @@ import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.concurrent.*;
import java.util.Queue;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.LongConsumer;
/**
@ -26,8 +31,8 @@ public final class UpdateManager {
private ThreadProvider threadProvider;
private final ConcurrentLinkedQueue<LongConsumer> tickStartCallbacks = new ConcurrentLinkedQueue<>();
private final ConcurrentLinkedQueue<LongConsumer> tickEndCallbacks = new ConcurrentLinkedQueue<>();
private final Queue<LongConsumer> tickStartCallbacks = Queues.newConcurrentLinkedQueue();
private final Queue<LongConsumer> tickEndCallbacks = Queues.newConcurrentLinkedQueue();
{
// DEFAULT THREAD PROVIDER
@ -106,7 +111,7 @@ public final class UpdateManager {
* @param callbacks the callbacks to execute
* @param value the value to give to the consumers
*/
private void doTickCallback(ConcurrentLinkedQueue<LongConsumer> callbacks, long value) {
private void doTickCallback(Queue<LongConsumer> callbacks, long value) {
if (!callbacks.isEmpty()) {
LongConsumer callback;
while ((callback = callbacks.poll()) != null) {

View File

@ -1,5 +1,6 @@
package net.minestom.server.entity;
import com.google.common.collect.Queues;
import net.minestom.server.MinecraftServer;
import net.minestom.server.Viewable;
import net.minestom.server.chat.ColoredText;
@ -40,7 +41,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
@ -132,7 +132,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
protected Pose pose = Pose.STANDING;
// list of scheduled tasks to be executed during the next entity tick
protected final ConcurrentLinkedQueue<Consumer<Entity>> nextTick = new ConcurrentLinkedQueue<>();
protected final Queue<Consumer<Entity>> nextTick = Queues.newConcurrentLinkedQueue();
// Tick related
private long ticks;

View File

@ -1,5 +1,6 @@
package net.minestom.server.entity;
import com.google.common.collect.Queues;
import net.minestom.server.MinecraftServer;
import net.minestom.server.chat.ChatColor;
import net.minestom.server.chat.ColoredText;
@ -11,8 +12,8 @@ import net.minestom.server.network.packet.server.play.KeepAlivePacket;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;
public final class EntityManager {
@ -23,7 +24,7 @@ public final class EntityManager {
private static final long KEEP_ALIVE_KICK = 30_000;
private static final ColoredText TIMEOUT_TEXT = ColoredText.of(ChatColor.RED + "Timeout");
private final ConcurrentLinkedQueue<Player> waitingPlayers = new ConcurrentLinkedQueue<>();
private final Queue<Player> waitingPlayers = Queues.newConcurrentLinkedQueue();
/**
* Connects waiting players.

View File

@ -1,5 +1,6 @@
package net.minestom.server.entity;
import com.google.common.collect.Queues;
import net.minestom.server.MinecraftServer;
import net.minestom.server.advancements.AdvancementTab;
import net.minestom.server.attribute.Attribute;
@ -65,7 +66,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
@ -134,7 +134,7 @@ public class Player extends LivingEntity implements CommandSender {
private final AtomicInteger teleportId = new AtomicInteger();
protected boolean onGround;
private final ConcurrentLinkedQueue<ClientPlayPacket> packets = new ConcurrentLinkedQueue<>();
private final Queue<ClientPlayPacket> packets = Queues.newConcurrentLinkedQueue();
private final boolean levelFlat;
private final PlayerSettings settings;
private float exp;

View File

@ -1,5 +1,6 @@
package net.minestom.server.instance;
import com.google.common.collect.Queues;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMaps;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
@ -39,7 +40,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.Consumer;
@ -93,7 +93,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
protected UUID uniqueId;
// list of scheduled tasks to be executed during the next instance tick
protected final ConcurrentLinkedQueue<Consumer<Instance>> nextTick = new ConcurrentLinkedQueue<>();
protected final Queue<Consumer<Instance>> nextTick = Queues.newConcurrentLinkedQueue();
// instance custom data
private Data data;

View File

@ -1,5 +1,6 @@
package net.minestom.server.scoreboard;
import com.google.common.collect.Queues;
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
import net.minestom.server.chat.ChatParser;
import net.minestom.server.chat.ColoredText;
@ -13,8 +14,8 @@ import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
@ -45,7 +46,7 @@ public class Sidebar implements Scoreboard {
private final Set<Player> viewers = new CopyOnWriteArraySet<>();
private final ConcurrentLinkedQueue<ScoreboardLine> lines = new ConcurrentLinkedQueue<>();
private final Queue<ScoreboardLine> lines = Queues.newConcurrentLinkedQueue();
private final IntLinkedOpenHashSet availableColors = new IntLinkedOpenHashSet();
private final String objectiveName;