1 package org.jacorb.notification.engine; 2 3 23 24 import org.jacorb.notification.util.AbstractPoolable; 25 26 30 31 public abstract class AbstractTask extends AbstractPoolable implements Runnable , Schedulable 32 { 33 private TaskExecutor taskExecutor_; 34 35 37 protected TaskExecutor getTaskExecutor() 38 { 39 return taskExecutor_; 40 } 41 42 protected void setTaskExecutor(TaskExecutor taskExecutor) 43 { 44 taskExecutor_ = taskExecutor; 45 } 46 47 50 public abstract void doWork() throws Exception ; 51 52 protected boolean isRunnable() 53 { 54 return true; 55 } 56 57 63 public void run() 64 { 65 try 66 { 67 if (isRunnable()) 68 { 69 doWork(); 70 } 71 } catch (Throwable t) 72 { 73 handleTaskError(this, t); 74 } finally 75 { 76 dispose(); 77 } 78 } 79 80 abstract void handleTaskError(AbstractTask t, Throwable error); 81 82 83 protected void checkInterrupt() throws InterruptedException 84 { 85 if (Thread.currentThread().isInterrupted()) 86 { 87 throw new InterruptedException (); 88 } 89 } 90 91 99 protected void schedule(boolean directRunAllowed) throws InterruptedException 100 { 101 schedule(taskExecutor_, directRunAllowed); 102 } 103 104 114 protected void schedule(TaskExecutor executor, boolean directRunAllowed) 115 throws InterruptedException 116 { 117 if (directRunAllowed) 118 { 119 run(); 120 } 121 else 122 { 123 executor.execute(this); 124 } 125 } 126 } | Popular Tags |