001 package javax.realtime; 002 003 /** A bound asynchronous event handler is an asynchronous event handler 004 * that is permanently bound to a thread. Bound asynchronous event 005 * handlers are meant for use in situations where the added timeliness 006 * is worth the overhead of binding the handler to a thread. 007 */ 008 public abstract class BoundAsyncEventHandler extends AsyncEventHandler { 009 010 protected boolean nonHeap = false; 011 protected Runnable logic = null; 012 013 protected SchedulingParameters scheduling; 014 protected ReleaseParameters release; 015 protected MemoryParameters memory; 016 protected ProcessingGroupParameters group; 017 protected MemoryArea area; 018 019 /** Create a handler whose parameters are inherited from the current 020 * thread, if it is a <code>RealtimeThread</code>, or null otherwise. 021 */ 022 public BoundAsyncEventHandler() { 023 if (Thread.currentThread() instanceof RealtimeThread) { 024 RealtimeThread t = RealtimeThread.currentRealtimeThread(); 025 scheduling = t.getSchedulingParameters(); 026 release = t.getReleaseParameters(); 027 memory = t.getMemoryParameters(); 028 group = t.getProcessingGroupParameters(); 029 area = t.getMemoryArea(); 030 } 031 else { 032 scheduling = null; 033 release = null; 034 memory = null; 035 group = null; 036 area = null; 037 } 038 } 039 040 /** Create a handler with the specified parameters. 041 * 042 * @param scheduling A <code>SchedulingParameters</code> object which will be 043 * associated with the constructed instance. If null, 044 * <code>this</code> will be assigned the reference to the 045 * <code>SchedulingParameters</code> of the current thread. 046 * @param release A <code>ReleaseParameters</code> object which will be associated 047 * with the contructed instance. If null, <code>this</code> will 048 * have no <code>ReleaseParameters</code>. 049 * @param memory A <code>MemoryParameters</code> object which will be associated 050 * with the constructed instance. If null, <code>this</code> will 051 * have no <code>MemoryParameters</code>. 052 * @param area The <code>MemoryArea</code> for <code>this</code>. If null, the 053 * memory area will be that of the current thread. 054 * @param group A <code>ProcessingGroupParameters</code> object which will be 055 * associated with the constructed instance. If null, <code>this</code> 056 * will not be associated with any processing group. 057 * @param nonheap A flag meaning, when true, that this will have characteristics 058 * identical to a <code>NoHeapRealtimeThread</code>. A false value 059 * means this will have characteristics identical to a 060 * <code>RealtimeThread</code>. If true and the current thread is 061 * <i>not</i> a <code>NoHeapRealtimeThread</code> or a 062 * <code>RealtimeThread</code> executing within a <code>ScopedMemory</code> 063 * or <code>ImmortalMemory</code> scope then an 064 * <code>IllegalArgumentException</code> is thrown. 065 * @param logic The <code>java.lang.Runnable</code> object whose <code>run()</code> 066 * method is executed by <code>AsyncEventHandler.handleAsyncEvent()</code>. 067 * @throws java.lang.IllegalArgumentException If the initial memory area is in heap 068 * memory, and the <code>nonheap</code> 069 * parameter is true. 070 */ 071 public BoundAsyncEventHandler(SchedulingParameters scheduling, 072 ReleaseParameters release, 073 MemoryParameters memory, 074 MemoryArea area, 075 ProcessingGroupParameters group, 076 boolean nonheap, Runnable logic) { 077 this.scheduling = scheduling; 078 this.release = release; 079 this.memParams = memory; 080 this.group = group; 081 this.memArea = area; 082 this.nonHeap = nonHeap; 083 this.logic = logic; 084 } 085 }