001/*
002 * JPPF.
003 * Copyright (C) 2005-2016 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.spi;
020
021import org.jppf.load.balancer.*;
022import org.jppf.utils.TypedProperties;
023
024/**
025 * <p>Interface for all load-balancing algorithm providers.
026 * An implementation of this interface shall be provided for each load-balancing algorithm, to enable its dynamic discovery by JPPF components.
027 * <p>To integrate a load-balancing algorithm provider, the following steps should be performed:
028 * <ul>
029 * <li>At one of the classpath roots, ensure that there is a folder named META-INF/services</li>
030 * <li>In this folder, create or edit a file named {@code org.jppf.load.balancer.spi.JPPFBundlerProvider}</li>
031 * <li>In this file, add a line containing the fully qualified name of the class implementing the {@link JPPFBundlerProvider} interface</li>
032 * </ul>
033 * @param <T> the type of parameters profile used by the bundler.
034 * @author Laurent Cohen
035 */
036public interface JPPFBundlerProvider<T extends LoadBalancingProfile> {
037  /**
038   * Get the name of the algorithm defined by this provider. Each algorithm must have a name distinct from that of all other algorithms.
039   * @return the algorithm's name as a string.
040   */
041  String getAlgorithmName();
042
043  /**
044   * Create a bundler instance using the specified parameters profile.
045   * The parameters profile is created by JPPF internally via a call to {@link #createProfile(TypedProperties)}.
046   * @param profile an {@link Bundler} instance.
047   * @return an instance of the bundler implementation defined by this provider.
048   */
049  Bundler<T> createBundler(T profile);
050
051  /**
052   * <p>Create a bundler profile containing the parameters of the algorithm.
053   * <p>The configuration parameter contains a set of properties that define the parameters names and values.<br>
054   * The parameter names are provided <i>without any JPPF configuration-specific prefix</i>.
055   * <p>For example: if the JPPF configuration file specifies a profile named "myProfile" (through the property "jppf.load.balancing.profile = myProfile"),
056   * and the algorithm has a parameter named "{@code myParameter}", then in the configuration file it will be specified as "{@code jppf.load.balancing.profile.myProfile.myParameter = some_value}".<br>
057   * When this method is called, only the parameter name is kept, and its definition becomes "{@code myParameter = some_value}".
058   * @param configuration a set of properties defining the algorithm's parameters.
059   * @return an {@link LoadBalancingProfile} instance.
060   */
061  T createProfile(TypedProperties configuration);
062}