001 // AperiodicParameters.java, created by cata 002 // Copyright (C) 2001 Catalin Francu <cata@mit.edu> 003 // Licensed under the terms of the GNU GPL; see COPYING for details. 004 005 package javax.realtime; 006 007 import java.util.LinkedList; 008 import java.util.Iterator; 009 010 /** The release parameter object characterizes a schedulable object that may become 011 * active at atny time. When a reference to a <code>AperiodicParameters</code> 012 * object is given as a parameter to a constructor the 013 * <code>AperiodicParameters</code> object becomes bound to the object being created. 014 * Changed to the values in the <code>AperiodicParameters</code> object affect the 015 * constructed object. If given to more than one constructor then changes to the values 016 * in the <code>AperiodicParameters</code> object affect <i>all</i> of the associated 017 * objects. Note that this is a one-to-many relationship and <i>not</i> a many-to-many. 018 * <p> 019 * <b>Caution:</b> This class is explicitly unsafe in multithreaded situations when it 020 * is being changed. No synchronization is done. It is assumed that users of this class 021 * who are mutating instances will be doing their own synchronization at a higher level. 022 */ 023 public class AperiodicParameters extends ReleaseParameters { 024 LinkedList schList = new LinkedList(); 025 026 /** Create an <code>AperiodicParameters</code> object. 027 * 028 * @param cost Processing time per invocation. On implementations which can measure 029 * the amount of time a schedulable object is executed, this value is the 030 * maximum amount of time a schedulable object receives. On implementations 031 * which cannot measure execution time, this value is used as a hint to the 032 * feasibility algorithm. On such systems it is not possible to determine 033 * when any particular object exceeds cost. Equivalent to 034 * <code>RelativeTime(0, 0)</code> if null. 035 * @param deadline The latest permissible completion time measured from the release 036 * time of the associated invocation of the schedulable object. Not 037 * used in feasibility analysis for minimum implementation. If null, 038 * the deadline will be <code>RelativeTime(Long.MAX_VALUE, 999999)</code>. 039 * @param overrunHandler This handler is invoked if an invocation of the schedulable 040 * object exceeds cost. Not required for minimum implementation. 041 * If null, nothing happens on the overrun condition. 042 * @param missHandler This handler is invoked if the <code>run()</code> method of the 043 * schedulable object is still executing after the deadline has passed. 044 * Although minimum implementations do not consider deadlines in 045 * feasibility calculations, they must recognize variable deadlines 046 * and invoke the miss handler as appropriate. If null, nothing 047 * happens on the miss deadline condition. 048 */ 049 public AperiodicParameters(RelativeTime cost, RelativeTime deadline, 050 AsyncEventHandler overrunHandler, 051 AsyncEventHandler missHandler) { 052 super(cost, 053 (deadline == null) ? new RelativeTime(Long.MAX_VALUE, 999999) : 054 deadline, 055 overrunHandler, missHandler); 056 } 057 058 /** This method appears in many classes in the RTSJ and with various parameters. 059 * The parameters are either new scheduling characteristics for an instance 060 * <code>Schedulable</code> or an instance of <code>Schedulable</code>. The 061 * method first performs a feasibility analysis using the new scheduling 062 * characteristics as replacements for the matching scheduling characteristics 063 * of either <code>this</code> or the given instance of <code>Schedulable</code>. 064 * If the resulting system is feasible the method replaces the current scheduling 065 * characteristics, of either <code>this</code> or the given instance of 066 * <code>Schedulable</code> as appropriate, with the new scheduling characteristics. 067 * 068 * @param cost The proposed cost. 069 * @param deadline The proposed deadline. 070 * @return True, if the resulting system is feasible and the changes are made. 071 * False, if the resulting system is not feasible and no changes are made. 072 */ 073 public boolean setIfFeasible(RelativeTime cost, 074 RelativeTime deadline) { 075 boolean b = true; 076 for (Iterator it = schList.iterator(); it.hasNext(); ) { 077 Schedulable sch = (Schedulable)it.next(); 078 Scheduler sched = sch.getScheduler(); 079 if (!sched.isFeasible(sch, new AperiodicParameters(cost, deadline, overrunHandler, missHandler))) { 080 b = false; 081 break; 082 } 083 } 084 085 if (b) { 086 setCost(cost); 087 setDeadline(deadline); 088 } 089 return b; 090 } 091 092 /** Informs <code>this</code> that there is one more instance of <code>Schedulable</code> 093 * that uses <code>this</code> as its <code>ReleaseParameters</code>. 094 */ 095 public boolean bindSchedulable(Schedulable sch) { 096 return schList.add(sch); 097 } 098 099 /** Informs <code>this</code> that <code>Schedulable sch</code> 100 * that uses <code>this</code> as its <code>ReleaseParameters</code>. 101 */ 102 public boolean unbindSchedulable(Schedulable sch) { 103 return schList.remove(sch); 104 } 105 }