Add client open event for NetMarshalServer.

This commit is contained in:
Captain ALM 2023-05-20 18:09:45 +01:00
parent 93b40d57a3
commit 1285317289
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
2 changed files with 26 additions and 2 deletions

View File

@ -583,7 +583,7 @@ public class NetMarshalClient implements Closeable {
/** /**
* Gets the {@link Consumer} closed consumer. * Gets the {@link Consumer} closed consumer.
* *
* @return The closed or null. * @return The closed consumer or null.
*/ */
public Consumer<NetMarshalClient> getClosedConsumer() { public Consumer<NetMarshalClient> getClosedConsumer() {
return closedConsumer; return closedConsumer;

View File

@ -35,6 +35,7 @@ public class NetMarshalServer implements Closeable {
protected BiConsumer<IPacket, NetMarshalClient> receiveBiConsumer; protected BiConsumer<IPacket, NetMarshalClient> receiveBiConsumer;
protected BiConsumer<Exception, NetMarshalClient> receiveExceptionBiConsumer; protected BiConsumer<Exception, NetMarshalClient> receiveExceptionBiConsumer;
protected BiConsumer<Exception, NetMarshalServer> acceptExceptionBiConsumer; protected BiConsumer<Exception, NetMarshalServer> acceptExceptionBiConsumer;
protected Consumer<NetMarshalClient> openedConsumer;
protected Consumer<NetMarshalClient> closedConsumer; protected Consumer<NetMarshalClient> closedConsumer;
protected BiConsumer<CandidateClient, NetMarshalServer> acceptanceBiConsumer; protected BiConsumer<CandidateClient, NetMarshalServer> acceptanceBiConsumer;
protected BiConsumer<Socket, NetMarshalServer> socketSetupBiConsumer; protected BiConsumer<Socket, NetMarshalServer> socketSetupBiConsumer;
@ -286,7 +287,7 @@ public class NetMarshalServer implements Closeable {
/** /**
* Gets the {@link Consumer} closed consumer. * Gets the {@link Consumer} closed consumer.
* *
* @return The closed or null. * @return The closed consumer or null.
*/ */
public Consumer<NetMarshalClient> getClosedConsumer() { public Consumer<NetMarshalClient> getClosedConsumer() {
return closedConsumer; return closedConsumer;
@ -303,6 +304,26 @@ public class NetMarshalServer implements Closeable {
closedConsumer = consumer; closedConsumer = consumer;
} }
/**
* Gets the {@link Consumer} opened consumer.
*
* @return The opened consumer or null.
*/
public Consumer<NetMarshalClient> getOpenedConsumer() {
return openedConsumer;
}
/**
* Sets the {@link Consumer} opened consumer.
*
* @param consumer The new opened consumer.
* @throws NullPointerException consumer is null.
*/
public void setOpenedConsumer(Consumer<NetMarshalClient> consumer) {
if (consumer == null) throw new NullPointerException("consumer is null");
openedConsumer = consumer;
}
/** /**
* Gets the {@link BiConsumer} client acceptance consumer. * Gets the {@link BiConsumer} client acceptance consumer.
* Use {@link CandidateClient#accept} to declare whether the candidate should be accepted. * Use {@link CandidateClient#accept} to declare whether the candidate should be accepted.
@ -418,6 +439,7 @@ public class NetMarshalServer implements Closeable {
} }
} }
found.open(); found.open();
if (openedConsumer != null) openedConsumer.accept(found);
return found; return found;
} }
return null; return null;
@ -485,6 +507,7 @@ public class NetMarshalServer implements Closeable {
clients.add(client); clients.add(client);
} }
client.open(); client.open();
if (openedConsumer != null) openedConsumer.accept(client);
} else { } else {
clientSocket.close(); clientSocket.close();
} }
@ -527,6 +550,7 @@ public class NetMarshalServer implements Closeable {
applyClientEvents(client); applyClientEvents(client);
clients.add(client); clients.add(client);
client.open(); client.open();
if (openedConsumer != null) openedConsumer.accept(client);
} }
} catch (Exception e) { } catch (Exception e) {
synchronized (slockOutputs) { synchronized (slockOutputs) {