001    package javax.realtime;
002    
003    /** An asynchronous event handler encapsulates code that gets run
004     *  at some time after an <code>AsyncEvent</code> occurs.
005     *  <p>
006     *  It is essentially a <code>java.lang.Runnable</code> with a set
007     *  of parameter objects, making it very much like
008     *  <code>RealtimeThread</code>. The expectation is that there may
009     *  be thousands of events, with corresponding handlers, averaging
010     *  about one handler per event. The number of unblocked
011     *  (i.e., scheduled) handlers is expected to be relatively small.
012     *  <p>
013     *  It is guaranteed that multiple firings of an event handler will
014     *  be serialized. It is also guaranteed that (unless the handler
015     *  explicitly chooses otherwise) for each firing of the handler,
016     *  there will be one execution of the <code>handleAsyncEvent</code>
017     *  method.
018     *  <p>
019     *  For instances of <code>AsyncEventHandler</code> with a release
020     *  parameter of type <code>SporadicParameters</code> have a list of
021     *  release times which correspond to execution times of
022     *  <code>AsyncEvent.fire()</code>. The minimum interarrival time
023     *  specified in <code>SporadicParameters</code> is enforced as
024     *  defined there. Unless the handler explicitly chooses otherwise
025     *  there will be one execution of the code in <code>handleAsyncEvent</code>
026     *  for each entry in the list. The i-th execution of
027     *  <code>handleAsyncEvent</code> will be realeased for scheduling
028     *  at the time of the i-th entry in the list.
029     *  <p>
030     *  The is no restriction on what handlers may do. They may run for
031     *  a long or short time, and they may block. (Note: blocked handlers
032     *  may hold system resources).
033     *  <p>
034     *  Normally, handlers are bound to an execution context dynamically,
035     *  when their <code>AsyncEvent</code> occurs. This can introduce a
036     *  (small) time penalty. For critical handlers that can not afford
037     *  the expense, and where this penalty is a problem, use a
038     *  <code>BoundAsyncEventHandler</code>.
039     *  <p>
040     *  The semantics for memory areas that were defined for realtime
041     *  threads apply in the same way to instances of <code>AsyncEventHandler</code>.
042     *  They may inherit a scope stack when they are created, and the single
043     *  parent rule applies to the use of memory scopes for instances of
044     *  <code>AsyncEventHandler</code> just as it does in realtime threads.
045     */
046    public class AsyncEventHandler implements Schedulable {
047        
048        protected int fireCount = 0;
049        protected boolean nonheap = false;
050        protected Runnable logic;
051    
052        protected Scheduler currentScheduler;
053    
054        protected SchedulingParameters scheduling;
055        protected ReleaseParameters release;
056        protected MemoryParameters memParams;
057        protected MemoryArea memArea;
058        protected ProcessingGroupParameters group;
059        private static long UID = 0;
060        private long myUID = ++UID;
061    
062        /** Create an instance of <code>AsyncEventHandler</code> whose
063         *  <code>SchedulingParameters</code> are inherited from the current
064         *  thread and does not have either <code>ReleaseParameters</code> or
065         *  <code>MemoryParameters</code>.
066         */
067        public AsyncEventHandler() {
068            if (Thread.currentThread() instanceof RealtimeThread)
069                scheduling = RealtimeThread.currentRealtimeThread().getSchedulingParameters();
070            else scheduling = null;
071            release = null;
072            memParams = null;
073        }
074    
075        /** Create an instance of <code>AsyncEventHandler</code> whose
076         *  parameters are inherited from the current thread, if the current
077         *  thread is a <code>RealtimeThread</code>, or null, otherwise.
078         *
079         *  @param nonheap A flag meaning, when true, that this will have
080         *                 characteristics identical to a
081         *                 <code>NoHeapRealtimeThread</code>. A false value
082         *                 means this will have characteristics identical to a
083         *                 <code>RealtimeThread</code>. If true and the current
084         *                 thread is <i>not</i> a <code>NoHeapRealtimeThread</code>
085         *                 of a <code>RealtimeThread</code> executing within a
086         *                 <code>ScopedMemory</code> or <code>ImmortalMemory</code>
087         *                 scope then an <code>IllegalArgumentException<code> is thrown.
088         *  @throws java.lang.IllegalArgumentException If the initial memory area is
089         *                                             in heap memory, and the
090         *                                             <code>nonheap</code> parameter
091         *                                             is true.
092         */
093        public AsyncEventHandler(boolean nonheap) {
094            this();
095            this.nonheap = nonheap;
096        }
097    
098        /** Create an instance of <code>AsyncEventHandler</code> whose
099         *  <code>SchedulingParameters</code> are inherited from the current
100         *  thread and does not have either <code>ReleaseParameters</code> or
101         *  <code>MemoryParameters</code>.
102         *
103         *  @param logic The <code>java.lang.Runnable</code> object whose
104         *               <code>run()</code> method is executed by
105         *               <code>handleAsyncEvent()</code>.
106         */
107        public AsyncEventHandler(Runnable logic) {
108            this();
109            this.logic = logic;
110        }
111    
112        /** Create an instance of <code>AsyncEventHandler</code> whose
113         *  parameters are inherited from the current thread, if the current
114         *  thread is a <code>RealtimeThread</code>, or null, otherwise.
115         *
116         *  @param lobic The <code>java.lang.Runnable</code> object whose
117         *               <code>run()</code> method is executed by
118         *               <code>handleAsyncEvent()</code>.
119         *  @param nonheap A flag meaning, when true, that this will have
120         *                 characteristics identical to a
121         *                 <code>NoHeapRealtimeThread</code>. A false value
122         *                 means this will have characteristics identical to a
123         *                 <code>RealtimeThread</code>. If true and the current
124         *                 thread is <i>not</i> a <code>NoHeapRealtimeThread</code>
125         *                 of a <code>RealtimeThread</code> executing within a
126         *                 <code>ScopedMemory</code> or <code>ImmortalMemory</code>
127         *                 scope then an <code>IllegalArgumentException<code> is thrown.
128         *  @throws java.lang.IllegalArgumentException If the initial memory area is
129         *                                             in heap memory, and the
130         *                                             <code>nonheap</code> parameter
131         *                                             is true.
132         */
133        public AsyncEventHandler(Runnable logic, boolean nonheap) {
134            this(nonheap);
135            this.logic = logic;
136        }
137    
138        /** Create an instance of <code>AsyncEventHandler</code> whose
139         *  parameters are inherited from the current thread, if the current
140         *  thread is a <code>RealtimeThread</code>, or null, otherwise.
141         *
142         *  @param scheduling A <code>SchedulingParameters</code> object which
143         *                    will be associated with the constructed instance.
144         *                    If null, <code>this</code> will be assigned the
145         *                    reference to the <code>SchedulingParameters</code>
146         *                    of the current thread.
147         *  @param release A <code>ReleaseParameters</code> obejct which will be
148         *                 associated with the constructed isntance. If null,
149         *                 <code>this</code> will have no <code>ReleaseParameters</code>.
150         *  @param memory A <code>MemoryParameters</code> object which will be
151         *                associated with the constructed intance. If null,
152         *                <code>this</code> will have no <code>MemoryParameters</code>.
153         *  @param area The <code>MemoryArea</code> for <code>this</code>. If null,
154         *              the memory area will be that of the current thread.
155         *  @param group A <code>ProcessingGroupParamters</code> object which
156         *               will be associated with the constructed instance. If null,
157         *               will not be associated with any processing group.
158         *  @param nonheap A flag meaning, when true, that this will have
159         *                 characteristics identical to a
160         *                 <code>NoHeapRealtimeThread</code>. A false value
161         *                 means this will have characteristics identical to a
162         *                 <code>RealtimeThread</code>. If true and the current
163         *                 thread is <i>not</i> a <code>NoHeapRealtimeThread</code>
164         *                 of a <code>RealtimeThread</code> executing within a
165         *                 <code>ScopedMemory</code> or <code>ImmortalMemory</code>
166         *                 scope then an <code>IllegalArgumentException<code> is thrown.
167         *  @throws java.lang.IllegalArgumentException If the initial memory area is
168         *                                             in heap memory, and the
169         *                                             <code>nonheap</code> parameter
170         *                                             is true.
171         */
172        public AsyncEventHandler(SchedulingParameters scheduling,
173                                 ReleaseParameters release,
174                                 MemoryParameters memory,
175                                 MemoryArea area,
176                                 ProcessingGroupParameters group,
177                                 boolean nonheap) {
178            this(nonheap);
179            this.scheduling = scheduling;
180            this.release = release;
181            this.memParams = memory;
182            this.memArea = area;
183            this.group = group;
184        }
185    
186        /** Create an instance of <code>AsyncEventHandler</code> whose
187         *  parameters are inherited from the current thread, if the current
188         *  thread is a <code>RealtimeThread</code>, or null, otherwise.
189         *
190         *  @param scheduling A <code>SchedulingParameters</code> object which
191         *                    will be associated with the constructed instance.
192         *                    If null, <code>this</code> will be assigned the
193         *                    reference to the <code>SchedulingParameters</code>
194         *                    of the current thread.
195         *  @param release A <code>ReleaseParameters</code> obejct which will be
196         *                 associated with the constructed isntance. If null,
197         *                 <code>this</code> will have no <code>ReleaseParameters</code>.
198         *  @param memory A <code>MemoryParameters</code> object which will be
199         *                associated with the constructed intance. If null,
200         *                <code>this</code> will have no <code>MemoryParameters</code>.
201         *  @param area The <code>MemoryArea</code> for <code>this</code>. If null,
202         *              the memory area will be that of the current thread.
203         *  @param group A <code>ProcessingGroupParamters</code> object which
204         *               will be associated with the constructed instance. If null,
205         *               will not be associated with any processing group.
206         *  @param logic The <code>java.lang.Runnable</code> object whose <code>run()</code>
207         *               method is executed by <code>handleAsyncEvent()</code>.
208         *  @throws java.lang.IllegalArgumentException If the initial memory area is
209         *                                             in heap memory, and the
210         *                                             <code>nonheap</code> parameter
211         *                                             is true.
212         */
213        public AsyncEventHandler(SchedulingParameters scheduling,
214                                 ReleaseParameters release,
215                                 MemoryParameters memory,
216                                 MemoryArea area,
217                                 ProcessingGroupParameters group,
218                                 Runnable logic) {
219            this(logic);
220            this.scheduling = scheduling;
221            this.release = release;
222            this.memParams = memory;
223            this.memArea = area;
224            this.group = group;
225        }
226    
227        /** Create an instance of <code>AsyncEventHandler</code> whose
228         *  parameters are inherited from the current thread, if the current
229         *  thread is a <code>RealtimeThread</code>, or null, otherwise.
230         *
231         *  @param scheduling A <code>SchedulingParameters</code> object which
232         *                    will be associated with the constructed instance.
233         *                    If null, <code>this</code> will be assigned the
234         *                    reference to the <code>SchedulingParameters</code>
235         *                    of the current thread.
236         *  @param release A <code>ReleaseParameters</code> obejct which will be
237         *                 associated with the constructed isntance. If null,
238         *                 <code>this</code> will have no <code>ReleaseParameters</code>.
239         *  @param memory A <code>MemoryParameters</code> object which will be
240         *                associated with the constructed intance. If null,
241         *                <code>this</code> will have no <code>MemoryParameters</code>.
242         *  @param area The <code>MemoryArea</code> for <code>this</code>. If null,
243         *              the memory area will be that of the current thread.
244         *  @param group A <code>ProcessingGroupParamters</code> object which
245         *               will be associated with the constructed instance. If null,
246         *               will not be associated with any processing group.
247         *  @param logic The <code>java.lang.Runnable</code> object whose <code>run()</code>
248         *               method is executed by <code>handleAsyncEvent()</code>.
249         *  @param nonheap A flag meaning, when true, that this will have
250         *                 characteristics identical to a
251         *                 <code>NoHeapRealtimeThread</code>. A false value
252         *                 means this will have characteristics identical to a
253         *                 <code>RealtimeThread</code>. If true and the current
254         *                 thread is <i>not</i> a <code>NoHeapRealtimeThread</code>
255         *                 of a <code>RealtimeThread</code> executing within a
256         *                 <code>ScopedMemory</code> or <code>ImmortalMemory</code>
257         *                 scope then an <code>IllegalArgumentException<code> is thrown.
258         *  @throws java.lang.IllegalArgumentException If the initial memory area is
259         *                                             in heap memory, and the
260         *                                             <code>nonheap</code> parameter
261         *                                             is true.
262         */
263        public AsyncEventHandler(SchedulingParameters scheduling,
264                                 ReleaseParameters release,
265                                 MemoryParameters memory,
266                                 MemoryArea area,
267                                 ProcessingGroupParameters group,
268                                 boolean nonheap, Runnable logic) {
269            this(scheduling, release, memory, area, group, logic);
270            this.nonheap = nonheap;
271            
272        }
273    
274        /** Inform the scheduler and cooperating facilities that the feasibility
275         *  parameters associated with <code>this</code> should be considered in
276         *  feasibility analyses until further notified, only if the new set of
277         *  parameters is feasible.
278         *
279         *  @return True if the additions is successful. False if the addition is
280         *          not successful or there is no assigned scheduler.
281         */
282        public boolean addIfFeasible() {
283            if ((currentScheduler == null) ||
284                (!currentScheduler.isFeasible(this, getReleaseParameters()))) return false;
285            else return addToFeasibility();
286        }
287    
288        /** Inform the scheduler and cooperating facilities that the feasibility
289         *  parameters associated with <code>this</code> should be considered in
290         *  feasibility analyses until further notified.
291         */
292        public boolean addToFeasibility() {
293            if (currentScheduler != null) {
294                currentScheduler.addToFeasibility(this);
295                return currentScheduler.isFeasible();
296            }
297            else return false;
298        }
299    
300        /** This is an accessor method for <code>fireCount</code>. This method
301         *  atomically sets the value of <code>fireCount</code> to zero and
302         *  returns the value from before it was set to zero. This may be used
303         *  by handlers for which the logic can accommodate multiple firings in
304         *  a single execution. The general form for using this is:
305         *  <p>
306         *  <code>
307         *  public void handleAsyncEvent() {
308         *      int numberOfFirings = getAndClearPendingFireCount();
309         *      <handle the events>
310         *  }
311         *  </code>
312         *
313         *  @return The value held by <code>fireCount</code> prior to setting
314         *          the value to zero.
315         */  
316        protected final int getAndClearPendingFireCount() {
317            int x = fireCount;
318            fireCount = 0;
319            return x;
320        }
321    
322        /** This is an accessor method for <code>fireCount</code>. This method
323         *  atomically decrements, by one, the value of <code>fireCount</code>
324         *  (if it was greater than zero) and returns the value from before
325         *  the decrement. This method can be used in the <code>handleAsyncEvent</code>
326         *  method to handle multiple firings:
327         *  <p>
328         *  <code>
329         *  public void handleAsyncEvent() {
330         *      <setup>
331         *      do {
332         *          <handle the events>
333         *      } while (getAndDecrementPendingFireCounts() > 0);
334         *  }
335         *  </code>
336         *  <p>
337         *  This construction is necessary only in the case where one wishes to
338         *  avoid the setup costs since the framework guarantees that
339         *  <code>handleAsyncEvent()</code> will be invoked the appropriate number of times.
340         *
341         *  @return The value held by <code>fireCount</code> prior to decrementing it by one.
342         */
343        protected int getAndDecrementPendingFireCount() {
344            if (fireCount > 0) return fireCount--;
345            else return 0;
346        }
347    
348        /** This is an accessor method for <code>fireCount</code>. This method
349         *  atomically increments, by one, the value of <code>fireCount</code>
350         *  and return the value from before the increment.
351         *
352         *  @return The value held by <code>fireCount</code> prior to incrementing it by one.
353         */
354        protected int getAndIncrementPendingFireCount() {
355            return fireCount++;
356        }
357    
358        /** This is an accessor method for the intance of <code>MemoryArea</code>
359         *  associated with <code>this</code>.
360         *
361         *  @return The instance of <code>MemoryArea</code> which is the current
362         *          area for <code>this</code>.
363         */
364        public MemoryArea getMemoryArea() {
365            return memArea;
366        }
367    
368        /** Gets the memory parameters associated with this instance of <code>Schedulable</code>.
369         *
370         *  @return The <code>MemoryParameters</code> object associated with <code>this</code>.
371         */
372        public MemoryParameters getMemoryParameters() {
373            return memParams;
374        }
375    
376        /** This is an accessor method for <code>fireCount</code>. The <code>fireCount</code>
377         *  field nominally holds the number of times associated instance of <code>AsyncEvent</code>
378         *  have occured that have not had the method <code>handleAsyncEvent()</code> invoked.
379         *  Due to accessor methods the pplication logic may manipulate the value in this field
380         *  for application specific reasons.
381         *
382         *  @return The value held by <code>fireCount</code>.
383         */
384        protected final int getPendingFireCount() {
385            return fireCount;
386        }
387    
388        /** Gets the processing group parameters associated with this intance of <code>Schedulable</code>.
389         *
390         *  @return The <code>ProcessingGroupParameters</code> object associated with <code>this</code>.
391         */
392        public ProcessingGroupParameters getProcessingGroupParameters() {
393            return group;
394        }
395    
396        /** Gets the release parameters associated with this instance of <code>Schedulable</code>.
397         *
398         *  @return The <code>ReleaseParameters</code> object associated with <code>this</code>.
399         */
400        public ReleaseParameters getReleaseParameters() {
401            return release;
402        }
403    
404        /** Gets the instance of <code>Scheduler</code> associated with this instance of <code>Schedulable</code>.
405         *
406         *  @return The instance of <code>Scheduler</code> associated with <code>this</code>.
407         */
408        public Scheduler getScheduler() {
409            return currentScheduler;
410        }
411    
412        /** Gets the scheduling parameters associated with this instance of <code>Schedulable</code>.
413         *
414         *  @return The <code>SchedulingParameters</code> object associated with <code>this</code>.
415         */
416        public SchedulingParameters getSchedulingParameters() {
417            return scheduling;
418        }
419    
420        /** This method holds the logic which is to be executed when assiciated instances of
421         *  <code>AsyncEvent</code> occur. If this handler was constructed using an instance of
422         *  <code>java.lang.Runnable</code> as an argument to the constructor, then that instance's
423         *  <code>run()</code> method will be invoked from this method. This method will be invoked
424         *  repreadedly while <code>fireCount</code> is greater than zero.
425         */
426        public void handleAsyncEvent() {
427            if (logic != null) logic.run();
428        }
429    
430        /** Inform the scheduler and cooperating facilities that the scheduling characteristics
431         *  of this instance of <code>Schedulable</code> should not  be considered in feasibility
432         *  analyses until further notified.
433         *
434         *  @return True, if the removal was successful. False, if the removal was unsuccessful.
435         */
436        public void removeFromFeasibility() {
437            if (currentScheduler != null)
438                currentScheduler.removeFromFeasibility(this);
439        }
440    
441        /** Used by the asynchronous event mechanism, see <code>AsyncEvent</code>.
442         *  This method invokes <code>handleAsyncEvent()</code> repeatedly while
443         *  fire count is greater than zero. Applications cannot override this
444         *  method and should thus override <code>handleAsyncEvent()</code> in
445         *  subclasses with the logic of the handler.
446         */
447        public final void run() {
448            while (getAndDecrementPendingFireCount() > 0)
449                handleAsyncEvent();
450        }   
451    
452        /** This method appears in many classes in the RTSJ and with various parameters.
453         *  The parameters are either new scheduling characteristics for an instance
454         *  <code>Schedulable</code> or an instance of <code>Schedulable</code>. The method
455         *  first performs a feasibility analysis using the new scheduling characteristics
456         *  as replacements for the matching scheduling characteristics of either
457         *  <code>this</code> or the given instance of <code>Schedulable</code>. If the
458         *  resulting system is feasible the method replaces the current scheduling
459         *  characteristics, of either <code>this</code> or the given instance of
460         *  <code>Schedulable</code> as appropriate, with the new scheduling characteristics.
461         *
462         *  @param release The proposed release parameters.
463         *  @param memory The proposed memory parameters.
464         *  @return True, if the resulting system is feasible and the changes are made.
465         *          False, if the resulting system is not feasible and no changes are made.
466         */
467        public boolean setIfFeasible(ReleaseParameters release,
468                                     MemoryParameters memory) {
469            return setIfFeasible(release, memory, getProcessingGroupParameters());
470        }
471    
472        /** This method appears in many classes in the RTSJ and with various parameters.
473         *  The parameters are either new scheduling characteristics for an instance
474         *  <code>Schedulable</code> or an instance of <code>Schedulable</code>. The method
475         *  first performs a feasibility analysis using the new scheduling characteristics
476         *  as replacements for the matching scheduling characteristics of either
477         *  <code>this</code> or the given instance of <code>Schedulable</code>. If the
478         *  resulting system is feasible the method replaces the current scheduling
479         *  characteristics, of either <code>this</code> or the given instance of
480         *  <code>Schedulable</code> as appropriate, with the new scheduling characteristics.
481         *
482         *  @param release The proposed release parameters.
483         *  @param memory The proposed memory parameters.
484         *  @param group The proposed processing group parameters.
485         *  @return True, if the resulting system is feasible and the changes are made.
486         *          False, if the resulting system is not feasible and no changes are made.
487         */
488        public boolean setIfFeasible(ReleaseParameters release,
489                                     MemoryParameters memory,
490                                     ProcessingGroupParameters group) {
491            if (currentScheduler == null) return false;
492            else return currentScheduler.setIfFeasible(this, release, memory, group);
493        }
494    
495        /** This method appears in many classes in the RTSJ and with various parameters.
496         *  The parameters are either new scheduling characteristics for an instance
497         *  <code>Schedulable</code> or an instance of <code>Schedulable</code>. The method
498         *  first performs a feasibility analysis using the new scheduling characteristics
499         *  as replacements for the matching scheduling characteristics of either
500         *  <code>this</code> or the given instance of <code>Schedulable</code>. If the
501         *  resulting system is feasible the method replaces the current scheduling
502         *  characteristics, of either <code>this</code> or the given instance of
503         *  <code>Schedulable</code> as appropriate, with the new scheduling characteristics.
504         *
505         *  @param release The proposed release parameters.
506         *  @param group The proposed processing group parameters.
507         *  @return True, if the resulting system is feasible and the changes are made.
508         *          False, if the resulting system is not feasible and no changes are made.
509         */
510        public boolean setIfFeasible(ReleaseParameters release,
511                                     ProcessingGroupParameters group) {
512            return setIfFeasible(release, getMemoryParameters(), group);
513        }
514    
515        /** Sets the memory parameters associated with this instance of <code>Schedulable</code>.
516         *  When is is next executed, that execution will use the new parameters to control memory
517         *  allocation. Does not affect the current invocation of the <code>run()</code> of this handler.
518         *
519         *  @param memory A <code>MemoryParameters</code> object which will become the memory
520         *                parameters associated with <code>this</code> after the method call.
521         */
522        public void setMemoryParameters(MemoryParameters memory) {
523            memParams = memory;
524        }
525    
526        /** The method first performs a feasibility analysis using the given memory parameters
527         *  as replacements for the memory parameters of <code>this</code>. If the resulting
528         *  system is feasible the method replaces the current memory parameters of
529         *  <code>this</code> with the new memory parameters.
530         *
531         *  @param memory The proposed memory parameters.
532         *  @return True, if the resulting system is feasible and the changes are made.
533         *          False, if the resulting system is not feasible and no changes are made.
534         */
535        public boolean setMemoryParametersIfFeasible(MemoryParameters memory) {
536            return setIfFeasible(getReleaseParameters(), memory,
537                                 getProcessingGroupParameters());
538        }
539    
540        /** Sets the processing group parameters associated with this instance of <code>Schedulable</code>.
541         *
542         *  @param parameters A <code>ProcessingGroupParameters</code> object which will become
543         *                    the processing group parameters associated with <code>this</code>
544         *                    after the method call.
545         */
546        public void setProcessingGroupParameters(ProcessingGroupParameters group) {
547            this.group = group;
548        }
549    
550        /** The method first performs a feasibility analysis using the given processing group
551         *  parameters as replacements for the processing group parameters of <code>this</code>.
552         *  If the resulting system is feasible the method replaces the current processing group
553         *  parameters of <code>this</code> with the new processing group parameters.
554         *
555         *  @param group The proposed processing group parameters.
556         *  @return True, if the resulting system is feasible and the changes are made.
557         *          False, if the resulting system is not feasible and no changes are made.
558         */
559        public boolean setProcessingGroupParametersIfFeasible(ProcessingGroupParameters group) {
560            return setIfFeasible(getReleaseParameters(),
561                                 getMemoryParameters(), group);
562        }
563    
564        /** Set the realease parameters associated with this instance of <code>Schedulable</code>.
565         *  When it is next executed, that execution will use the new parameters to control
566         *  scheduling. If the scheduling parameters of a handler is set to null, the handler will
567         *  be executed immediately when any associated <code>AsyncEvent</code> is fired, in the
568         *  context of the thread invoking the <code>fire()</code> method. Does not affect the
569         *  current invocation of the <code>run()</code> of this handler.
570         *  
571         *  @param release A <code>ReleaseParameters</code> object which will become the release
572         *                 parameters associated with this after the method call.
573         */
574        public void setReleaseParameters(ReleaseParameters release) {
575            this.release = release;
576        }
577    
578        /** The method first performs a feasibility analysis using the given release parameters
579         *  as replacements for the release parameters of <code>this</code>. If the resulting
580         *  system is feasible the method replaces the current release parameters of
581         *  <code>this</code> with the new release parameters.
582         *
583         *  @param release The proposed release parameters.
584         *  @return True, if the resulting system is feasible and the changes are made.
585         *          False, if the resulting system is not feasible and no changes are made.
586         */
587        public boolean setReleaseParametersIfFeasible(ReleaseParameters release) {
588            return setIfFeasible(release, getMemoryParameters(),
589                                 getProcessingGroupParameters());
590        }
591    
592        /** Sets the scheduler associated with this instance of <code>Schedulable</code>.
593         *
594         *  @param scheduler An instance of <code>Scheduler</code> which will manage the
595         *                   execution of this thread. If <code>scheduler</code> is null
596         *                   nothing happens.
597         *  @throws java.langIllegalThreadStateException
598         */
599        public void setScheduler(Scheduler scheduler)
600            throws IllegalThreadStateException {
601            setScheduler(scheduler, getSchedulingParameters(), getReleaseParameters(),
602                         getMemoryParameters(), getProcessingGroupParameters());
603        }
604    
605        /** Sets the scheduler associated with this instance of <code>Schedulable</code>.
606         *
607         *  @param scheduler An instance of <code>Scheduler</code> which will manage the
608         *                   execution of this thread. If <code>scheduler</code> is null
609         *                   nothing happens.
610         *  @param scheduling A <code>SchedulingParameters</code> object which will be
611         *                    associated with <code>this</code>. If null, <code>this</code>
612         *                    will be assigned the reference to the instance of
613         *                    <code>SchedulingParameters</code> of the current thread.
614         *  @param release A <code>ReleaseParameters</code> object which will be associated
615         *                 with <code>this</code>. If null, <code>this</code> will have no
616         *                 associated instance of <code>ReleaseParameters</code>.
617         *  @param memoryParameters A <code>MemoryParameters</code> object which will be
618         *                          associated with <code>this</code>. If null, <code>this</code>
619         *                          will have no associated instance of <code>MemoryParameters</code>.
620         *  @throws java.lang.IllegalThreadStateException
621         */
622        public void setScheduler(Scheduler scheduler,
623                                 SchedulingParameters scheduling,
624                                 ReleaseParameters release,
625                                 MemoryParameters memoryParameters,
626                                 ProcessingGroupParameters processingGroup)
627            throws IllegalThreadStateException {
628            currentScheduler = scheduler;
629            this.scheduling = scheduling;
630            this.release = release;
631            this.memParams = memoryParameters;
632            this.group = processingGroup;
633        }
634    
635        /** Sets the scheduling parameters associated with this instance of <code>Schedulable</code>.
636         *  When it is next executed, that execution will use the new parameters to control releases.
637         *  If the scheduling parameters of a handler is set to null, the handler will be executed
638         *  immediately when any associated <code>AsycnEvent</code> is fired, in the context of the
639         *  thread invoking the <code>fire()</code> method. Does not affect the current invocation of
640         *  the <code>run()</code> of this handler.
641         *
642         *  @param scheduling A <code>SchedulingParameters</code> object which will become the
643         *                    scheduling parameters associated with <code>this</code> after the method call.
644         */
645        public void setSchedulingParameters(SchedulingParameters scheduling) {
646            this.scheduling = scheduling;
647        }
648    
649        /** The method first performs a feasibility analysis using the given scheduling parameters as
650         *  replacements for the scheduling parameters of <code>this</code>. If the resulting system
651         *  is feasible the method replaces the current scheduling parameters of <code>this</code>
652         *  with new scheduling parameters.
653         *
654         *  @param scheduling The proposed scheduling parameters.
655         *  @return True, if the resulting system is feasible and the changes are made.
656         *          False, if the resulting system is not feasible and no changes are made.
657         */
658        public boolean setSchedulingParametersIfFeasible(SchedulingParameters scheduling) {
659            // How do scheduling parameters affect the feasibility of the task set?
660            this.scheduling = scheduling;
661            return true;
662    //      if (currentScheduler == null) return false;
663    //      SchedulingParameters old_scheduling = this.scheduling;
664    //      setSchedulingParameters(scheduling);
665    //      if (currentScheduler.isFeasible()) return true;
666    //      else {
667    //          setSchedulingParameters(old_scheduling);
668    //          return false;
669    //      }
670        }
671    
672        public long getUID() {
673            return myUID;
674        }
675    }