Download JPPF Manual

Transcript
7.5.3 Implementing the bundler provider interface
Custom load-balancers are defined and deployed using the Service Provider Interface (SPI) mechanism. For a new loadbalancer to be recognized by JPPF, it has to provide an implementation of the JPPFBundlerProvider interface, which
is defined as:
public interface JPPFBundlerProvider {
// Get the name of the algorithm defined by this provider
// Each algorithm must have a name distinct from that of all other algorithms
public String getAlgorithmName();
// Create a bundler instance using the specified parameters profile
public Bundler createBundler(LoadBalancingProfile profile);
}
// Create a bundler profile containing the parameters of the algorithm
public LoadBalancingProfile createProfile(TypedProperties configuration);
In the case of our fixed size algorithm, the FixedSizeBundlerProvider implementation is quite straightforward:
public class FixedSizeBundlerProvider implements JPPFBundlerProvider {
// Get the name of the algorithm defined by this provider
public String getAlgorithmName() {
return "manual";
}
// Create a bundler instance using the specified parameters profile
public Bundler createBundler(LoadBalancingProfile profile) {
return new FixedSizeBundler(profile);
}
}
// Create a bundler profile containing the parameters of the algorithm
public LoadBalancingProfile createProfile(TypedProperties configuration) {
return new FixedSizeProfile(configuration);
}
7.5.4 Deploying the custom load-balancer
For our custom load-balancer to be recognized and loaded, we need to create the corresponding service definition file. If
it doesn't already exist, we create, in the source folder, a subfolder named META-INF/services. In this folder, we will
create a file named org.jppf.server.scheduler.bundle.providers.FixedSizeBundlerProvider, and open
it in a text editor. In the editor, we add a single line containing the fully qualified name of our provider implementation:
org.jppf.server.scheduler.bundle.providers.FixedSizeBundlerProvider
Now, to actually deploy our implementation, we will create a jar file that contains all the artifacts we have created: the
Bundler, LoadBalancingProfile and JPPFBundlerProvider implementation classes, along with the METAINF/services folder, and add this jar to the class path of the server.
7.5.5 Node-aware load balancers
Load balancers can be made aware of a node's environment and configuration, and make dynamic decisions based on
this information.
To this effect, the Bundler implementation will need to also implement the interface NodeAwareness, defined as follows:
// Bundler implementations should implement this interface
// if they wish to have access to a node's configuration
public interface NodeAwareness {
// Get the corresponding node's system information
JPPFSystemInformation getNodeConfiguration();
}
// Set the corresponding node's system information
void setNodeConfiguration(JPPFSystemInformation nodeConfiguration);