1 8 package org.apache.avalon.excalibur.event; 9 10 import java.util.ArrayList ; 11 12 17 public abstract class AbstractQueue implements Queue 18 { 19 protected long m_timeout = 0; 20 21 24 public int canAccept() 25 { 26 return ( maxSize() > 0 ) ? maxSize() - size() : maxSize(); 27 } 28 29 32 public int maxSize() 33 { 34 return -1; 35 } 36 37 40 public boolean isFull() 41 { 42 return maxSize() - size() > 0; 43 } 44 45 48 public void setTimeout( final long millis ) 49 { 50 if ( millis > 0 ) 51 { 52 m_timeout = millis; 53 } 54 else 55 { 56 m_timeout = 0; 57 } 58 } 59 60 protected void block( Object lock ) 61 { 62 if ( m_timeout > 0 ) 63 { 64 long start = System.currentTimeMillis(); 65 long end = start + m_timeout; 66 67 while ( start < end || size() > 0 ) 68 { 69 try 70 { 71 lock.wait( m_timeout ); 72 } 73 catch ( InterruptedException ie ) 74 { 75 } 77 } 78 } 79 } 80 } 81 | Popular Tags |