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.protocol;
020
021/**
022 * This interface represents the Service Level Agreement between a JPPF job and a JPPF client.
023 * It determines the state, conditions and order in which a job will be executed.
024 * @author Laurent Cohen
025 */
026public class JobClientSLA extends JobCommonSLA<JobClientSLA> {
027  /**
028   * Explicit serialVersionUID.
029   */
030  private static final long serialVersionUID = 1L;
031  /**
032   * The maximum number of nodes this job can run on.
033   * The default value is set to <code>1</code> to preserve backward compatibility, by emulating the behavior of previous versions.
034   */
035  private int maxChannels = 1;
036
037  /**
038   * Default constructor.
039   * @exclude
040   */
041  public JobClientSLA() {
042  }
043
044  /**
045   * Get the maximum number of channels, including the local execution channel if it is enabled, this job can be sent on.
046   * @return the number of channels as an int value.
047   */
048  public int getMaxChannels() {
049    return maxChannels;
050  }
051
052  /**
053   * Set the maximum number of channels, including the local execution channel if it is enabled, this job can be sent on.
054   * @param maxChannels the number of channels as an int value. A value <= 0 means no limit on the number of channels.
055   * @return this SLA, for method chaining.
056   */
057  public JobClientSLA setMaxChannels(final int maxChannels) {
058    this.maxChannels = maxChannels > 0 ? maxChannels : Integer.MAX_VALUE;
059    return this;
060  }
061
062  /**
063   * Create a copy of this job SLA.
064   * @return a {@link JobClientSLA} instance.
065   */
066  public JobClientSLA copy() {
067    final JobClientSLA sla = new JobClientSLA();
068    copyTo(sla);
069    sla.setMaxChannels(maxChannels);
070    return sla;
071  }
072}