1 29 30 31 package hero.hook; 32 33 import java.sql.Date ; 34 import java.util.Calendar ; 35 import java.util.Collection ; 36 import java.util.GregorianCalendar ; 37 import java.util.Iterator ; 38 39 import hero.util.HeroHookException; 40 import hero.interfaces.BnNodeLocal; 41 42 43 public class TestDeadlines implements hero.hook.NodeHookI { 44 45 public void create(Object b,BnNodeLocal n) throws HeroHookException { 46 47 } 48 49 public void beforeStart(Object b,BnNodeLocal n) throws HeroHookException { 50 } 51 public void afterStart(Object b,BnNodeLocal n) throws HeroHookException { 52 } 53 public void beforeTerminate(Object b,BnNodeLocal n) throws HeroHookException {} 54 public void afterTerminate(Object b,BnNodeLocal n) throws HeroHookException {} 55 public void onCancel(Object b,BnNodeLocal n) throws HeroHookException {} 56 public void anticipate(Object b,BnNodeLocal n) throws HeroHookException {} 57 public void onReady(Object b,BnNodeLocal n) throws HeroHookException {} 58 public void onDeadline(Object b,BnNodeLocal n) throws HeroHookException { 59 try{ 60 String name=n.getName(); 61 if (n.getDeadlines().size()!=0){ 62 Collection co = n.getDeadlines(); 63 Iterator it = co.iterator(); 64 System.out.println("Deadlines Test, node name: "+name); 65 System.out.println("One of the following deadline has been executed"); 66 while (it.hasNext()){ 67 Date date = (Date )it.next(); 68 long lt = date.getTime(); 69 Calendar calendar = new GregorianCalendar (); 70 calendar.setTime(date); 71 System.out.println("date (long) = " + lt + " - date (YY/MM/DD/HH/MM/SS)= " + calendar.get(Calendar.YEAR) + "/" + calendar.get(Calendar.MONTH) + "/" + 72 calendar.get(Calendar.DAY_OF_MONTH) + "/" + calendar.get(Calendar.HOUR) + "/" + calendar.get(Calendar.MINUTE) + 73 "/" + calendar.get(Calendar.SECOND)); 74 } 75 } 76 if (n.getRelativeDeadlines().size()!=0){ 77 Collection co = n.getRelativeDeadlines(); 78 Iterator it = co.iterator(); 79 System.out.println("Deadlines Test, node name: "+name); 80 System.out.println("One of the following relative deadline has been executed"); 81 while (it.hasNext()){ 82 Date date = (Date )it.next(); 83 long lt = date.getTime(); 84 Calendar calendar = new GregorianCalendar (); 85 calendar.setTime(date); 86 System.out.println("date (long) = " + lt + " - date (YY/MM/DD/HH/MM/SS) = " + calendar.get(Calendar.YEAR) + "/" + calendar.get(Calendar.MONTH) + "/" + 87 calendar.get(Calendar.DAY_OF_MONTH) + "/" + calendar.get(Calendar.HOUR) + "/" + calendar.get(Calendar.MINUTE) + 88 "/" + calendar.get(Calendar.SECOND)); 89 } 90 } 91 }catch(Exception e){e.printStackTrace();} 92 } 93 94 } 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | Popular Tags |