import java.lang.*; import java.io.*; import java.util.*; import EDU.neu.ccs.demeter.*; import ServiceExecutorThread; class TimeOut extends Service { protected float timeout; public float get_timeout() { return timeout; } public void set_timeout(float new_timeout) { timeout = new_timeout; } protected Service service; public Service get_service() { return service; } public void set_service(Service new_service) { service = new_service; } public TimeOut() { super(); } public TimeOut(float timeout, Service service) { super(); set_timeout(timeout); set_service(service); } public static TimeOut parse(java.io.Reader in) throws ParseException { return new Parser(in)._TimeOut(); } public static TimeOut parse(java.io.InputStream in) throws ParseException { return new Parser(in)._TimeOut(); } public static TimeOut parse(String s) { try { return parse(new java.io.StringReader(s)); } catch (ParseException e) { throw new RuntimeException(e.toString()); } } void universal_trv0_bef(UniversalVisitor _v_) { super.universal_trv0_bef(_v_); _v_.before(this); } void universal_trv0_aft(UniversalVisitor _v_) { _v_.after(this); super.universal_trv0_aft(_v_); } void universal_trv0(UniversalVisitor _v_) { universal_trv0_bef(_v_); _v_.before_timeout(this, timeout); _v_.after_timeout(this, timeout); _v_.before_service(this, service); service.universal_trv0(_v_); _v_.after_service(this, service); super.universal_trv0(_v_); universal_trv0_aft(_v_); } void all_WebScript_trv_bef(UniversalVisitor __v0) { super.all_WebScript_trv_bef(__v0); __v0.before(this); } void all_WebScript_trv_aft(UniversalVisitor __v0) { __v0.after(this); super.all_WebScript_trv_aft(__v0); } void all_WebScript_trv(UniversalVisitor __v0) { all_WebScript_trv_bef(__v0); __v0.before_timeout(this, timeout); __v0.after_timeout(this, timeout); __v0.before_service(this, service); service.all_WebScript_trv(__v0); __v0.after_service(this, service); super.all_WebScript_trv(__v0); all_WebScript_trv_aft(__v0); } // the method that attempts to execute ths service public boolean executeService(PrintStream out) { // create the mutex ThreadMutex mutex = new ThreadMutex(1,out); // create a thread ServiceExecutorThread thread = new ServiceExecutorThread(service, mutex); thread.run(); long millisec = (long)timeout; try { // wait for the thread to finish for millisec thread.join(millisec); } catch (InterruptedException ex) { } // if the thread is still alive then destroy it. if (thread.isAlive()) { System.out.println("Service Timedout.."); thread.destroy(); return false; } return true; } }