Meilleure gestion ignore list + correctifs divers

- Correction d'une cause probable d'un bug : l'arrêt des serveurs spigot se bloque après la sauvegarde des maps (donc logiquement après l'arrêt des plugins). La cause probable est qu'un thread non "daemon" ne s'arrête pas et bloque la fermeture du processus de Spigot. Le retrait de cette cause probable implique que chaque thread créé par le plugin doit être défini en daemon. (Thread#setDaemon())
This commit is contained in:
Marc Baloup 2016-08-18 15:27:46 +02:00
parent 0c1ac240f8
commit a6bccfc17a
5 changed files with 46 additions and 14 deletions

View File

@ -1,14 +1,19 @@
package fr.pandacube.java.util.db; package fr.pandacube.java.util.db;
import java.sql.Date; import java.sql.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import fr.pandacube.java.util.db.sql_tools.ORM; import fr.pandacube.java.util.db.sql_tools.ORM;
import fr.pandacube.java.util.db.sql_tools.ORMException; import fr.pandacube.java.util.db.sql_tools.ORMException;
import fr.pandacube.java.util.db.sql_tools.SQLElement; import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLElementList;
import fr.pandacube.java.util.db.sql_tools.SQLField; import fr.pandacube.java.util.db.sql_tools.SQLField;
import fr.pandacube.java.util.db.sql_tools.SQLType; import fr.pandacube.java.util.db.sql_tools.SQLType;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
public class SQLPlayer extends SQLElement<SQLPlayer> { public class SQLPlayer extends SQLElement<SQLPlayer> {
@ -83,9 +88,32 @@ public class SQLPlayer extends SQLElement<SQLPlayer> {
set(token, (t == null) ? (String) null : t.toString()); set(token, (t == null) ? (String) null : t.toString());
} }
public static SQLPlayer getPlayerFromUUID(UUID playerId) throws ORMException { public static SQLPlayer getPlayerFromUUID(UUID playerId) throws ORMException {
return ORM.getFirst(SQLPlayer.class, return ORM.getFirst(SQLPlayer.class,
new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, playerId.toString()), null); new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, playerId.toString()), null);
} }
public static SQLElementList<SQLPlayer> getPlayersFromUUIDs(Set<UUID> playerIds) throws ORMException {
Set<String> uuidsString = new HashSet<>();
for (UUID id : playerIds)
uuidsString.add(id.toString());
return getPlayersFromUUIDStr(uuidsString);
}
public static SQLElementList<SQLPlayer> getPlayersFromUUIDStr(Set<String> playerIds) throws ORMException {
SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR);
for (String userId : playerIds) {
where.add(new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, userId));
}
return ORM.getAll(SQLPlayer.class, where, null, null, null);
}
} }

View File

@ -1,13 +1,13 @@
package fr.pandacube.java.util.db; package fr.pandacube.java.util.db;
import java.util.ArrayList; import java.util.Map;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import fr.pandacube.java.util.db.sql_tools.ORM; import fr.pandacube.java.util.db.sql_tools.ORM;
import fr.pandacube.java.util.db.sql_tools.ORMException;
import fr.pandacube.java.util.db.sql_tools.SQLElement; import fr.pandacube.java.util.db.sql_tools.SQLElement;
import fr.pandacube.java.util.db.sql_tools.SQLElementList;
import fr.pandacube.java.util.db.sql_tools.SQLFKField; import fr.pandacube.java.util.db.sql_tools.SQLFKField;
import fr.pandacube.java.util.db.sql_tools.SQLOrderBy;
import fr.pandacube.java.util.db.sql_tools.SQLType; import fr.pandacube.java.util.db.sql_tools.SQLType;
import fr.pandacube.java.util.db.sql_tools.SQLWhereChain; import fr.pandacube.java.util.db.sql_tools.SQLWhereChain;
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; import fr.pandacube.java.util.db.sql_tools.SQLWhereComp;
@ -52,7 +52,7 @@ public class SQLPlayerIgnore extends SQLElement<SQLPlayerIgnore> {
set(ignored, (pName == null) ? (String) null : pName.toString()); set(ignored, (pName == null) ? (String) null : pName.toString());
} }
public static SQLPlayerIgnore getPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws Exception { public static SQLPlayerIgnore getPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws ORMException {
return ORM.getFirst(SQLPlayerIgnore.class, return ORM.getFirst(SQLPlayerIgnore.class,
new SQLWhereChain(SQLBoolOp.AND) new SQLWhereChain(SQLBoolOp.AND)
.add(new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString())) .add(new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString()))
@ -60,11 +60,11 @@ public class SQLPlayerIgnore extends SQLElement<SQLPlayerIgnore> {
null); null);
} }
public static boolean isPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws Exception { public static boolean isPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws ORMException {
return getPlayerIgnoringPlayer(ignorer, ignored) != null; return getPlayerIgnoringPlayer(ignorer, ignored) != null;
} }
public static void setPlayerIgnorePlayer(UUID ignorer, UUID ignored, boolean newIgnoreState) throws Exception { public static void setPlayerIgnorePlayer(UUID ignorer, UUID ignored, boolean newIgnoreState) throws ORMException {
SQLPlayerIgnore el = getPlayerIgnoringPlayer(ignorer, ignored); SQLPlayerIgnore el = getPlayerIgnoringPlayer(ignorer, ignored);
if (el == null && newIgnoreState) { if (el == null && newIgnoreState) {
el = new SQLPlayerIgnore(); el = new SQLPlayerIgnore();
@ -80,14 +80,12 @@ public class SQLPlayerIgnore extends SQLElement<SQLPlayerIgnore> {
} }
public static List<UUID> getListIgnoredPlayer(UUID ignorer) throws Exception { public static Map<String, SQLPlayer> getIgnoredPlayer(UUID ignorer) throws ORMException {
List<SQLPlayerIgnore> els = ORM.getAll(SQLPlayerIgnore.class, SQLElementList<SQLPlayerIgnore> els = ORM.getAll(SQLPlayerIgnore.class,
new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString()), new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString()),
new SQLOrderBy().addField(ORM.getSQLIdField(SQLPlayerIgnore.class)), null, null); null, null, null);
List<UUID> ret = new ArrayList<>(els.size());
for (SQLPlayerIgnore el : els) return els.getAllForeign(SQLPlayerIgnore.ignored);
ret.add(el.getIgnoredId());
return ret;
} }
} }

View File

@ -33,6 +33,7 @@ public class TCPClient extends Thread implements Closeable {
public TCPClient(InetSocketAddress a, String connName, TCPClientListener l) throws IOException { public TCPClient(InetSocketAddress a, String connName, TCPClientListener l) throws IOException {
super("TCPCl " + connName); super("TCPCl " + connName);
setDaemon(true);
if (a == null || l == null) throw new IllegalArgumentException("les arguments ne peuvent pas être null"); if (a == null || l == null) throw new IllegalArgumentException("les arguments ne peuvent pas être null");
socket = new Socket(); socket = new Socket();
socket.setReceiveBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE); socket.setReceiveBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE);

View File

@ -49,6 +49,7 @@ public class TCPServer extends Thread implements Closeable {
public TCPServer(int port, String sckName, TCPServerListener l) throws IOException { public TCPServer(int port, String sckName, TCPServerListener l) throws IOException {
super("TCPSv " + sckName); super("TCPSv " + sckName);
setDaemon(true);
if (port <= 0 || port > 65535) throw new IllegalArgumentException("le numéro de port est invalide"); if (port <= 0 || port > 65535) throw new IllegalArgumentException("le numéro de port est invalide");
socket = new ServerSocket(); socket = new ServerSocket();
socket.setReceiveBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE); socket.setReceiveBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE);
@ -97,6 +98,7 @@ public class TCPServer extends Thread implements Closeable {
public TCPServerClientConnection(Socket s, int coId) throws IOException { public TCPServerClientConnection(Socket s, int coId) throws IOException {
super("TCPSv " + socketName + " Conn#" + coId + " In"); super("TCPSv " + socketName + " Conn#" + coId + " In");
setDaemon(true);
socket = s; socket = s;
in = socket.getInputStream(); in = socket.getInputStream();
out = socket.getOutputStream(); out = socket.getOutputStream();
@ -189,6 +191,7 @@ public class TCPServer extends Thread implements Closeable {
public TCPServerConnectionOutputThread(int coId) { public TCPServerConnectionOutputThread(int coId) {
super("TCPSv " + socketName + " Conn#" + coId + " Out"); super("TCPSv " + socketName + " Conn#" + coId + " Out");
setDaemon(true);
} }
private void addPacket(PacketServer packet) { private void addPacket(PacketServer packet) {

View File

@ -4,7 +4,9 @@ public class ThreadNAPIExecutionHandler implements NAPIExecutionHandler {
@Override @Override
public void handleRun(Runnable executor) { public void handleRun(Runnable executor) {
new Thread(executor).start(); Thread t = new Thread(executor);
t.setDaemon(true);
t.start();
} }
} }