Fix up method synchronisation.

This commit is contained in:
Captain ALM 2023-05-20 20:02:35 +01:00
parent 3934e2e861
commit 1949c848b8
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
2 changed files with 12 additions and 12 deletions

View File

@ -319,7 +319,7 @@ public class NetMarshalClient implements Closeable {
* Clears the fragment storage registries if fragmentation is enabled. * Clears the fragment storage registries if fragmentation is enabled.
* WARNING: Use of this method is not recommended. * WARNING: Use of this method is not recommended.
*/ */
public synchronized final void clearFragmentStorage() { public final void clearFragmentStorage() {
if (fragmentationOptions == null) return; if (fragmentationOptions == null) return;
fragmentReceiver.clearRegistry(); fragmentReceiver.clearRegistry();
fragmentSender.clearRegistry(); fragmentSender.clearRegistry();
@ -366,7 +366,7 @@ public class NetMarshalClient implements Closeable {
* *
* @return If the marshal is running. * @return If the marshal is running.
*/ */
public synchronized final boolean isRunning() { public final boolean isRunning() {
return running; return running;
} }
@ -384,7 +384,7 @@ public class NetMarshalClient implements Closeable {
* *
* @return Is the marshal ssl upgraded. * @return Is the marshal ssl upgraded.
*/ */
public synchronized final boolean isSSLUpgraded() { public final boolean isSSLUpgraded() {
if (!running) return false; if (!running) return false;
return socket instanceof SSLSocket; return socket instanceof SSLSocket;
} }
@ -398,7 +398,7 @@ public class NetMarshalClient implements Closeable {
* @throws PacketException An exception has occurred. * @throws PacketException An exception has occurred.
* @throws NullPointerException packetIn is null. * @throws NullPointerException packetIn is null.
*/ */
public synchronized final void sendPacket(IPacket packetIn, boolean directSend) throws IOException, PacketException { public final void sendPacket(IPacket packetIn, boolean directSend) throws IOException, PacketException {
if (packetIn == null) throw new NullPointerException("packetIn is null"); if (packetIn == null) throw new NullPointerException("packetIn is null");
synchronized (slocksock) { synchronized (slocksock) {
if (fragmentationOptions == null || directSend) { if (fragmentationOptions == null || directSend) {
@ -415,7 +415,7 @@ public class NetMarshalClient implements Closeable {
* *
* @throws IOException A stream exception has occurred. * @throws IOException A stream exception has occurred.
*/ */
public synchronized final void flush() throws IOException { public final void flush() throws IOException {
synchronized (slocksock) { synchronized (slocksock) {
outputStream.flush(); outputStream.flush();
rootOutputStream.flush(); rootOutputStream.flush();
@ -514,7 +514,7 @@ public class NetMarshalClient implements Closeable {
sslUpgrade(context, remoteHostName); sslUpgrade(context, remoteHostName);
} }
protected synchronized final void sslUpgrade(SSLContext context, String remoteHostName) throws SSLUtilityException, IOException { protected final void sslUpgrade(SSLContext context, String remoteHostName) throws SSLUtilityException, IOException {
if (!running || socket == null || socket instanceof SSLSocket) return; if (!running || socket == null || socket instanceof SSLSocket) return;
if (context == null) throw new NullPointerException("context is null"); if (context == null) throw new NullPointerException("context is null");
if (!disablePacketReading && Thread.currentThread() != receiveThread) throw new IllegalStateException("sslUpgrade methods should be called in a BiConsumer (for setReceiveBiConsumer) within the target NetMarshalClient" + if (!disablePacketReading && Thread.currentThread() != receiveThread) throw new IllegalStateException("sslUpgrade methods should be called in a BiConsumer (for setReceiveBiConsumer) within the target NetMarshalClient" +

View File

@ -162,7 +162,7 @@ public class NetMarshalServer implements Closeable {
* *
* @return If the marshal is running. * @return If the marshal is running.
*/ */
public synchronized final boolean isRunning() { public final boolean isRunning() {
return running; return running;
} }
@ -180,7 +180,7 @@ public class NetMarshalServer implements Closeable {
* *
* @return An array of connected clients. * @return An array of connected clients.
*/ */
public synchronized final NetMarshalClient[] getConnectedClients() { public final NetMarshalClient[] getConnectedClients() {
synchronized (slocksock) { synchronized (slocksock) {
return clients.toArray(new NetMarshalClient[0]); return clients.toArray(new NetMarshalClient[0]);
} }
@ -195,7 +195,7 @@ public class NetMarshalServer implements Closeable {
* @throws PacketException An exception has occurred. * @throws PacketException An exception has occurred.
* @throws NullPointerException packetIn is null. * @throws NullPointerException packetIn is null.
*/ */
public synchronized final void broadcastPacket(IPacket packetIn, boolean directSend) throws IOException, PacketException { public final void broadcastPacket(IPacket packetIn, boolean directSend) throws IOException, PacketException {
if (packetIn == null) throw new NullPointerException("packetIn is null"); if (packetIn == null) throw new NullPointerException("packetIn is null");
synchronized (slocksock) { synchronized (slocksock) {
for (NetMarshalClient c : clients) for (NetMarshalClient c : clients)
@ -208,7 +208,7 @@ public class NetMarshalServer implements Closeable {
* *
* @throws IOException A stream exception has occurred. * @throws IOException A stream exception has occurred.
*/ */
public synchronized final void flush() throws IOException { public final void flush() throws IOException {
synchronized (slocksock) { synchronized (slocksock) {
for (NetMarshalClient c : clients) for (NetMarshalClient c : clients)
if (c.isRunning()) c.flush(); if (c.isRunning()) c.flush();
@ -220,7 +220,7 @@ public class NetMarshalServer implements Closeable {
* *
* @throws IOException An I/O Exception has occurred. * @throws IOException An I/O Exception has occurred.
*/ */
public synchronized final void disconnectAll() throws IOException { public final void disconnectAll() throws IOException {
disconnectAllInternal(); disconnectAllInternal();
} }
@ -396,7 +396,7 @@ public class NetMarshalServer implements Closeable {
* @return A NetMarshalClient instance or null for non-accepted connection. * @return A NetMarshalClient instance or null for non-accepted connection.
* @throws IOException A connection error has occurred. * @throws IOException A connection error has occurred.
*/ */
public synchronized final NetMarshalClient connect(InetAddress remoteAddress, int remotePort, int timeout) throws IOException { public final NetMarshalClient connect(InetAddress remoteAddress, int remotePort, int timeout) throws IOException {
if (remoteAddress == null) throw new NullPointerException("remoteAddress is null"); if (remoteAddress == null) throw new NullPointerException("remoteAddress is null");
if (remotePort < 0) throw new IllegalArgumentException("remotePort is less than 0"); if (remotePort < 0) throw new IllegalArgumentException("remotePort is less than 0");
if (remotePort > 65535) throw new IllegalArgumentException("remotePort is greater than 65535"); if (remotePort > 65535) throw new IllegalArgumentException("remotePort is greater than 65535");