Compare commits

..

No commits in common. "12326fe1224ff9919a0f7eb12c1ba3ad728d1356" and "54442355129656b8f2e735ef15708dfa4819b839" have entirely different histories.

9 changed files with 63 additions and 98 deletions

View File

@ -16,7 +16,6 @@ import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.unchecked.Unchecked; import io.smallrye.mutiny.unchecked.Unchecked;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.ws.rs.ForbiddenException; import jakarta.ws.rs.ForbiddenException;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -24,7 +23,6 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.time.Duration; import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.concurrent.Executor;
import static fr.titionfire.ffsaf.net2.Client_Thread.MAPPER; import static fr.titionfire.ffsaf.net2.Client_Thread.MAPPER;
@ -53,15 +51,6 @@ public class CompetitionWS {
@Inject @Inject
CompetPermService competPermService; CompetPermService competPermService;
@SuppressWarnings("CdiInjectionPointsInspection")
@Inject
OpenConnections connections;
@Inject
@Named("notify-executor")
Executor notifyExecutor;
private static Executor executor;
@Inject @Inject
CompetitionRepository competitionRepository; CompetitionRepository competitionRepository;
@ -90,8 +79,6 @@ public class CompetitionWS {
getWSReceiverMethods(RCategorie.class, rCategorie); getWSReceiverMethods(RCategorie.class, rCategorie);
getWSReceiverMethods(RRegister.class, rRegister); getWSReceiverMethods(RRegister.class, rRegister);
getWSReceiverMethods(RCardboard.class, rCardboard); getWSReceiverMethods(RCardboard.class, rCardboard);
executor = notifyExecutor;
} }
@OnOpen @OnOpen
@ -199,7 +186,7 @@ public class CompetitionWS {
// return Uni.createFrom().item(new Message<>(message.uuid(), message.code(), MessageType.REPLY, "ko")); // return Uni.createFrom().item(new Message<>(message.uuid(), message.code(), MessageType.REPLY, "ko"));
} }
public static void sendNotifyToOtherEditor(WebSocketConnection connection, String code, Object data) { public static Uni<Void> sendNotifyToOtherEditor(WebSocketConnection connection, String code, Object data) {
String uuid = connection.pathParam("uuid"); String uuid = connection.pathParam("uuid");
List<Uni<Void>> queue = new ArrayList<>(); List<Uni<Void>> queue = new ArrayList<>();
@ -211,15 +198,7 @@ public class CompetitionWS {
} }
}); });
Uni.join().all(queue) return Uni.join().all(queue).andCollectFailures().onFailure().recoverWithNull().replaceWithVoid();
.andCollectFailures()
.runSubscriptionOn(executor)
.subscribeAsCompletionStage()
.whenComplete((v, t) -> {
if (t != null) {
LOGGER.error("Error sending ws_out message", t);
}
});
} }
@OnError @OnError

View File

@ -1,19 +0,0 @@
package fr.titionfire.ffsaf.ws;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
import jakarta.inject.Singleton;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@Singleton
public class ExecutorProducer {
@Produces
@Named("notify-executor")
public Executor produceNotifyExecutor() {
// Créez un pool de threads avec une taille fixe (par exemple, 10 threads)
return Executors.newFixedThreadPool(10);
}
}

View File

@ -80,32 +80,35 @@ public class RCardboard {
return Uni.createFrom().nullItem(); return Uni.createFrom().nullItem();
return Panache.withTransaction(() -> cardboardRepository.persist(cardboardModel)); return Panache.withTransaction(() -> cardboardRepository.persist(cardboardModel));
})) }))
.invoke(model -> SSCardboard.sendCardboard(connection, CardboardEntity.fromModel(model))) .call(model -> SSCardboard.sendCardboard(connection, CardboardEntity.fromModel(model)))
.replaceWithVoid(); .replaceWithVoid();
} }
@WSReceiver(code = "getCardboardWithoutThis", permission = PermLevel.VIEW) @WSReceiver(code = "getCardboardWithoutThis", permission = PermLevel.VIEW)
public Uni<CardboardAllMatch> getCardboardWithoutThis(WebSocketConnection connection, Long matchId) { public Uni<CardboardAllMatch> getCardboardWithoutThis(WebSocketConnection connection, Long matchId) {
return getById(matchId, connection) return getById(matchId, connection)
.chain(matchModel -> cardboardRepository.list("compet = ?1 AND match != ?2", .chain(matchModel -> cardboardRepository.list("compet = ?1 AND match != ?2", matchModel.getCategory().getCompet(), matchModel)
matchModel.getCategory().getCompet(), matchModel)
.map(models -> { .map(models -> {
CardboardAllMatch out = new CardboardAllMatch(); CardboardAllMatch out = new CardboardAllMatch();
for (CardboardModel c : models) { models.stream().filter(c -> (matchModel.getC1_id() != null
if ((matchModel.getC1_id() != null && Objects.equals(c.getComb(), && Objects.equals(c.getComb(), matchModel.getC1_id()))
matchModel.getC1_id())) || (matchModel.getC1_guest() != null && Objects.equals( || (matchModel.getC1_guest() != null
c.getGuestComb(), matchModel.getC1_guest()))) { && Objects.equals(c.getGuestComb(), matchModel.getC1_guest())))
.forEach(c -> {
out.c1_yellow += c.getYellow(); out.c1_yellow += c.getYellow();
out.c1_red += c.getRed(); out.c1_red += c.getRed();
} });
if ((matchModel.getC2_id() != null && Objects.equals(c.getComb(),
matchModel.getC2_id())) || (matchModel.getC2_guest() != null && Objects.equals( models.stream().filter(c -> (matchModel.getC2_id() != null
c.getGuestComb(), matchModel.getC2_guest()))) { && Objects.equals(c.getComb(), matchModel.getC2_id()))
|| (matchModel.getC2_guest() != null
&& Objects.equals(c.getGuestComb(), matchModel.getC2_guest())))
.forEach(c -> {
out.c2_yellow += c.getYellow(); out.c2_yellow += c.getYellow();
out.c2_red += c.getRed(); out.c2_red += c.getRed();
} });
}
return out; return out;
})); }));
} }

View File

@ -97,7 +97,7 @@ public class RCategorie {
return categoryRepository.create(categoryModel); return categoryRepository.create(categoryModel);
}) })
.invoke(cat -> SSCategorie.sendAddCategory(connection, cat)) .call(cat -> SSCategorie.sendAddCategory(connection, cat))
.map(CategoryModel::getId); .map(CategoryModel::getId);
} }
@ -121,7 +121,7 @@ public class RCategorie {
Uni<Long> finalUni = uni; Uni<Long> finalUni = uni;
return Panache.withTransaction(() -> finalUni); return Panache.withTransaction(() -> finalUni);
}) })
.invoke(cat -> SSCategorie.sendCategory(connection, cat)) .call(cat -> SSCategorie.sendCategory(connection, cat))
.replaceWithVoid(); .replaceWithVoid();
} }
@ -202,7 +202,7 @@ public class RCategorie {
.call(__ -> treeRepository.flush()) .call(__ -> treeRepository.flush())
.call(cat -> treeRepository.list("category = ?1 AND level != 0", cat.getId()) .call(cat -> treeRepository.list("category = ?1 AND level != 0", cat.getId())
.map(treeModels -> treeModels.stream().map(TreeEntity::fromModel).toList()) .map(treeModels -> treeModels.stream().map(TreeEntity::fromModel).toList())
.invoke(trees -> SSCategorie.sendTreeCategory(connection, trees))) .chain(trees -> SSCategorie.sendTreeCategory(connection, trees)))
.replaceWithVoid(); .replaceWithVoid();
} }
@ -212,7 +212,7 @@ public class RCategorie {
.call(cat -> Panache.withTransaction(() -> treeRepository.delete("category = ?1", cat.getId()) .call(cat -> Panache.withTransaction(() -> treeRepository.delete("category = ?1", cat.getId())
.call(__ -> matchRepository.delete("category = ?1", cat)))) .call(__ -> matchRepository.delete("category = ?1", cat))))
.chain(cat -> Panache.withTransaction(() -> categoryRepository.delete(cat))) .chain(cat -> Panache.withTransaction(() -> categoryRepository.delete(cat)))
.invoke(__ -> SSCategorie.sendDelCategory(connection, id)) .call(__ -> SSCategorie.sendDelCategory(connection, id))
.replaceWithVoid(); .replaceWithVoid();
} }

View File

@ -84,7 +84,7 @@ public class RMatch {
})) }))
.chain(categoryModel -> creatMatch(categoryModel, m)) .chain(categoryModel -> creatMatch(categoryModel, m))
.chain(mm -> Panache.withTransaction(() -> matchRepository.create(mm))) .chain(mm -> Panache.withTransaction(() -> matchRepository.create(mm)))
.invoke(mm -> SSMatch.sendMatch(connection, MatchEntity.fromModel(mm))) .call(mm -> SSMatch.sendMatch(connection, MatchEntity.fromModel(mm)))
.replaceWithVoid(); .replaceWithVoid();
} }
@ -121,7 +121,7 @@ public class RMatch {
mm.setC2_guest(null); mm.setC2_guest(null);
})) }))
.chain(mm -> Panache.withTransaction(() -> matchRepository.persist(mm))) .chain(mm -> Panache.withTransaction(() -> matchRepository.persist(mm)))
.invoke(mm -> SSMatch.sendMatch(connection, MatchEntity.fromModel(mm))) .call(mm -> SSMatch.sendMatch(connection, MatchEntity.fromModel(mm)))
.replaceWithVoid(); .replaceWithVoid();
} }
@ -136,7 +136,7 @@ public class RMatch {
m.getCategory_ord())) m.getCategory_ord()))
.invoke(m -> m.setCategory_ord(order.pos)) .invoke(m -> m.setCategory_ord(order.pos))
.call(m -> Panache.withTransaction(() -> matchRepository.persist(m))) .call(m -> Panache.withTransaction(() -> matchRepository.persist(m)))
.invoke(mm -> SSMatch.sendMatchOrder(connection, order)) .call(mm -> SSMatch.sendMatchOrder(connection, order))
.replaceWithVoid(); .replaceWithVoid();
} }
@ -163,12 +163,12 @@ public class RMatch {
.call(mm -> { .call(mm -> {
if (mm.isEnd() && mm.win() != old_win && mm.getCategory_ord() == -42) { if (mm.isEnd() && mm.win() != old_win && mm.getCategory_ord() == -42) {
return updateEndAndTree(mm, new ArrayList<>()) return updateEndAndTree(mm, new ArrayList<>())
.invoke(l -> SSMatch.sendMatch(connection, l)); .call(l -> SSMatch.sendMatch(connection, l));
} }
return Uni.createFrom().nullItem(); return Uni.createFrom().nullItem();
}); });
}) })
.invoke(mm -> SSMatch.sendMatch(connection, MatchEntity.fromModel(mm))) .call(mm -> SSMatch.sendMatch(connection, MatchEntity.fromModel(mm)))
.replaceWithVoid(); .replaceWithVoid();
} }
@ -189,7 +189,7 @@ public class RMatch {
}) })
.invoke(mm -> toSend.add(MatchEntity.fromModel(mm))) .invoke(mm -> toSend.add(MatchEntity.fromModel(mm)))
.chain(mm -> updateEndAndTree(mm, toSend)) .chain(mm -> updateEndAndTree(mm, toSend))
.invoke(__ -> SSMatch.sendMatch(connection, toSend)) .call(__ -> SSMatch.sendMatch(connection, toSend))
.replaceWithVoid(); .replaceWithVoid();
} }
@ -278,7 +278,7 @@ public class RMatch {
public Uni<Void> deleteMatch(WebSocketConnection connection, Long idMatch) { public Uni<Void> deleteMatch(WebSocketConnection connection, Long idMatch) {
return getById(idMatch, connection) return getById(idMatch, connection)
.chain(matchModel -> Panache.withTransaction(() -> matchRepository.delete(matchModel))) .chain(matchModel -> Panache.withTransaction(() -> matchRepository.delete(matchModel)))
.invoke(__ -> SSMatch.sendDeleteMatch(connection, idMatch)) .call(__ -> SSMatch.sendDeleteMatch(connection, idMatch))
.replaceWithVoid(); .replaceWithVoid();
} }
@ -295,7 +295,7 @@ public class RMatch {
.call(cm -> data.matchesToRemove.isEmpty() ? Uni.createFrom().voidItem() : .call(cm -> data.matchesToRemove.isEmpty() ? Uni.createFrom().voidItem() :
(Panache.withTransaction( (Panache.withTransaction(
() -> matchRepository.delete("id IN ?1 AND category = ?2", data.matchesToRemove, cm)) () -> matchRepository.delete("id IN ?1 AND category = ?2", data.matchesToRemove, cm))
.invoke(__ -> SSMatch.sendDeleteMatch(connection, data.matchesToRemove)))) .call(__ -> SSMatch.sendDeleteMatch(connection, data.matchesToRemove))))
.call(cm -> Panache.withSession(() -> matchRepository.list("id IN ?1 AND category = ?2", .call(cm -> Panache.withSession(() -> matchRepository.list("id IN ?1 AND category = ?2",
Stream.concat(data.matchOrderToUpdate.keySet().stream(), Stream.concat(data.matchOrderToUpdate.keySet().stream(),
data.matchPouleToUpdate.keySet().stream()) data.matchPouleToUpdate.keySet().stream())
@ -321,7 +321,7 @@ public class RMatch {
.chain(mm -> mm.isEmpty() ? Uni.createFrom().voidItem() : .chain(mm -> mm.isEmpty() ? Uni.createFrom().voidItem() :
Panache.withTransaction(() -> matchRepository.create(mm)) Panache.withTransaction(() -> matchRepository.create(mm))
.invoke(__ -> matches.addAll(mm.stream().map(MatchEntity::fromModel).toList()))) .invoke(__ -> matches.addAll(mm.stream().map(MatchEntity::fromModel).toList())))
.invoke(__ -> SSMatch.sendMatch(connection, matches)) .call(__ -> SSMatch.sendMatch(connection, matches))
.replaceWithVoid(); .replaceWithVoid();
} }

View File

@ -3,10 +3,11 @@ package fr.titionfire.ffsaf.ws.send;
import fr.titionfire.ffsaf.domain.entity.CardboardEntity; import fr.titionfire.ffsaf.domain.entity.CardboardEntity;
import fr.titionfire.ffsaf.ws.CompetitionWS; import fr.titionfire.ffsaf.ws.CompetitionWS;
import io.quarkus.websockets.next.WebSocketConnection; import io.quarkus.websockets.next.WebSocketConnection;
import io.smallrye.mutiny.Uni;
public class SSCardboard { public class SSCardboard {
public static void sendCardboard(WebSocketConnection connection, CardboardEntity cardboardEntity) { public static Uni<Void> sendCardboard(WebSocketConnection connection, CardboardEntity cardboardEntity) {
CompetitionWS.sendNotifyToOtherEditor(connection, "sendCardboard", cardboardEntity); return CompetitionWS.sendNotifyToOtherEditor(connection, "sendCardboard", cardboardEntity);
} }
} }

View File

@ -5,32 +5,33 @@ import fr.titionfire.ffsaf.domain.entity.TreeEntity;
import fr.titionfire.ffsaf.ws.CompetitionWS; import fr.titionfire.ffsaf.ws.CompetitionWS;
import fr.titionfire.ffsaf.ws.recv.RCategorie; import fr.titionfire.ffsaf.ws.recv.RCategorie;
import io.quarkus.websockets.next.WebSocketConnection; import io.quarkus.websockets.next.WebSocketConnection;
import io.smallrye.mutiny.Uni;
import java.util.List; import java.util.List;
public class SSCategorie { public class SSCategorie {
public static void sendAddCategory(WebSocketConnection connection, CategoryModel category) { public static Uni<Void> sendAddCategory(WebSocketConnection connection, CategoryModel category) {
SSCategorie.sendAddCategory(connection, RCategorie.JustCategorie.from(category)); return SSCategorie.sendAddCategory(connection, RCategorie.JustCategorie.from(category));
} }
public static void sendAddCategory(WebSocketConnection connection, RCategorie.JustCategorie justCategorie) { public static Uni<Void> sendAddCategory(WebSocketConnection connection, RCategorie.JustCategorie justCategorie) {
CompetitionWS.sendNotifyToOtherEditor(connection, "sendAddCategory", justCategorie); return CompetitionWS.sendNotifyToOtherEditor(connection, "sendAddCategory", justCategorie);
} }
public static void sendCategory(WebSocketConnection connection, CategoryModel category) { public static Uni<Void> sendCategory(WebSocketConnection connection, CategoryModel category) {
SSCategorie.sendCategory(connection, RCategorie.JustCategorie.from(category)); return SSCategorie.sendCategory(connection, RCategorie.JustCategorie.from(category));
} }
public static void sendCategory(WebSocketConnection connection, RCategorie.JustCategorie justCategorie) { public static Uni<Void> sendCategory(WebSocketConnection connection, RCategorie.JustCategorie justCategorie) {
CompetitionWS.sendNotifyToOtherEditor(connection, "sendCategory", justCategorie); return CompetitionWS.sendNotifyToOtherEditor(connection, "sendCategory", justCategorie);
} }
public static void sendTreeCategory(WebSocketConnection connection, List<TreeEntity> treeEntities) { public static Uni<Void> sendTreeCategory(WebSocketConnection connection, List<TreeEntity> treeEntities) {
CompetitionWS.sendNotifyToOtherEditor(connection, "sendTreeCategory", treeEntities); return CompetitionWS.sendNotifyToOtherEditor(connection, "sendTreeCategory", treeEntities);
} }
public static void sendDelCategory(WebSocketConnection connection, Long id) { public static Uni<?> sendDelCategory(WebSocketConnection connection, Long id) {
CompetitionWS.sendNotifyToOtherEditor(connection, "sendDelCategory", id); return CompetitionWS.sendNotifyToOtherEditor(connection, "sendDelCategory", id);
} }
} }

View File

@ -4,28 +4,29 @@ import fr.titionfire.ffsaf.domain.entity.MatchEntity;
import fr.titionfire.ffsaf.ws.CompetitionWS; import fr.titionfire.ffsaf.ws.CompetitionWS;
import fr.titionfire.ffsaf.ws.recv.RMatch; import fr.titionfire.ffsaf.ws.recv.RMatch;
import io.quarkus.websockets.next.WebSocketConnection; import io.quarkus.websockets.next.WebSocketConnection;
import io.smallrye.mutiny.Uni;
import java.util.List; import java.util.List;
public class SSMatch { public class SSMatch {
public static void sendMatch(WebSocketConnection connection, MatchEntity matchEntity) { public static Uni<Void> sendMatch(WebSocketConnection connection, MatchEntity matchEntity) {
SSMatch.sendMatch(connection, List.of(matchEntity)); return SSMatch.sendMatch(connection, List.of(matchEntity));
} }
public static void sendMatch(WebSocketConnection connection, List<MatchEntity> matchEntities) { public static Uni<Void> sendMatch(WebSocketConnection connection, List<MatchEntity> matchEntities) {
CompetitionWS.sendNotifyToOtherEditor(connection, "sendMatch", matchEntities); return CompetitionWS.sendNotifyToOtherEditor(connection, "sendMatch", matchEntities);
} }
public static void sendMatchOrder(WebSocketConnection connection, RMatch.MatchOrder matchOrder) { public static Uni<Void> sendMatchOrder(WebSocketConnection connection, RMatch.MatchOrder matchOrder) {
CompetitionWS.sendNotifyToOtherEditor(connection, "sendMatchOrder", matchOrder); return CompetitionWS.sendNotifyToOtherEditor(connection, "sendMatchOrder", matchOrder);
} }
public static void sendDeleteMatch(WebSocketConnection connection, Long l) { public static Uni<Void> sendDeleteMatch(WebSocketConnection connection, Long l) {
SSMatch.sendDeleteMatch(connection, List.of(l)); return SSMatch.sendDeleteMatch(connection, List.of(l));
} }
public static void sendDeleteMatch(WebSocketConnection connection, List<Long> longs) { public static Uni<Void> sendDeleteMatch(WebSocketConnection connection, List<Long> longs) {
CompetitionWS.sendNotifyToOtherEditor(connection, "sendDeleteMatch", longs); return CompetitionWS.sendNotifyToOtherEditor(connection, "sendDeleteMatch", longs);
} }
} }

View File

@ -8,7 +8,6 @@ quarkus.hibernate-orm.database.generation=update
quarkus.hibernate-orm.physical-naming-strategy=fr.titionfire.ffsaf.data.SafcaNamingStrategy quarkus.hibernate-orm.physical-naming-strategy=fr.titionfire.ffsaf.data.SafcaNamingStrategy
quarkus.hibernate-orm.dialect=fr.titionfire.ffsaf.data.CustomPostgreSQLDialect quarkus.hibernate-orm.dialect=fr.titionfire.ffsaf.data.CustomPostgreSQLDialect
quarkus.datasource.jdbc.reactive.max-size=40
quarkus.http.cors.enabled=true quarkus.http.cors.enabled=true
quarkus.quartz.start-mode=forced quarkus.quartz.start-mode=forced