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