@Test public void disconnect() { assertThat(doDisconnectCalled.get()).isEqualTo(false); assertThat(link.isConnected()).isEqualTo(false); link.connect(); assertThat(doConnectCalled.get()).isEqualTo(true); assertThat(link.isConnected()).isEqualTo(true); }
@Override public final CompletableFuture<Void> disconnect() { try { if (this.connected.compareAndSet(CONNECTED, NOT_CONNECTED)) { logger.debug("[linktype={}] (ILPAddress={}) disconnecting from linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doDisconnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkDisconnectedEvent.of(this)); logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { final String errorMessage = String.format( "[linktype=%s] While trying to disconnect linkId=%s from operatorIlpAddress=%s error=%s", this.getLinkSettings().getLinkType(), this.getLinkId(), this.operatorAddressAsString(), error.getMessage() ); logger.error(errorMessage, error); } }) .thenAccept(($) -> logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() )); } else { logger.debug("[linktype={}] (ILPAddress={}) already disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId()); return CompletableFuture.completedFuture(null); } } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
AbstractStatefulLink extends AbstractLink<L> implements StatefulLink<L> { @Override public final CompletableFuture<Void> disconnect() { try { if (this.connected.compareAndSet(CONNECTED, NOT_CONNECTED)) { logger.debug("[linktype={}] (ILPAddress={}) disconnecting from linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doDisconnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkDisconnectedEvent.of(this)); logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { final String errorMessage = String.format( "[linktype=%s] While trying to disconnect linkId=%s from operatorIlpAddress=%s error=%s", this.getLinkSettings().getLinkType(), this.getLinkId(), this.operatorAddressAsString(), error.getMessage() ); logger.error(errorMessage, error); } }) .thenAccept(($) -> logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() )); } else { logger.debug("[linktype={}] (ILPAddress={}) already disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId()); return CompletableFuture.completedFuture(null); } } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } }
AbstractStatefulLink extends AbstractLink<L> implements StatefulLink<L> { @Override public final CompletableFuture<Void> disconnect() { try { if (this.connected.compareAndSet(CONNECTED, NOT_CONNECTED)) { logger.debug("[linktype={}] (ILPAddress={}) disconnecting from linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doDisconnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkDisconnectedEvent.of(this)); logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { final String errorMessage = String.format( "[linktype=%s] While trying to disconnect linkId=%s from operatorIlpAddress=%s error=%s", this.getLinkSettings().getLinkType(), this.getLinkId(), this.operatorAddressAsString(), error.getMessage() ); logger.error(errorMessage, error); } }) .thenAccept(($) -> logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() )); } else { logger.debug("[linktype={}] (ILPAddress={}) already disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId()); return CompletableFuture.completedFuture(null); } } catch (Exception e) { 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> disconnect() { try { if (this.connected.compareAndSet(CONNECTED, NOT_CONNECTED)) { logger.debug("[linktype={}] (ILPAddress={}) disconnecting from linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doDisconnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkDisconnectedEvent.of(this)); logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { final String errorMessage = String.format( "[linktype=%s] While trying to disconnect linkId=%s from operatorIlpAddress=%s error=%s", this.getLinkSettings().getLinkType(), this.getLinkId(), this.operatorAddressAsString(), error.getMessage() ); logger.error(errorMessage, error); } }) .thenAccept(($) -> logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() )); } else { logger.debug("[linktype={}] (ILPAddress={}) already disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId()); return CompletableFuture.completedFuture(null); } } catch (Exception e) { 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> disconnect() { try { if (this.connected.compareAndSet(CONNECTED, NOT_CONNECTED)) { logger.debug("[linktype={}] (ILPAddress={}) disconnecting from linkId={}...", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); return this.doDisconnect() .whenComplete(($, error) -> { if (error == null) { this.linkConnectionEventEmitter.emitEvent(LinkDisconnectedEvent.of(this)); logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() ); } else { final String errorMessage = String.format( "[linktype=%s] While trying to disconnect linkId=%s from operatorIlpAddress=%s error=%s", this.getLinkSettings().getLinkType(), this.getLinkId(), this.operatorAddressAsString(), error.getMessage() ); logger.error(errorMessage, error); } }) .thenAccept(($) -> logger.debug("[linktype={}] (ILPAddress={}) disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId() )); } else { logger.debug("[linktype={}] (ILPAddress={}) already disconnected from linkId={}", this.getLinkSettings().getLinkType(), this.operatorAddressAsString(), this.getLinkId()); return CompletableFuture.completedFuture(null); } } catch (Exception e) { 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);  }