1 50 package org.apache.avalon.excalibur.concurrent; 51 52 67 public class ConditionalEvent 68 { 69 private boolean m_state = false; 70 private boolean m_autoReset = false; 71 72 76 82 public ConditionalEvent( boolean initialState ) 83 { 84 m_state = initialState; 85 } 86 87 94 public ConditionalEvent( boolean initialState, boolean autoReset ) 95 { 96 m_state = initialState; 97 m_autoReset = autoReset; 98 } 99 100 106 public boolean isSignalled() 107 { 108 return m_state; 109 } 110 111 117 public void signal() 118 { 119 synchronized( this ) 120 { 121 m_state = true; 122 notify(); 123 } 124 } 125 126 132 public void signalAll() 133 { 134 synchronized( this ) 135 { 136 m_state = true; 137 notifyAll(); 138 } 139 } 140 141 144 public void reset() 145 { 146 synchronized( this ) 147 { 148 m_state = false; 149 } 150 } 151 152 158 public void waitForSignal() 159 throws InterruptedException 160 { 161 synchronized( this ) 162 { 163 while( !m_state ) 164 { 165 wait(); 166 } 167 if( m_autoReset ) 168 { 169 m_state = false; 170 } 171 } 172 } 173 } 174 | Popular Tags |