1 22 package com.scalagent.scheduler; 23 24 import fr.dyade.aaa.agent.*; 25 26 import java.io.*; 27 import java.util.Date ; 28 29 import org.objectweb.util.monolog.api.BasicLevel; 30 import org.objectweb.util.monolog.api.Logger; 31 32 40 public class SchedulerAlarm implements NotificationInputStream { 41 public static Logger logger = Debug.getLogger(SchedulerAlarm.class.getName()); 42 43 44 long time; 45 46 49 public SchedulerAlarm() { 50 time = 0; 51 } 52 53 61 public Notification readNotification() throws ClassNotFoundException , IOException { 62 synchronized (this) { 63 waitLoop: while (true) { 64 while (time == 0) { 65 try { 66 if (logger.isLoggable(BasicLevel.DEBUG)) 67 logger.log(BasicLevel.DEBUG, "SchedulerAlarm indefinitely waits"); 68 wait(); 69 } catch (InterruptedException exc) { 70 } 72 } 73 74 if (time < 0) { 75 throw new EOFException(); 77 } 78 79 long localTime = time; 81 time = 0; 82 try { 83 if (logger.isLoggable(BasicLevel.DEBUG)) 84 logger.log(BasicLevel.DEBUG, "SchedulerAlarm waits " + localTime); 85 wait(localTime); 86 } catch (InterruptedException exc) { 87 if (logger.isLoggable(BasicLevel.DEBUG)) 89 logger.log(BasicLevel.DEBUG, "SchedulerAlarm interrupted", exc); 90 } 91 if (time == 0) { 92 if (logger.isLoggable(BasicLevel.DEBUG)) 94 logger.log(BasicLevel.DEBUG, "SchedulerAlarm break loop"); 95 break waitLoop; 96 } else { 97 if (logger.isLoggable(BasicLevel.DEBUG)) 98 logger.log(BasicLevel.DEBUG, "SchedulerAlarm loops"); 99 } 100 } 101 } 102 103 if (logger.isLoggable(BasicLevel.DEBUG)) 105 logger.log(BasicLevel.DEBUG, "SchedulerAlarm send notif"); 106 return new ScheduleNotification(); 107 } 108 109 116 synchronized void setTime(long time) { 117 if (logger.isLoggable(BasicLevel.DEBUG)) 118 logger.log(BasicLevel.DEBUG, "SchedulerAlarm.setTime(" + 119 time + ')'); 120 this.time = time; 121 notify(); 122 } 123 124 129 public void close() throws IOException { 130 if (logger.isLoggable(BasicLevel.DEBUG)) 131 logger.log(BasicLevel.DEBUG, "SchedulerAlarm.close()"); 132 synchronized(this) { 133 this.time = -1; 134 notify(); 135 } 136 } 137 138 } 139 | Popular Tags |