1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2009 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
package com.sun.grid.jsv;
import java.io.Serializable;
/**
* The CheckpointSpecifier class represents the checkpointing environment
* settings for a job, including the name of the checkpoint environment to use
* and the frequency with which checkpoints should be taken.
* @see JobDescription#getCheckpointSpecifier()
* @see JobDescription#setCheckpointSpecifier(com.sun.grid.jsv.CheckpointSpecifier)
* @since 6.2u5
*/
public final class CheckpointSpecifier implements Cloneable, Serializable {
/**
* String indicating that checkpoints should never be taken.
*/
public static final String NEVER_STR = "n";
/**
* Code indicating that checkpoints should be taken when the execd
* shuts down
*/
public static final byte ON_SHUTDOWN = 0x01;
/**
* Value indicating that checkpoints should be taken when the execd
* shuts down
*/
public static final String ON_SHUTDOWN_STR = "s";
/**
* Code indicating that checkpoints should be taken periodically at the
* minimum CPU interval as specified by the queue.
*/
public static final byte ON_MIN_CPU_INTERVAL = 0x02;
/**
* String indicating that checkpoints should be taken periodically at the
* minimum CPU interval as specified by the queue.
*/
public static final String ON_MIN_CPU_INTERVAL_STR = "m";
/**
* Code indicating that checkpoints should be taken the job is suspended.
*/
public static final byte ON_SUSPEND = 0x04;
/**
* String indicating that checkpoints should be taken the job is suspended.
*/
public static final String ON_SUSPEND_STR = "x";
/**
* Interval representation of the occasion.
*/
private byte when = 0;
/**
* The checkpoint frequency.
*/
private long interval = 0L;
/**
* The name of the checkpointing environment
*/
private String name = null;
/**
* Get the name of the checkpointing environment.
* @return the name
*/
public String getName() {
return name;
}
/**
* Set the name of the checkpointing environment.
* @param name the name
*/
public void setName(String name) {
this.name = name;
}
/**
* Set whether a checkpoint should be taken when the execution daemon
* shuts down. Setting this value to true will also set the checkpointing
* interval to 0.
* @param set whether to take a checkpoint
* @return the previous value
* @see #getInterval()
*/
public boolean onShutdown(boolean set) {
boolean ret = (when & ON_SHUTDOWN) != 0;
if (set) {
when |= ON_SHUTDOWN;
interval = 0L;
} else {
when &= ~ON_SHUTDOWN;
}
return ret;
}
/**
* Set whether a checkpoint should be taken periodically at the minimum
* CPU interval as specified by the queue. Setting this value to true will
* also set the checkpointing interval to 0.
* @param set whether to take a checkpoint
* @return the previous value
* @see #getInterval()
*/
public boolean onMinCpuInterval(boolean set) {
boolean ret = (when & ON_MIN_CPU_INTERVAL) != 0;
if (set) {
when |= ON_MIN_CPU_INTERVAL;
interval = 0L;
} else {
when &= ~ON_MIN_CPU_INTERVAL;
}
return ret;
}
/**
* Set whether a checkpoint should be taken when the job is suspended.
* Setting this value to true will also set the checkpointing
* interval to 0.
* @param set whether to take a checkpoint
* @return the previous value
* @see #getInterval()
*/
public boolean onSuspend(boolean set) {
boolean ret = (when & ON_SUSPEND) != 0;
if (set) {
when |= ON_SUSPEND;
interval = 0L;
} else {
when &= ~ON_SUSPEND;
}
return ret;
}
/**
* Indicate that a checkpoint should never be taken.
* @return the previous occasion value, as would be returned by
* getOccasion()
* @see #getOccasion()
*/
public byte never() {
byte ret = when;
when = 0;
return ret;
}
/**
* Set the interval at which checkpoints should be taken. If the value is
* 0, periodic checkpoints will not be taken. If the value is non-zero,
* the checkpoint occasion will be set to "never".
* @param sec the number of seconds between checkpoints
* @return the previous value
* @see #getOccasion()
*/
public long setInterval(long sec) {
if (sec < 0L) {
throw new IllegalArgumentException("attempted to set the interval to a negative time value");
}
long ret = interval;
interval = sec;
if (interval > 0) {
never();
}
return ret;
}
/**
* Set the interval at which checkpoints should be taken. If the value is
* 0, periodic checkpoints will not be taken. If the value is non-zero,
* the checkpoint occasion will be set to "never".
* @param hours the number of hours between checkpoints -- this value is
* combined to the number of minutes and seconds
* @param minutes the number of minutes between checkpoints -- this value is
* combined to the number of hours and seconds
* @param seconds the number of seconds between checkpoints -- this value is
* combined to the number of minutes and hours
* @return the previous value
* @see #getOccasion()
*/
public long setInterval(int hours, int minutes, int seconds) {
if (hours < 0L) {
throw new IllegalArgumentException("attempted to set the interval to a negative hours value");
} else if (minutes < 0L) {
throw new IllegalArgumentException("attempted to set the interval to a negative minutes value");
} else if (seconds < 0L) {
throw new IllegalArgumentException("attempted to set the interval to a negative seconds value");
}
return setInterval(seconds + 60 * (minutes + 60 * hours));
}
/**
* Get the number of seconds between checkpoints.
* @return the number of seconds
*/
public long getInterval() {
return interval;
}
/**
* Get a byte value that represents the occasions when the job should be
* checkpointed. This value is composed by ORing together the code for the
* occasions when the job should be checkpointed. If the occasion value is
* non-zero, the checkpointing interval will be set to 0.
* @return the occasion value
* @see #ON_MIN_CPU_INTERVAL
* @see #ON_SHUTDOWN
* @see #ON_SUSPEND
* @see #getInterval()
*/
public byte getOccasion() {
return when;
}
/**
* Set the occasions when the job should be checkpointed according to a
* a byte value composed by ORing together the code for the
* occasions when the job should be checkpointed. If the occasion value is
* non-zero, the checkpointing interval will be set to 0.
* @param value the occasion value
* @see #ON_MIN_CPU_INTERVAL
* @see #ON_SHUTDOWN
* @see #ON_SUSPEND
* @see #getInterval()
*/
void setOccasion(int value) {
if (value > 0x07) {
throw new IllegalArgumentException("attempted to set the occasion specifier to an illegal value: " + value);
}
when = (byte)value;
if (when != 0) {
interval = 0L;
}
}
/**
* Set the occasions when the job should be checkpointed according to a
* a String composed by combining the string values for the
* occasions when the job should be checkpointed. If the occasion value is
* not NEVER, the checkpointing interval will be set to 0.
* @param value the occasion string
* @see #ON_MIN_CPU_INTERVAL_STR
* @see #ON_SHUTDOWN_STR
* @see #ON_SUSPEND_STR
* @see #getInterval()
*/
public void setOccasion(String value) {
if ((value != null) && !value.equals("") && !value.matches("n|[msx]*")) {
throw new IllegalArgumentException("attempted to set the occasion specifier to an illegal string: " + value);
}
never();
if ((value != null) && !value.equals("")) {
if (value.contains(ON_MIN_CPU_INTERVAL_STR)) {
onMinCpuInterval(true);
}
if (value.contains(ON_SHUTDOWN_STR)) {
onShutdown(true);
}
if (value.contains(ON_SUSPEND_STR)) {
onSuspend(true);
}
}
}
/**
* Get an occasion string that represents the occasions when the job should
* be checkpointed. This value is composed by combining the string values
* for the occasions when the job should be checkpointed.
* @return the occasion string
* @see #ON_MIN_CPU_INTERVAL_STR
* @see #ON_SHUTDOWN_STR
* @see #ON_SUSPEND_STR
*/
public String getOccasionString() {
StringBuilder ret = new StringBuilder();
if ((when & ON_MIN_CPU_INTERVAL) != 0) {
ret.append(ON_MIN_CPU_INTERVAL_STR);
}
if ((when & ON_SHUTDOWN) != 0) {
ret.append(ON_SHUTDOWN_STR);
}
if ((when & ON_SUSPEND) != 0) {
ret.append(ON_SUSPEND_STR);
}
if (ret.length() == 0) {
ret.append(NEVER_STR);
}
return ret.toString();
}
@Override
public boolean equals(Object obj) {
boolean ret = false;
if ((obj instanceof CheckpointSpecifier) &&
(when == ((CheckpointSpecifier) obj).when) &&
(interval == ((CheckpointSpecifier) obj).interval) &&
((name == ((CheckpointSpecifier) obj).name) ||
name.equals(((CheckpointSpecifier) obj).name))) {
ret = true;
}
return ret;
}
@Override
public int hashCode() {
if (name != null) {
return name.hashCode();
} else if (interval != 0) {
return (int)interval;
} else {
return when;
}
}
@Override
public CheckpointSpecifier clone() {
CheckpointSpecifier clone = null;
try {
clone = (CheckpointSpecifier)super.clone();
} catch (CloneNotSupportedException e) {
assert false : "CheckpointSpecifier class not cloneable";
}
return clone;
}
@Override
public String toString() {
if ((name != null) && (when != 0x00)) {
return name + ": " + getOccasionString();
} else if (name != null) {
return name + ": " + getInterval();
} else if (when != 0x00) {
return "[null]: " + getOccasionString();
} else {
return "[null]: " + getInterval();
}
}
}
|