@Test public void connect() { assertThat(doConnectCalled.get()).isEqualTo(false); assertThat(link.isConnected()).isEqualTo(false); link.connect(); assertThat(doConnectCalled.get()).isEqualTo(true); assertThat(link.isConnected()).isEqualTo(true); verify(linkConnectionEventEmitterMock).emitEvent(Mockito.<LinkConnectedEvent>any()); verifyNoMoreInteractions(linkConnectionEventEmitterMock); }
@Override public final CompletableFuture<Void> connect() { try { if (this.connected.compareAndSet(NOT_CONNECTED, CONNECTED)) { logger.debug("[linktype={}] (operatorIlpAddress={}) connecting to linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doConnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkConnectedEvent.of(this)); logger.debug("[linktype={}] (Operator operatorIlpAddress={}) connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { this.connected.set(NOT_CONNECTED); final String errorMessage = String.format( "[linktype=%s] (Operator operatorIlpAddress=%s) was unable to connect to linkId=%s", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId().value() ); logger.error(errorMessage, error); } }); } else { logger.debug("[linktype={}] (Operator operatorIlpAddress={}) already connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return CompletableFuture.completedFuture(null); } } catch (RuntimeException e) { this.disconnect().join(); throw e; } catch (Exception e) { this.disconnect().join(); throw new RuntimeException(e.getMessage(), e); } }
AbstractStatefulLink extends AbstractLink<L> implements StatefulLink<L> { @Override public final CompletableFuture<Void> connect() { try { if (this.connected.compareAndSet(NOT_CONNECTED, CONNECTED)) { logger.debug("[linktype={}] (operatorIlpAddress={}) connecting to linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doConnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkConnectedEvent.of(this)); logger.debug("[linktype={}] (Operator operatorIlpAddress={}) connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { this.connected.set(NOT_CONNECTED); final String errorMessage = String.format( "[linktype=%s] (Operator operatorIlpAddress=%s) was unable to connect to linkId=%s", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId().value() ); logger.error(errorMessage, error); } }); } else { logger.debug("[linktype={}] (Operator operatorIlpAddress={}) already connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return CompletableFuture.completedFuture(null); } } catch (RuntimeException e) { this.disconnect().join(); throw e; } catch (Exception e) { this.disconnect().join(); throw new RuntimeException(e.getMessage(), e); } } }
AbstractStatefulLink extends AbstractLink<L> implements StatefulLink<L> { @Override public final CompletableFuture<Void> connect() { try { if (this.connected.compareAndSet(NOT_CONNECTED, CONNECTED)) { logger.debug("[linktype={}] (operatorIlpAddress={}) connecting to linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doConnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkConnectedEvent.of(this)); logger.debug("[linktype={}] (Operator operatorIlpAddress={}) connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { this.connected.set(NOT_CONNECTED); final String errorMessage = String.format( "[linktype=%s] (Operator operatorIlpAddress=%s) was unable to connect to linkId=%s", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId().value() ); logger.error(errorMessage, error); } }); } else { logger.debug("[linktype={}] (Operator operatorIlpAddress={}) already connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return CompletableFuture.completedFuture(null); } } catch (RuntimeException e) { this.disconnect().join(); throw e; } catch (Exception e) { this.disconnect().join(); throw new RuntimeException(e.getMessage(), e); } } protected  AbstractStatefulLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final L linkSettings,
      final LinkConnectionEventEmitter linkConnectionEventEmitter
  ); }
AbstractStatefulLink extends AbstractLink<L> implements StatefulLink<L> { @Override public final CompletableFuture<Void> connect() { try { if (this.connected.compareAndSet(NOT_CONNECTED, CONNECTED)) { logger.debug("[linktype={}] (operatorIlpAddress={}) connecting to linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doConnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkConnectedEvent.of(this)); logger.debug("[linktype={}] (Operator operatorIlpAddress={}) connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { this.connected.set(NOT_CONNECTED); final String errorMessage = String.format( "[linktype=%s] (Operator operatorIlpAddress=%s) was unable to connect to linkId=%s", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId().value() ); logger.error(errorMessage, error); } }); } else { logger.debug("[linktype={}] (Operator operatorIlpAddress={}) already connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return CompletableFuture.completedFuture(null); } } catch (RuntimeException e) { this.disconnect().join(); throw e; } catch (Exception e) { this.disconnect().join(); throw new RuntimeException(e.getMessage(), e); } } protected  AbstractStatefulLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final L linkSettings,
      final LinkConnectionEventEmitter linkConnectionEventEmitter
  ); @Override final CompletableFuture<Void> connect(); abstract CompletableFuture<Void> doConnect(); @Override void close(); @Override final CompletableFuture<Void> disconnect(); abstract CompletableFuture<Void> doDisconnect(); @Override boolean isConnected(); @Override void addLinkEventListener(final LinkConnectionEventListener linkConnectionEventListener); @Override void removeLinkEventListener(final LinkConnectionEventListener linkConnectionEventListener); }
AbstractStatefulLink extends AbstractLink<L> implements StatefulLink<L> { @Override public final CompletableFuture<Void> connect() { try { if (this.connected.compareAndSet(NOT_CONNECTED, CONNECTED)) { logger.debug("[linktype={}] (operatorIlpAddress={}) connecting to linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doConnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkConnectedEvent.of(this)); logger.debug("[linktype={}] (Operator operatorIlpAddress={}) connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { this.connected.set(NOT_CONNECTED); final String errorMessage = String.format( "[linktype=%s] (Operator operatorIlpAddress=%s) was unable to connect to linkId=%s", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId().value() ); logger.error(errorMessage, error); } }); } else { logger.debug("[linktype={}] (Operator operatorIlpAddress={}) already connected to linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return CompletableFuture.completedFuture(null); } } catch (RuntimeException e) { this.disconnect().join(); throw e; } catch (Exception e) { this.disconnect().join(); throw new RuntimeException(e.getMessage(), e); } } protected  AbstractStatefulLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final L linkSettings,
      final LinkConnectionEventEmitter linkConnectionEventEmitter
  ); @Override final CompletableFuture<Void> connect(); abstract CompletableFuture<Void> doConnect(); @Override void close(); @Override final CompletableFuture<Void> disconnect(); abstract CompletableFuture<Void> doDisconnect(); @Override boolean isConnected(); @Override void addLinkEventListener(final LinkConnectionEventListener linkConnectionEventListener); @Override void removeLinkEventListener(final LinkConnectionEventListener linkConnectionEventListener);  }