1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.engine.conf;
\r
21 import org.apache.log4j.Logger;
\r
23 import compbio.engine.client.ConfExecutable;
\r
24 import compbio.engine.client.Executable;
\r
25 import compbio.engine.client.EngineUtil;
\r
26 import compbio.util.Util;
\r
28 public class DirectoryManager {
\r
30 private static Logger log = Logger.getLogger(DirectoryManager.class);
\r
32 public static final String DELIM = "#";
\r
34 public static String getTaskDirectory(Class<?> clazz) {
\r
35 return clazz.getSimpleName() + DELIM + getNonRepeatableNumber();
\r
38 static long getNonRepeatableNumber() {
\r
39 // The random value is concatenated with time value not added to it and
\r
40 // then converted to long.
\r
41 // Top 3 high order bits are cut and replaced by random number
\r
42 // to make sure that the resulting number fits into long value
\r
43 String longNum = new Long(System.nanoTime()).toString();
\r
44 return Long.parseLong(Util.getRandomNumber(100, 999)
\r
45 + longNum.substring(4));
\r
48 public static Class<Executable<?>> getClass(String taskId) {
\r
49 assert EngineUtil.isValidJobId(taskId);
\r
50 String className = null;
\r
51 if (taskId.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX)) {
\r
52 className = taskId.substring(1, taskId.indexOf(DELIM));
\r
54 className = taskId.substring(0, taskId.indexOf(DELIM));
\r
57 return (Class<Executable<?>>) Class.forName(className);
\r
58 } catch (ClassNotFoundException e) {
\r
59 log.error("Could not parse taskId " + taskId + " Message " + e.getLocalizedMessage(), e.getCause());
\r