e8f9f81475eea23ffbd7eb97378ce0c1f6ff8c8b
[utils] / socketproxy / src / org / wamblee / socketproxy / Barrier.java
1 package org.wamblee.socketproxy; 
2
3 /**
4  * Copyright (c) 2005 UPS_SCS NL
5  * 
6  */
7
8 public class Barrier {
9
10     private int _countLeft;
11
12     public Barrier( int aCount ) {
13         _countLeft = aCount;
14     }
15
16     public synchronized void block( ) {
17         _countLeft--;
18         if ( _countLeft < 0 ) {
19             throw new IllegalStateException(
20                     "Barrier count became negative, programming error" );
21         }
22         notifyAll( );
23         while ( _countLeft > 0 ) {
24             waitUninterruptable( );
25         }
26     }
27
28     private void waitUninterruptable( ) {
29         try {
30             wait( );
31         } catch ( InterruptedException e ) {
32             // ignore.
33         }
34     }
35
36 }