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.node.protocol;
020
021import java.io.Serializable;
022
023import org.jppf.utils.TypedProperties;
024
025/**
026 * Instances of this class are set as job SLA attributes and describe the desired node configuration for a job.
027 * @author Laurent Cohen
028 */
029public class JPPFNodeConfigSpec implements Serializable {
030  /**
031   * The desired JPPF configuration of each node.
032   */
033  private final TypedProperties configuration;
034  /**
035   * Whether to force the restart of a node after reconfiguring it.
036   */
037  private final boolean forceRestart;
038
039  /**
040   * Initialize this node config spec with the specified desiredConfiguration and a restart flag set to {@code true}.
041   * @param desiredConfiguration the desired JPPF configuration of each node.
042   * @throws IllegalArgumentException if {@code desiredConfiguration} is {@code null}.
043   */
044  public JPPFNodeConfigSpec(final TypedProperties desiredConfiguration) {
045    this(desiredConfiguration, true);
046  }
047
048  /**
049   * Initialize this node config spec with the specified desiredConfiguration and restart flag.
050   * @param desiredConfiguration the desired JPPF configuration of each node.
051   * @param forceRestart whether to force the restart of a node after reconfiguring it.
052   * @throws IllegalArgumentException if {@code desiredConfiguration} is {@code null}.
053   */
054  public JPPFNodeConfigSpec(final TypedProperties desiredConfiguration, final boolean forceRestart) throws IllegalArgumentException {
055    if (desiredConfiguration == null)
056      throw new IllegalArgumentException("the desired configuration of a " + getClass().getSimpleName() + " cannot be null");
057    this.configuration = desiredConfiguration;
058    this.forceRestart = forceRestart;
059  }
060
061  /**
062   * Get the desired JPPF configuration of each node.
063   * @return a TypedProperties object containing the desired configuration properties.
064   */
065  public TypedProperties getConfiguration() {
066    return configuration;
067  }
068
069  /**
070   * Determine whether to force the restart of a node after reconfiguring it.
071   * @return {@code true} if each node is to be restarted after reconfiguration, {@code false} otherwise.
072   */
073  public boolean isForceRestart() {
074    return forceRestart;
075  }
076}