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
021import java.io.Serializable;
022
023/**
024 * This class defines whether a job should be persisted and the behavior of the persistence facility upon recovery.
025 * @author Laurent Cohen
026 * @since 6.0
027 */
028public class PersistenceSpec implements Serializable {
029  /**
030   * Explicit serialVersionUID.
031   */
032  private static final long serialVersionUID = 1L;
033  /**
034   * Whether the job is persisted in the driver.
035   */
036  private boolean persistent = false;
037  /**
038   * Whether the driver should automatically execute the job after a restart.
039   */
040  private boolean autoExecuteOnRestart = false;
041  /**
042   * Whether the persisteed job should be deleted from the persistence store when it terminates.
043   */
044  private boolean deleteOnCompletion = true;
045
046  /**
047   * Determine whether the job is persisted in the driver.
048   * The default value of this attribute is {@code false}.
049   * @return {@code true} if the job is persisted, {@code false} otherwise.
050   */
051  public boolean isPersistent() {
052    return persistent;
053  }
054
055  /**
056   * Specify whether the job is persisted in the driver.
057   * @param persistent {@code true} if the job is to be persisted, {@code false} otherwise.
058   * @return this {@code PersistenceSpec} instance, for method call chaining.
059   */
060  public PersistenceSpec setPersistent(final boolean persistent) {
061    this.persistent = persistent;
062    return this;
063  }
064
065  /**
066   * Determine whether the driver should automatically execute the persisted job after a restart.
067   * The default value of this attribute is {@code false}.
068   * @return {@code true} if the job is automatically executed upon recovery, {@code false} otherwise.
069   */
070  public boolean isAutoExecuteOnRestart() {
071    return autoExecuteOnRestart;
072  }
073
074  /**
075   * Specify whether the driver should automatically execute the persisted job after a restart.
076   * @param autoExecuteOnRestart {@code true} if the job is to be automatically executed upon recovery, {@code false} otherwise.
077   * @return this {@code PersistenceSpec} instance, for method call chaining.
078   */
079  public PersistenceSpec setAutoExecuteOnRestart(final boolean autoExecuteOnRestart) {
080    this.autoExecuteOnRestart = autoExecuteOnRestart;
081    return this;
082  }
083
084  /**
085   * Determine whether the persisted job should be deleted from the persistence store when it terminates.
086   * The default value of this attribute is {@code true}.
087   * @return {@code true} if the job should be deleted from persistence, {@code false} otherwise.
088   */
089  public boolean isDeleteOnCompletion() {
090    return deleteOnCompletion;
091  }
092
093  /**
094   * Determine whether the persisted job should be deleted from the persistence store when it terminates.
095   * @param deleteOnCompletion {@code true} if the job should be deleted from persistence, {@code false} otherwise.
096   * @return this {@code PersistenceSpec} instance, for method call chaining.
097   */
098  public PersistenceSpec setDeleteOnCompletion(final boolean deleteOnCompletion) {
099    this.deleteOnCompletion = deleteOnCompletion;
100    return this;
101  }
102}