From 1285317289c94902f3b5a0058eb2956faee60ff8 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Sat, 20 May 2023 18:09:45 +0100 Subject: [PATCH] Add client open event for NetMarshalServer. --- .../lib/calmnet/marshal/NetMarshalClient.java | 2 +- .../lib/calmnet/marshal/NetMarshalServer.java | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/com/captainalm/lib/calmnet/marshal/NetMarshalClient.java b/src/com/captainalm/lib/calmnet/marshal/NetMarshalClient.java index 5774836..e6899f9 100644 --- a/src/com/captainalm/lib/calmnet/marshal/NetMarshalClient.java +++ b/src/com/captainalm/lib/calmnet/marshal/NetMarshalClient.java @@ -583,7 +583,7 @@ public class NetMarshalClient implements Closeable { /** * Gets the {@link Consumer} closed consumer. * - * @return The closed or null. + * @return The closed consumer or null. */ public Consumer getClosedConsumer() { return closedConsumer; diff --git a/src/com/captainalm/lib/calmnet/marshal/NetMarshalServer.java b/src/com/captainalm/lib/calmnet/marshal/NetMarshalServer.java index 1a79bc4..9f636b6 100644 --- a/src/com/captainalm/lib/calmnet/marshal/NetMarshalServer.java +++ b/src/com/captainalm/lib/calmnet/marshal/NetMarshalServer.java @@ -35,6 +35,7 @@ public class NetMarshalServer implements Closeable { protected BiConsumer receiveBiConsumer; protected BiConsumer receiveExceptionBiConsumer; protected BiConsumer acceptExceptionBiConsumer; + protected Consumer openedConsumer; protected Consumer closedConsumer; protected BiConsumer acceptanceBiConsumer; protected BiConsumer socketSetupBiConsumer; @@ -286,7 +287,7 @@ public class NetMarshalServer implements Closeable { /** * Gets the {@link Consumer} closed consumer. * - * @return The closed or null. + * @return The closed consumer or null. */ public Consumer getClosedConsumer() { return closedConsumer; @@ -303,6 +304,26 @@ public class NetMarshalServer implements Closeable { closedConsumer = consumer; } + /** + * Gets the {@link Consumer} opened consumer. + * + * @return The opened consumer or null. + */ + public Consumer getOpenedConsumer() { + return openedConsumer; + } + + /** + * Sets the {@link Consumer} opened consumer. + * + * @param consumer The new opened consumer. + * @throws NullPointerException consumer is null. + */ + public void setOpenedConsumer(Consumer consumer) { + if (consumer == null) throw new NullPointerException("consumer is null"); + openedConsumer = consumer; + } + /** * Gets the {@link BiConsumer} client acceptance consumer. * Use {@link CandidateClient#accept} to declare whether the candidate should be accepted. @@ -418,6 +439,7 @@ public class NetMarshalServer implements Closeable { } } found.open(); + if (openedConsumer != null) openedConsumer.accept(found); return found; } return null; @@ -485,6 +507,7 @@ public class NetMarshalServer implements Closeable { clients.add(client); } client.open(); + if (openedConsumer != null) openedConsumer.accept(client); } else { clientSocket.close(); } @@ -527,6 +550,7 @@ public class NetMarshalServer implements Closeable { applyClientEvents(client); clients.add(client); client.open(); + if (openedConsumer != null) openedConsumer.accept(client); } } catch (Exception e) { synchronized (slockOutputs) {