001/*
002 * JPPF.
003 * Copyright (C) 2005-2018 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.node.policy;
020
021import org.jppf.node.protocol.*;
022import org.jppf.utils.stats.JPPFStatistics;
023
024/**
025 * Instances of this class provide contextual information to execution policies.
026 * It contains information on the job, if any, against which the policy is evaluated, and on the server for server-side policies.
027 * @since 5.0
028 * @author Laurent Cohen
029 */
030public class PolicyContext {
031  /**
032   * The job server side SLA, set at runtime by the server.
033   */
034  private final JobSLA sla;
035  /**
036   * The job client side SLA, set at runtime by the server.
037   */
038  private final JobClientSLA clientSLA;
039  /**
040   * The job metadata, set at runtime by the server.
041   */
042  private final JobMetadata metadata;
043  /**
044   * Number of nodes the job is already dispatched to.
045   */
046  private final int jobDispatches;
047  /**
048   * The server statistics.
049   */
050  private final JPPFStatistics stats;
051
052  /**
053   * Initialize this policy context.
054   * @param sla the job server side SLA, set at runtime by the server.
055   * @param clientSLA the job client side SLA, set at runtime by the server.
056   * @param metadata the job metadata, set at runtime by the server.
057   * @param jobDispatches the number of nodes the job is already dispatched to.
058   * @param stats the server statistics.
059   * @exclude
060   */
061  public PolicyContext(final JobSLA sla, final JobClientSLA clientSLA, final JobMetadata metadata, final int jobDispatches, final JPPFStatistics stats) {
062    this.sla = sla;
063    this.clientSLA = clientSLA;
064    this.metadata = metadata;
065    this.jobDispatches = jobDispatches;
066    this.stats = stats;
067  }
068
069  /**
070   * Get the job server side SLA, set at runtime by the server.
071   * @return a {@link JobSLA} object.
072   */
073  public JobSLA getSLA() {
074    return sla;
075  }
076
077  /**
078   * Get the job client side SLA, set at runtime by the server.
079   * @return a {@link JobClientSLA} object.
080   */
081  public JobClientSLA getClientSLA() {
082    return clientSLA;
083  }
084
085  /**
086   * Get the job metadata, set at runtime by the server.
087   * @return a {@link JobMetadata} object.
088   */
089  public JobMetadata getMetadata() {
090    return metadata;
091  }
092
093  /**
094   * Get the number of nodes the job is already dispatched to.
095   * @return the number of nodes as an int.
096   */
097  public int getJobDispatches() {
098    return jobDispatches;
099  }
100
101  /**
102   * Get the server statistics.
103   * @return a {@link JPPFStatistics} object.
104   */
105  public JPPFStatistics getStats() {
106    return stats;
107  }
108}