001/*
002 * JPPF.
003 * Copyright (C) 2005-2019 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.load.balancer;
020
021import java.io.Serializable;
022import java.util.List;
023
024import org.jppf.utils.TypedProperties;
025
026/**
027 * Information on the load-balancing algorithm currently setup in the driver.
028 * @author Laurent Cohen
029 */
030public class LoadBalancingInformation implements Serializable {
031  /**
032   * Explicit serialVersionUID.
033   */
034  private static final long serialVersionUID = 1L;
035  /**
036   * The name of the algorithm.
037   */
038  private final String algorithm;
039  /**
040   * The algorithm's parameters.
041   */
042  private final TypedProperties parameters;
043  /**
044   * The names of all available algorithms.
045   */
046  private final List<String> algorithmNames;
047
048  /**
049   * Initialize this load balancing information with the specified algorithm and parameters.
050   * @param algorithm the name of the algorithm.
051   * @param parameters the algorithm's parameters.
052   */
053  public LoadBalancingInformation(final String algorithm, final TypedProperties parameters) {
054    this(algorithm, parameters, null);
055  }
056
057  /**
058   * Initialize this load balancing information with the specified algorithm and parameters.
059   * @param algorithm the name of the algorithm.
060   * @param parameters the algorithm's parameters.
061   * @param algorithmNames the names of all available algorithms.
062   */
063  public LoadBalancingInformation(final String algorithm, final TypedProperties parameters, final List<String> algorithmNames) {
064    this.algorithm = algorithm;
065    this.parameters = parameters;
066    this.algorithmNames = algorithmNames;
067  }
068
069  /**
070   * Get the name of the algorithm.
071   * @return the algorithm name as a string.
072   */
073  public String getAlgorithm() {
074    return algorithm;
075  }
076
077  /**
078   * Get the algorithm's parameters.
079   * @return the parameters as a set of (name, value) pairs.
080   */
081  public TypedProperties getParameters() {
082    return parameters;
083  }
084
085  /**
086   * The names of all available algorithms.
087   * @return a list of all available algorithm names.
088   */
089  public List<String> getAlgorithmNames() {
090    return algorithmNames;
091  }
092
093  @Override
094  public String toString() {
095    final StringBuilder sb = new StringBuilder();
096    sb.append(getClass().getSimpleName());
097    sb.append("[algorithm=").append(algorithm);
098    sb.append(", algorithmNames=").append(algorithmNames);
099    sb.append(", parameters=").append(parameters);
100    sb.append(']');
101    return sb.toString();
102  }
103}