WebScript { traversal runScript(RunServiceVisitor) { to-stop {Url,TimeOut,Limit,Repeat,Stall,Fail,Post,Get, Execution,SequenceOp,ConcurrentOp};} traversal stopScript(StopServiceVisitor) { to-stop {Url,TimeOut,Limit,Repeat,Stall,Fail,Post,Get, Execution,SequenceOp,ConcurrentOp};} } Service { (@ final static float CHECKPERIOD = (float)0.5; protected Timer m_timer; protected Clock m_clock; protected RunningThread m_running_thread; protected float m_interval; protected boolean m_has_timer; protected float m_rate; public void init() {}; public String getContent() {return null;}; public float getRate(){return 0;}; public void stop() {}; public void setTimer(float interval) {}; public void setClock(float starttime,float interval,float rate) {}; @) } Url { (@ public void init() { m_running_thread = new UrlRun(get_url()); } public void setTimer(float interval) { m_timer = new Timer(m_running_thread,interval); } public void setClock(float starttime,float interval,float rate) { m_clock = new Clock(m_running_thread,starttime,interval,rate); } public String getContent() { System.out.println("Url:" + get_url()); if(m_timer != null) m_timer.start(); if(m_clock != null) m_clock.start(); m_running_thread.start(); try { while(m_running_thread.isAlive()){Thread.yield();} } catch(NullPointerException e) { System.out.println("Null Pointer"); } return m_running_thread.getResult(); } public float getRate() { return m_running_thread.getRate(); } public void stop() { System.out.println("stop in Url"); m_running_thread.stop(); } @) } TimeOut { (@ public String getContent() { System.out.println("TimeOut:" + get_timeout().get_value()); float interval = (float)get_timeout().get_value(); Service service = get_service(); //service.setGui(m_gui); service.init(); service.setTimer(interval); return service.getContent(); } public float getRate() { return get_service().getRate(); } public void stop() { get_service().stop(); } @) } Stall { (@ public void init() { m_running_thread = new RunningThread(); } public void setTimer(float interval) { m_timer = new Timer(m_running_thread,interval); } public String getContent() { System.out.println("Stall:"); if(m_timer != null) m_timer.start(); m_running_thread.start(); try { while(m_running_thread.isAlive()){Thread.yield();} } catch(NullPointerException e) { System.out.println("Null Pointer"); } return null; } public float getRate() { return 0; } public void stop() { m_running_thread.stop(); } @) } Fail { (@ public String getContent() { return null; } @) } Limit { (@ public String getContent() { System.out.println("Limit: star time ->" + get_start_time().get_value() + " rate ->" + get_rate().get_value() ); float starttime = (float)get_start_time().get_value(); float rate = (float)get_rate().get_value(); Service service = get_service(); //service.setGui(m_gui); service.init(); service.setClock(starttime,CHECKPERIOD,rate); return service.getContent(); } public void stop() { get_service().stop(); } @) } Repeat { (@ public String getContent() { System.out.print("Repeat:"); Service service = get_service(); //service.setGui(m_gui); service.init(); String result; while( (result = service.getContent()) == null) { System.out.println("service failed, do it again"); } return result; } public void stop() { System.out.println("stop in Repeat"); get_service().stop(); } @) } ExecutionOp { (@ protected Service m_service1; protected Service m_service2; public void init(Service s1,Service s2) { m_service1 = s1; m_service2 = s2; }; public String getContent(){return null;} ; public void stop() { if(m_service1 != null) m_service1.stop(); if(m_service2 != null) m_service2.stop(); }; @) } SequenceOp { (@ public String getContent() { String result; System.out.println("Sequence Execution"); m_service1.init(); if((result = m_service1.getContent()) == null) { System.out.println("service 1 failed"); m_service2.init(); return m_service2.getContent(); } else { System.out.println("servece 2 succeed"); return result; } } @) } ConcurrentOp { (@ public String getContent() { String result1; String result2; System.out.println("Concurrent Execution"); m_service1.init(); m_service2.init(); RunningService rs1 = new RunningService(m_service1); RunningService rs2 = new RunningService(m_service2); rs1.start(); rs2.start(); while(true) { if((result1 = rs1.getResult()) != null) { rs2.stopRun(); return result1; } if((result2 = rs2.getResult()) != null) { rs1.stopRun(); return result2; } if((!rs1.isAlive()) && (!rs2.isAlive())) return null; } } @) } Execution { (@ public String getContent() { System.out.println("Execution:"); Service s1 = get_service1(); Service s2 = get_service2(); ExecutionOp op = get_op(); op.init(s1,s2); return op.getContent(); } @) } Post { (@ public void init() { String data = new String(); for(Enumeration e=get_data().elements();e.hasMoreElements();) { data = data + e.nextElement(); } m_running_thread = new PostRun(get_cgi(),data); } public void setTimer(float interval) { m_timer = new Timer(m_running_thread,interval); } public void setClock(float starttime,float interval,float rate) { m_clock = new Clock(m_running_thread,starttime,interval,rate); } public String getContent() { System.out.println("Post:" + get_cgi()); if(m_timer != null) m_timer.start(); if(m_clock != null) m_clock.start(); m_running_thread.start(); try { while(m_running_thread.isAlive()){Thread.yield();} } catch(NullPointerException e) { System.out.println("Null Pointer"); } return m_running_thread.getResult(); } public float getRate() { return m_running_thread.getRate(); } public void stop() { System.out.println("stop in Url"); m_running_thread.stop(); } @) } Get { (@ public void init() { String data = new String(); for(Enumeration e=get_data().elements();e.hasMoreElements();) { data = data + e.nextElement(); } m_running_thread = new GetRun(get_cgi(),data); } public void setTimer(float interval) { m_timer = new Timer(m_running_thread,interval); } public void setClock(float starttime,float interval,float rate) { m_clock = new Clock(m_running_thread,starttime,interval,rate); } public String getContent() { System.out.println("Get:" + get_cgi()); if(m_timer != null) m_timer.start(); if(m_clock != null) m_clock.start(); m_running_thread.start(); try { while(m_running_thread.isAlive()){Thread.yield();} } catch(NullPointerException e) { System.out.println("Null Pointer"); } return m_running_thread.getResult(); } public float getRate() { return m_running_thread.getRate(); } public void stop() { System.out.println("stop in Url"); m_running_thread.stop(); } @) } RunServiceVisitor { (@ private Gui m_gui; void setGui(Gui gui) { m_gui = gui; } @) before Service (@ host.init(); String result= host.getContent(); if(result != null) { m_gui.clear(); m_gui.display(result); System.out.println("Script Done"); } @) } StopServiceVisitor { before Service (@ System.out.println("Stop run in StopVisitor"); host.stop(); @) } Main { (@ public static void main(String[] argvs) { Gui gui = new Gui(); gui.setSize(800,600); gui.show(); } @) }