1 28 package net.sf.jasperreports.engine.fill; 29 30 import net.sf.jasperreports.engine.JRException; 31 import net.sf.jasperreports.engine.JRRuntimeException; 32 33 34 44 public class JRThreadSubreportRunner extends JRSubreportRunnable implements JRSubreportRunner 45 { 46 private final JRBaseFiller subreportFiller; 47 48 private Thread fillThread; 49 50 public JRThreadSubreportRunner(JRFillSubreport fillSubreport, JRBaseFiller subreportFiller) 51 { 52 super(fillSubreport); 53 this.subreportFiller = subreportFiller; 54 } 55 56 public boolean isFilling() 57 { 58 return fillThread != null; 59 } 60 61 public JRSubreportRunResult start() 62 { 63 fillThread = new Thread (this, subreportFiller.getJasperReport().getName() + " subreport filler"); 64 fillThread.start(); 65 66 return waitResult(); 67 } 68 69 public JRSubreportRunResult resume() 70 { 71 subreportFiller.notifyAll(); 73 74 return waitResult(); 75 } 76 77 protected JRSubreportRunResult waitResult() 78 { 79 try 80 { 81 subreportFiller.wait(); } 86 catch (InterruptedException e) 87 { 88 throw new JRRuntimeException("Error encountered while waiting on the report filling thread.", e); 89 } 90 91 return runResult(); 92 } 93 94 public void reset() 95 { 96 fillThread = null; 97 } 98 99 public void cancel() throws JRException 100 { 101 subreportFiller.notifyAll(); 104 105 if (isRunning()) 106 { 107 try 108 { 109 subreportFiller.wait(); 111 } 112 catch(InterruptedException e) 113 { 114 throw new JRException("Error encountered while waiting on the subreport filling thread.", e); 115 } 116 } 117 } 118 119 public void suspend() throws JRException 120 { 121 subreportFiller.notifyAll(); 123 124 try 125 { 126 subreportFiller.wait(); 128 } 129 catch(InterruptedException e) 130 { 131 throw new JRException("Error encountered while waiting on the subreport filling thread.", e); 132 } 133 } 134 135 public void run() 136 { 137 super.run(); 138 139 synchronized (subreportFiller) 140 { 141 subreportFiller.notifyAll(); 143 } 144 145 155 } 156 } 157 | Popular Tags |