mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Use Guava for building thread factory, remove reudndant utility
This commit is contained in:
@@ -20,11 +20,12 @@ import org.apollo.io.MessageHandlerChainSetParser;
|
||||
import org.apollo.login.LoginService;
|
||||
import org.apollo.net.session.GameSession;
|
||||
import org.apollo.util.MobRepository;
|
||||
import org.apollo.util.NamedThreadFactory;
|
||||
import org.apollo.util.xml.XmlNode;
|
||||
import org.apollo.util.xml.XmlParser;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
/**
|
||||
* The {@link GameService} class schedules and manages the execution of the {@link GamePulseHandler} class.
|
||||
*
|
||||
@@ -51,7 +52,7 @@ public final class GameService extends Service {
|
||||
/**
|
||||
* The scheduled executor service.
|
||||
*/
|
||||
private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("GameService"));
|
||||
private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("GameService").build());
|
||||
|
||||
/**
|
||||
* The {@link ClientSynchronizer}.
|
||||
|
||||
@@ -22,7 +22,8 @@ import org.apollo.game.sync.task.PreNpcSynchronizationTask;
|
||||
import org.apollo.game.sync.task.PrePlayerSynchronizationTask;
|
||||
import org.apollo.game.sync.task.SynchronizationTask;
|
||||
import org.apollo.util.MobRepository;
|
||||
import org.apollo.util.NamedThreadFactory;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
/**
|
||||
* An implementation of {@link ClientSynchronizer} which runs in a thread pool. A {@link Phaser} is used to ensure that
|
||||
@@ -52,7 +53,7 @@ public final class ParallelClientSynchronizer extends ClientSynchronizer {
|
||||
*/
|
||||
public ParallelClientSynchronizer() {
|
||||
int processors = Runtime.getRuntime().availableProcessors();
|
||||
ThreadFactory factory = new NamedThreadFactory("ClientSynchronizer");
|
||||
ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("ClientSynchronizer").build();
|
||||
executor = Executors.newFixedThreadPool(processors, factory);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,12 @@ import org.apollo.net.codec.login.LoginRequest;
|
||||
import org.apollo.net.release.Release;
|
||||
import org.apollo.net.session.GameSession;
|
||||
import org.apollo.net.session.LoginSession;
|
||||
import org.apollo.util.NamedThreadFactory;
|
||||
import org.apollo.util.xml.XmlNode;
|
||||
import org.apollo.util.xml.XmlParser;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
/**
|
||||
* The {@link LoginService} manages {@link LoginRequest}s.
|
||||
*
|
||||
@@ -32,7 +33,7 @@ public final class LoginService extends Service {
|
||||
/**
|
||||
* The {@link ExecutorService} to which workers are submitted.
|
||||
*/
|
||||
private final ExecutorService executor = Executors.newCachedThreadPool(new NamedThreadFactory("LoginService"));
|
||||
private final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("LoginService").build());
|
||||
|
||||
/**
|
||||
* The current {@link PlayerSerializer}.
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package org.apollo.util;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* A {@link ThreadFactory} which gives each thread a unique name made up of the name supplied in the constructor and
|
||||
* postfixed with an id.
|
||||
* <p>
|
||||
* For example, if the name {@code MyThread} was given and a third thread was created by the factory, the resulting name
|
||||
* would be {@code MyThread [id=2]}.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public final class NamedThreadFactory implements ThreadFactory {
|
||||
|
||||
/**
|
||||
* The next id.
|
||||
*/
|
||||
private AtomicInteger id = new AtomicInteger(0);
|
||||
|
||||
/**
|
||||
* The unique name.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Creates the named thread factory.
|
||||
*
|
||||
* @param name The unique name.
|
||||
*/
|
||||
public NamedThreadFactory(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable runnable) {
|
||||
int currentId = id.getAndIncrement();
|
||||
return new Thread(runnable, name + " [id=" + currentId + "]");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user