this.expectedVersion = expectedVersion;
}
- private void connect() throws IOException {
- if (fcpConnection.get() != null) {
- return;
+ private FcpConnection connect() throws IOException {
+ FcpConnection fcpConnection = this.fcpConnection.get();
+ if (fcpConnection != null) {
+ return fcpConnection;
}
- fcpConnection.compareAndSet(null, createConnection());
+ fcpConnection = createConnection();
+ this.fcpConnection.compareAndSet(null, fcpConnection);
+ return fcpConnection;
}
private FcpConnection createConnection() throws IOException {
public Future<FcpKeyPair> execute() {
return threadPool.submit(() -> {
connect();
- return new FcpReplySequence<FcpKeyPair>(threadPool, fcpConnection.get()) {
+ return new FcpReplySequence<FcpKeyPair>(threadPool, connect()) {
private AtomicReference<FcpKeyPair> keyPair = new AtomicReference<>();
@Override
clientGet.setGlobal(true);
}
return threadPool.submit(() -> {
- connect();
- FcpReplySequence<Optional<Data>> replySequence = new FcpReplySequence<Optional<Data>>(threadPool, fcpConnection.get()) {
+ FcpReplySequence<Optional<Data>> replySequence = new FcpReplySequence<Optional<Data>>(threadPool, connect()) {
private final AtomicBoolean finished = new AtomicBoolean();
private final AtomicBoolean failed = new AtomicBoolean();