001/*
002 * Copyright 2008-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2015-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.tasks;
037
038
039
040import com.unboundid.util.StaticUtils;
041import com.unboundid.util.ThreadSafety;
042import com.unboundid.util.ThreadSafetyLevel;
043
044
045
046/**
047 * This class defines a task state, which provides information about the current
048 * state of processing for a scheduled task.
049 * <BR>
050 * <BLOCKQUOTE>
051 *   <B>NOTE:</B>  This class, and other classes within the
052 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
053 *   supported for use against Ping Identity, UnboundID, and
054 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
055 *   for proprietary functionality or for external specifications that are not
056 *   considered stable or mature enough to be guaranteed to work in an
057 *   interoperable way with other types of LDAP servers.
058 * </BLOCKQUOTE>
059 */
060@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
061public enum TaskState
062{
063  /**
064   * The task state that indicates that the task was canceled before it started
065   * running.
066   */
067  CANCELED_BEFORE_STARTING("canceled_before_starting"),
068
069
070
071  /**
072   * The task state that indicates that the task has completed successfully.
073   */
074  COMPLETED_SUCCESSFULLY("completed_successfully"),
075
076
077
078  /**
079   * The task state that indicates that the task has completed but with one or
080   * more errors.
081   */
082  COMPLETED_WITH_ERRORS("completed_with_errors"),
083
084
085
086  /**
087   * The task state that indicates that the task has been disabled.
088   */
089  DISABLED("disabled"),
090
091
092
093  /**
094   * The task state that indicates that the task is running.
095   */
096  RUNNING("running"),
097
098
099
100  /**
101   * The task state that indicates that the task was forced to stop running when
102   * it was canceled by an administrator.
103   */
104  STOPPED_BY_ADMINISTRATOR("stopped_by_administrator"),
105
106
107
108  /**
109   * The task state that indicates that the task was forced to stop running when
110   * it encountered an unrecoverable error.
111   */
112  STOPPED_BY_ERROR("stopped_by_error"),
113
114
115
116  /**
117   * The task state that indicates that the task was forced to stop running when
118   * the task scheduler was shut down.
119   */
120  STOPPED_BY_SHUTDOWN("stopped_by_shutdown"),
121
122
123
124  /**
125   * The task state that indicates that the task has not yet been scheduled.
126   */
127  UNSCHEDULED("unscheduled"),
128
129
130
131  /**
132   * The task state that indicates that the task has one or more unsatisfied
133   * dependencies.
134   */
135  WAITING_ON_DEPENDENCY("waiting_on_dependency"),
136
137
138
139  /**
140   * The task state that indicates that the task is waiting on the start time to
141   * arrive.
142   */
143  WAITING_ON_START_TIME("waiting_on_start_time");
144
145
146
147  // The name of this failed dependency action.
148  private final String name;
149
150
151
152  /**
153   * Creates a new task state with the specified name.
154   *
155   * @param  name  The name of the task state to create.
156   */
157  TaskState(final String name)
158  {
159    this.name = name;
160  }
161
162
163
164  /**
165   * Retrieves the name of this task state.
166   *
167   * @return  The name of this task state.
168   */
169  public String getName()
170  {
171    return name;
172  }
173
174
175
176  /**
177   * Retrieves the task state with the specified name.
178   *
179   * @param  name  The name of the task state to retrieve.
180   *
181   * @return  The requested task state, or {@code null} if there is no state
182   *          with the given name.
183   */
184  public static TaskState forName(final String name)
185  {
186    switch (StaticUtils.toLowerCase(name))
187    {
188      case "canceledbeforestarting":
189      case "canceled-before-starting":
190      case "canceled_before_starting":
191        return CANCELED_BEFORE_STARTING;
192      case "completedsuccessfully":
193      case "completed-successfully":
194      case "completed_successfully":
195        return COMPLETED_SUCCESSFULLY;
196      case "completedwitherrors":
197      case "completed-with-errors":
198      case "completed_with_errors":
199        return COMPLETED_WITH_ERRORS;
200      case "disabled":
201        return DISABLED;
202      case "running":
203        return RUNNING;
204      case "stoppedbyadministrator":
205      case "stopped-by-administrator":
206      case "stopped_by_administrator":
207        return STOPPED_BY_ADMINISTRATOR;
208      case "stoppedbyerror":
209      case "stopped-by-error":
210      case "stopped_by_error":
211        return STOPPED_BY_ERROR;
212      case "stoppedbyshutdown":
213      case "stopped-by-shutdown":
214      case "stopped_by_shutdown":
215        return STOPPED_BY_SHUTDOWN;
216      case "unscheduled":
217        return UNSCHEDULED;
218      case "waitingondependency":
219      case "waiting-on-dependency":
220      case "waiting_on_dependency":
221        return WAITING_ON_DEPENDENCY;
222      case "waitingonstarttime":
223      case "waiting-on-start-time":
224      case "waiting_on_start_time":
225        return WAITING_ON_START_TIME;
226      default:
227        return null;
228    }
229  }
230
231
232
233  /**
234   * Indicates whether this task state indicates that the task has not yet
235   * started running.
236   *
237   * @return  {@code true} if this task state indicates that the task has not
238   *          yet started, or {@code false} if not.
239   */
240  public boolean isPending()
241  {
242    switch (this)
243    {
244      case DISABLED:
245      case UNSCHEDULED:
246      case WAITING_ON_DEPENDENCY:
247      case WAITING_ON_START_TIME:
248        return true;
249      default:
250        return false;
251    }
252  }
253
254
255
256  /**
257   * Indicates whether this task state indicates that the task is currently
258   * running.
259   *
260   * @return  {@code true} if this task state indicates that the task is
261   *          currently running, or {@code false} if not.
262   */
263  public boolean isRunning()
264  {
265    return (this == RUNNING);
266  }
267
268
269
270  /**
271   * Indicates whether this task state indicates that the task has completed all
272   * of the processing that it will do.
273   *
274   * @return  {@code true} if this task state indicates that the task has
275   *          completed all of the processing that it will do, or {@code false}
276   *          if not.
277   */
278  public boolean isCompleted()
279  {
280    return (! (isPending() || isRunning()));
281  }
282
283
284
285  /**
286   * Retrieves a string representation of this task state.
287   *
288   * @return  A string representation of this task state.
289   */
290  @Override()
291  public String toString()
292  {
293    return name;
294  }
295}