1 26 27 package org.objectweb.jonas_lib.deployment.work; 28 29 import java.util.Enumeration ; 30 import java.util.Vector ; 31 32 import org.objectweb.util.monolog.api.Logger; 33 import org.objectweb.util.monolog.api.BasicLevel; 34 35 import org.objectweb.jonas.common.Log; 36 37 44 public class WorkCleaner extends Thread { 45 46 49 private static Logger logger = Log.getLogger(Log.JONAS_DEPLOY_WORK_PREFIX); 50 51 54 private static final int SLEEP_TIME = 300000; 55 56 60 private static WorkCleaner unique = null; 61 62 65 private Vector taskList = null; 66 67 70 private WorkCleaner() { 71 super("WorkCleaner"); 72 this.setPriority(Thread.MIN_PRIORITY); 75 taskList = new Vector (); 76 } 77 78 81 protected static Logger getLogger() { 82 return logger; 83 } 84 85 89 public static synchronized WorkCleaner getInstance() { 90 if (unique == null) { 91 unique = new WorkCleaner(); 92 } 93 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 94 getLogger().log(BasicLevel.DEBUG, "getInstance : ->" + unique); 95 } 96 return unique; 97 } 98 99 104 public synchronized void registerTask(AbsCleanTask absCleanTask) throws CleanerException { 105 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 106 getLogger().log(BasicLevel.DEBUG, "registerTask : called"); 107 } 108 if (taskList == null) { 110 throw new CleanerException("Can not add an entry, the vector is null"); 111 } 112 if (absCleanTask == null) { 113 throw new CleanerException("Can not add a null entry"); 114 } 115 if (!taskList.contains(absCleanTask)) { 117 taskList.add(absCleanTask); 118 } 119 } 120 121 124 public synchronized void executeTasks() { 125 try { 126 AbsCleanTask absCleanTask = null; 127 128 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 129 getLogger().log(BasicLevel.DEBUG, "executeTasks : wake up"); 130 } 131 for (Enumeration e = taskList.elements(); e.hasMoreElements();) { 132 133 absCleanTask = (AbsCleanTask) e.nextElement(); 134 absCleanTask.execute(); 135 } 136 137 } catch (CleanerException e) { 138 e.printStackTrace(); 139 } 140 } 141 142 145 public void run() { 146 147 for (;;) { 148 executeTasks(); 149 try { 150 Thread.sleep(SLEEP_TIME); 151 } catch (InterruptedException e) { 152 throw new RuntimeException ("Thread fail to sleep"); 153 } 154 } 155 } 156 157 } 158 | Popular Tags |