/**
   * Get the membership scheme applicable to this cluster
   *
   * @param clusterConfiguration the ClusterConfiguration instance
   * @return The membership scheme. Only wka and multicast are valid return values
   * @throws org.wso2.carbon.clustering.exception.ClusterConfigurationException If the
   *     membershipScheme specified in the cluster.xml file is invalid
   */
  public static String getMembershipScheme(ClusterConfiguration clusterConfiguration)
      throws ClusterConfigurationException {
    String mbrScheme = null;

    Object membershipScheme =
        clusterConfiguration.getMembershipSchemeConfiguration().getMembershipScheme();
    if (membershipScheme != null) {
      String membershipSchemeParam = membershipScheme.toString();
      mbrScheme = ClusteringConstants.MembershipScheme.MULTICAST_BASED;
      if (membershipSchemeParam != null) {
        mbrScheme = membershipSchemeParam.trim();
      }
      if (!mbrScheme.equals(ClusteringConstants.MembershipScheme.MULTICAST_BASED)
          && !mbrScheme.equals(ClusteringConstants.MembershipScheme.WKA_BASED)) {
        String msg =
            "Invalid membership scheme '"
                + mbrScheme
                + "'. Supported schemes are "
                + ClusteringConstants.MembershipScheme.MULTICAST_BASED
                + ", "
                + ClusteringConstants.MembershipScheme.WKA_BASED;
        logger.error(msg);
        throw new ClusterConfigurationException(msg);
      }
    }

    return mbrScheme;
  }
  /**
   * Returns the well known members defined in the cluster.xml
   *
   * @param clusterConfiguration the clusterConfiguration instance
   * @return List of well known members
   */
  public static List<ClusterMember> getWellKnownMembers(ClusterConfiguration clusterConfiguration) {
    List<ClusterMember> members = new ArrayList<>();

    List<WKAMember> wkaMembers =
        ((WKASchemeConfig)
                clusterConfiguration.getMembershipSchemeConfiguration().getMembershipScheme())
            .getWkaMembers();

    for (WKAMember wkaMember : wkaMembers) {
      String hostName = wkaMember.getHost();
      int port = wkaMember.getPort();

      if (hostName != null && port != 0) {
        members.add(new ClusterMember(replaceVariables(hostName), port));
      }
    }
    return members;
  }