@Test public void nextSequenceMultiThreaded() throws StreamConnectionClosedException { final List<CompletableFuture<UnsignedLong>> allFutures = Lists.newArrayList(); final int numRepetitions = 50000; final ExecutorService executorService = Executors.newFixedThreadPool(10); for (int i = 0; i < numRepetitions; i++) { allFutures.add( CompletableFuture.supplyAsync(() -> { try { UnsignedLong sequence = streamConnection.nextSequence(); return sequence; } catch (StreamConnectionClosedException e) { throw new RuntimeException(e); } }, executorService) ); } CompletableFuture.allOf(allFutures.toArray(new CompletableFuture[0])).join(); assertThat(streamConnection.nextSequence().longValue()).isEqualTo(numRepetitions + 1); }
public UnsignedLong nextSequence() throws StreamConnectionClosedException { final UnsignedLong nextSequence = sequence.getAndUpdate(currentSequence -> currentSequence.plus(UnsignedLong.ONE)); if (sequenceIsSafeForSingleSharedSecret(nextSequence)) { return nextSequence; } else { this.closeConnection(); throw new StreamConnectionClosedException(streamConnectionId); } }
StreamConnection implements Closeable { public UnsignedLong nextSequence() throws StreamConnectionClosedException { final UnsignedLong nextSequence = sequence.getAndUpdate(currentSequence -> currentSequence.plus(UnsignedLong.ONE)); if (sequenceIsSafeForSingleSharedSecret(nextSequence)) { return nextSequence; } else { this.closeConnection(); throw new StreamConnectionClosedException(streamConnectionId); } } }
StreamConnection implements Closeable { public UnsignedLong nextSequence() throws StreamConnectionClosedException { final UnsignedLong nextSequence = sequence.getAndUpdate(currentSequence -> currentSequence.plus(UnsignedLong.ONE)); if (sequenceIsSafeForSingleSharedSecret(nextSequence)) { return nextSequence; } else { this.closeConnection(); throw new StreamConnectionClosedException(streamConnectionId); } } StreamConnection(final InterledgerAddress receiverAddress, final SharedSecret sharedSecret);  StreamConnection(final StreamConnectionId streamConnectionId); }
StreamConnection implements Closeable { public UnsignedLong nextSequence() throws StreamConnectionClosedException { final UnsignedLong nextSequence = sequence.getAndUpdate(currentSequence -> currentSequence.plus(UnsignedLong.ONE)); if (sequenceIsSafeForSingleSharedSecret(nextSequence)) { return nextSequence; } else { this.closeConnection(); throw new StreamConnectionClosedException(streamConnectionId); } } StreamConnection(final InterledgerAddress receiverAddress, final SharedSecret sharedSecret);  StreamConnection(final StreamConnectionId streamConnectionId); UnsignedLong nextSequence(); Instant getCreationDateTime(); void transitionConnectionState(); StreamConnectionState getConnectionState(); StreamConnectionId getStreamConnectionId(); void closeConnection(); boolean isClosed(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); @Override void close(); }
StreamConnection implements Closeable { public UnsignedLong nextSequence() throws StreamConnectionClosedException { final UnsignedLong nextSequence = sequence.getAndUpdate(currentSequence -> currentSequence.plus(UnsignedLong.ONE)); if (sequenceIsSafeForSingleSharedSecret(nextSequence)) { return nextSequence; } else { this.closeConnection(); throw new StreamConnectionClosedException(streamConnectionId); } } StreamConnection(final InterledgerAddress receiverAddress, final SharedSecret sharedSecret);  StreamConnection(final StreamConnectionId streamConnectionId); UnsignedLong nextSequence(); Instant getCreationDateTime(); void transitionConnectionState(); StreamConnectionState getConnectionState(); StreamConnectionId getStreamConnectionId(); void closeConnection(); boolean isClosed(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); @Override void close(); static final UnsignedLong MAX_FRAMES_PER_CONNECTION; }