1 19 20 package org.netbeans.core.execution; 21 22 import java.lang.reflect.Field ; 23 import java.lang.reflect.Method ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 import org.openide.util.NbBundle; 28 import org.openide.windows.InputOutput; 29 30 31 final class RunClassThread extends Thread implements IOThreadIfc { 32 33 34 private InputOutput io; 35 36 String allName; 38 private final ExecutionEngine engine; 39 40 private final ExecutorTaskImpl task; 41 42 private Runnable run; 43 44 45 static int number = 0; 46 47 48 TaskThreadGroup mygroup; 49 50 51 boolean finalized; 52 53 58 public RunClassThread(TaskThreadGroup base, 59 String name, 60 int number, 61 InputOutput io, 62 org.netbeans.core.execution.ExecutionEngine engine, 63 ExecutorTaskImpl task, 64 Runnable run) { 65 super(base, "exec_" + name + "_" + number); mygroup = base; 67 mygroup.setRunClassThread(this); 68 this.allName = name; 69 this.io = io; 70 this.engine = engine; 71 this.task = task; 72 this.run = run; 73 this.finalized = false; 74 setDaemon(false); 76 this.start(); 77 } 78 79 81 public void run() { 82 mygroup.setFinalizable(); 84 boolean fire = true; 85 86 if (allName == null) { 87 allName = generateName(); 88 fire = false; 89 } 90 91 String ioname = NbBundle.getMessage(RunClassThread.class, "CTL_ProgramIO", allName); 92 93 DefaultSysProcess def; 95 if (io != null) { 96 def = new DefaultSysProcess(this, mygroup, io, allName); 97 TaskIO tIO = new TaskIO(io, ioname, true); 98 io.select(); 99 engine.getTaskIOs ().put (io, tIO); 100 } else { TaskIO tIO = null; 102 tIO = engine.getTaskIOs().getTaskIO(ioname); 103 if (tIO == null) { io = org.openide.windows.IOProvider.getDefault().getIO(ioname, true); 105 tIO = new TaskIO(io, ioname); 106 } else { 107 io = tIO.getInout(); 108 } 109 io.select(); 110 io.setFocusTaken(true); 111 engine.getTaskIOs().put(io, tIO); 112 def = new DefaultSysProcess(this, mygroup, io, allName); 113 } 114 115 ExecutionEvent ev = null; 116 try { 117 118 ev = new ExecutionEvent(engine, def); 119 if (fire) { 120 engine.fireExecutionStarted(ev); 121 } 122 123 synchronized (task.lock) { 124 task.proc = def; 125 task.lock.notifyAll(); 126 } 127 128 run.run(); 130 run = null; 132 133 int result = 2; 134 try { 135 result = def.result(); 136 } catch (ThreadDeath err) { } catch (IllegalMonitorStateException e) { 138 } 140 task.result = result; 141 142 } finally { 143 Thread.interrupted(); if (ev != null) { 145 if (fire) { 146 engine.fireExecutionFinished(ev); 147 } 148 } 149 150 engine.closeGroup(mygroup); task.finished(); 152 engine.getTaskIOs().free(mygroup, io); 154 157 mygroup = null; 158 io = null; 159 synchronized (this) { 160 finalized = true; 161 notifyAll(); 162 } 163 } 164 } 166 public InputOutput getInputOutput() { 167 return io; 168 } 169 170 public synchronized boolean waitForEnd() throws InterruptedException { 171 if (finalized) { 172 return true; 173 } 174 175 this.wait(1000); 176 return finalized; 177 } 178 179 static String generateName() { 180 return NbBundle.getMessage(RunClassThread.class, "CTL_GeneratedName", number++); 181 } 182 183 229 230 } 231 232 | Popular Tags |