@Override
  public void removedDistributedSystem(int remoteDsId) {
    cache = CacheFactory.getAnyInstance();
    if (remoteDsId == 2) { // When a site with distributed-system-id = -2 joins, stop gatewaysender
                           // with remoteDsId = 2
      if (cache != null) {
        GatewaySender sender = cache.getGatewaySender("LN_" + 2);
        sender.stop();
      }
    } else { // When a site with distributed-system-id = -1 joins, stop gatewayReceiver
      GatewayReceiver receiver = cache.getGatewayReceivers().iterator().next();
      receiver.stop();
    }
  }
Please note that dynamic addition of the sender id to region is not yet available.
geode-core/src/test/java/com/main/MyDistributedSystemListener.java