42
42
import java .net .SocketTimeoutException ;
43
43
import java .net .UnknownHostException ;
44
44
import java .nio .ByteBuffer ;
45
+ import java .util .ConcurrentModificationException ;
45
46
46
47
import org .slf4j .Logger ;
47
48
48
49
import com .google .errorprone .annotations .ForOverride ;
49
50
import com .google .errorprone .annotations .OverridingMethodsMustInvokeSuper ;
51
+ import com .google .errorprone .annotations .concurrent .GuardedBy ;
50
52
51
53
import uk .ac .manchester .spinnaker .connections .model .Connection ;
52
54
import uk .ac .manchester .spinnaker .messages .sdp .SDPHeader ;
@@ -102,6 +104,9 @@ public enum TrafficClass {
102
104
103
105
private int receivePacketSize = PACKET_MAX_SIZE ;
104
106
107
+ @ GuardedBy ("this" )
108
+ private boolean inUse = false ;
109
+
105
110
/**
106
111
* Main constructor, any argument of which could {@code null}.
107
112
* <p>
@@ -683,7 +688,8 @@ public boolean isClosed() {
683
688
* port in a NAT and/or firewall to allow incoming packets to be received.
684
689
*
685
690
* @param host
686
- * The address of the SpiNNaker board to which the message should
691
+ * The address of the SpiNNaker board to which the
692
+ * message should
687
693
* be sent
688
694
* @throws IOException
689
695
* If anything goes wrong
@@ -707,4 +713,16 @@ public String toString() {
707
713
getClass ().getSimpleName ().replaceAll ("^.*\\ ." , "" ),
708
714
localAddr (), isClosed () ? "|" : "" , remoteAddr ());
709
715
}
716
+
717
+ public synchronized void setInUse () {
718
+ if (inUse ) {
719
+ throw new ConcurrentModificationException (
720
+ "Connection " + this + " is already in use!" );
721
+ }
722
+ this .inUse = true ;
723
+ }
724
+
725
+ public synchronized void setNotInUse () {
726
+ this .inUse = false ;
727
+ }
710
728
}
0 commit comments