feat: add get private socket endpoint
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package fr.titionfire.ffsaf.net2;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import fr.titionfire.ffsaf.domain.service.ClubService;
|
||||
import fr.titionfire.ffsaf.domain.service.CombService;
|
||||
import fr.titionfire.ffsaf.net2.packet.IAction;
|
||||
import fr.titionfire.ffsaf.net2.packet.RegisterAction;
|
||||
import fr.titionfire.ffsaf.utils.Pair;
|
||||
import io.quarkus.runtime.ShutdownEvent;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
import jakarta.enterprise.event.Observes;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -25,8 +28,6 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@Singleton
|
||||
public class ServerCustom extends Thread {
|
||||
private static final Logger LOGGER = Logger.getLogger("SocketServer");
|
||||
@@ -38,6 +39,8 @@ public class ServerCustom extends Thread {
|
||||
private SSLServerSocket server;
|
||||
private boolean run;
|
||||
|
||||
private static ServerCustom serverCustom;
|
||||
|
||||
@ConfigProperty(name = "internal-port")
|
||||
int port;
|
||||
|
||||
@@ -50,6 +53,12 @@ public class ServerCustom extends Thread {
|
||||
@Inject
|
||||
protected Scheduler quartz;
|
||||
|
||||
@Inject
|
||||
public CombService combService;
|
||||
|
||||
@Inject
|
||||
public ClubService clubService;
|
||||
|
||||
private PublicKey publicKey;
|
||||
|
||||
private X509TrustManager tm(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
|
||||
@@ -134,6 +143,7 @@ public class ServerCustom extends Thread {
|
||||
|
||||
void onStart(@Observes StartupEvent ev) {
|
||||
LOGGER.info("The server is starting...");
|
||||
serverCustom = this;
|
||||
this.start();
|
||||
}
|
||||
|
||||
@@ -142,6 +152,10 @@ public class ServerCustom extends Thread {
|
||||
this.stop2();
|
||||
}
|
||||
|
||||
public static ServerCustom getInstance(){
|
||||
return serverCustom;
|
||||
}
|
||||
|
||||
public Stream<Client_Thread> get_clients() {
|
||||
return clients.stream();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import fr.titionfire.ffsaf.net2.Client_Thread;
|
||||
import fr.titionfire.ffsaf.net2.Message;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.vertx.SafeVertxContext;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import fr.titionfire.ffsaf.net2.Client_Thread;
|
||||
import fr.titionfire.ffsaf.net2.Message;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
public interface IAction {
|
||||
void dataIn(Client_Thread client_Thread, Message<JsonNode> message) throws JsonProcessingException;
|
||||
|
||||
39
src/main/java/fr/titionfire/ffsaf/net2/packet/RClub.java
Normal file
39
src/main/java/fr/titionfire/ffsaf/net2/packet/RClub.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package fr.titionfire.ffsaf.net2.packet;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RClub {
|
||||
private static final Logger LOGGER = Logger.getLogger(RClub.class);
|
||||
|
||||
final CIA<Long> findByIdOptionalClub = new CIA<>(Long.class, (client_Thread, message) -> {
|
||||
try {
|
||||
ClubModel clubModel = ServerCustom.getInstance().clubService.findByIdOptionalClub(message.data());
|
||||
client_Thread.sendRepTo(clubModel, message);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
client_Thread.sendErrTo(e.getMessage(), message);
|
||||
}
|
||||
});
|
||||
|
||||
final IAction findAllClub = (client_Thread, message) -> {
|
||||
try {
|
||||
Collection<ClubModel> clubModels = ServerCustom.getInstance().clubService.findAllClub();
|
||||
client_Thread.sendRepTo(clubModels, message);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
client_Thread.sendErrTo(e.getMessage(), message);
|
||||
}
|
||||
};
|
||||
|
||||
public static void register(HashMap<String, IAction> iMap) {
|
||||
RClub rClub = new RClub();
|
||||
|
||||
iMap.put("findByIdOptionalClub", rClub.findByIdOptionalClub);
|
||||
iMap.put("findAllClub", rClub.findAllClub);
|
||||
}
|
||||
}
|
||||
40
src/main/java/fr/titionfire/ffsaf/net2/packet/RComb.java
Normal file
40
src/main/java/fr/titionfire/ffsaf/net2/packet/RComb.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package fr.titionfire.ffsaf.net2.packet;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CombModel;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ApplicationScoped
|
||||
public class RComb {
|
||||
private static final Logger LOGGER = Logger.getLogger(RComb.class);
|
||||
|
||||
final IAction findComb = (client_Thread, message) -> {
|
||||
try {
|
||||
CombModel combModel = ServerCustom.getInstance().combService.find(message.data().get("licence").asInt(), message.data().get("np").asText());
|
||||
client_Thread.sendRepTo(combModel, message);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
client_Thread.sendErrTo(e.getMessage(), message);
|
||||
}
|
||||
};
|
||||
|
||||
final CIA<Long> findByIdOptionalComb = new CIA<>(Long.class, (client_Thread, message) -> {
|
||||
try {
|
||||
CombModel combModel = ServerCustom.getInstance().combService.findByIdOptionalComb(message.data());
|
||||
client_Thread.sendRepTo(combModel, message);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
client_Thread.sendErrTo(e.getMessage(), message);
|
||||
}
|
||||
});
|
||||
|
||||
public static void register(HashMap<String, IAction> iMap) {
|
||||
RComb rComb = new RComb();
|
||||
|
||||
iMap.put("findComb", rComb.findComb);
|
||||
iMap.put("findByIdOptionalComb", rComb.findByIdOptionalComb);
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,7 @@ public class RegisterAction {
|
||||
public static void register(HashMap<String, IAction> iMap) {
|
||||
iMap.clear();
|
||||
|
||||
RComb.register(iMap);
|
||||
RClub.register(iMap);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user