Job Metadata
From JPPF 6.2 Documentation
Main Page > Development guide > Job Metadata |
It is possible to attach user-defined metadata to a job, to describe the characteristics of the job and its tasks. This additional data can then be reused by customized load-balancing algorithms, to perform load balancing based on knowledge about the jobs. For instance, the metadata could provide information about the memory footprint of the tasks and about their duration, which can be critical data for the server, in order to determine on which nodes the job or tasks should be executed.
The job metadata is encapsulated in a specific class: JobMetadata, and can be accessed from the job as follows:
JPPFJob job = ...; JobMetadata metaData = job.getMetadata();
JobMetadata is defined as follows:
public interface JobMetadata extends Metadata { }
As for the data provider, the API is actually defined by the Metadata interface:
public interface Metadata extends Serializable { // Set a parameter in the metadata Metadata setParameter(Object key, T value) // Retrieve a parameter in the metadata <T> T getParameter(Object key) // Retrieve a parameter in the metadata <T> T getParameter(Object key, T defaultValue) // Remove a parameter from the metadata <T> T removeParameter(Object key) // Get a the metadata map public Map<Object, Object> getAll() // Clear all the the metadata void clear(); }
Here is an example use:
JPPFJob job = ...; JobMetadata metaData = job.getMetadata(); metaData // set the memory footprint of each task to 10 KB .setParameter(“task.footprint”, “” + (10 * 1024)) // set the duration of each task to 80 milliseconds .setParameter(“task.duration”, “80”);
Related sample: Custom Load Balancer.
Main Page > Development guide > Job Metadata |