00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030  
00031 package org.objectweb.proactive.core.util;
00032 
00033 
00043 public class ThreadStoreImpl implements ThreadStore, java.io.Serializable {
00044     private int counter;
00045     private boolean defaultOpenState;
00046     private transient boolean open;
00047 
00051     public ThreadStoreImpl() {
00052         this(true);
00053     }
00054 
00059     public ThreadStoreImpl(boolean isOpened) {
00060         defaultOpenState = isOpened;
00061         open = defaultOpenState;
00062     }
00063 
00067     public int threadCount() {
00068         return counter;
00069     }
00070 
00074     public synchronized void enter() {
00075         while (!open) {
00076             try {
00077                 wait();
00078             } catch (InterruptedException e) {
00079             }
00080         }
00081         counter++;
00082     }
00083 
00087     public synchronized void exit() {
00088         counter--;
00089         notifyAll();
00090     }
00091 
00095     public synchronized void close() {
00096         open = false;
00097         while ((counter != 0) && !open) {
00098             try {
00099                 wait();
00100             } catch (InterruptedException e) {
00101             }
00102         }
00103     }
00104 
00108     public synchronized void open() {
00109         open = true;
00110         notifyAll();
00111     }
00112 
00113     
00114     
00115     
00116     private void writeObject(java.io.ObjectOutputStream out)
00117         throws java.io.IOException {
00118         out.defaultWriteObject();
00119     }
00120 
00121     private void readObject(java.io.ObjectInputStream in)
00122         throws java.io.IOException, ClassNotFoundException {
00123         in.defaultReadObject();
00124         
00125         open = defaultOpenState;
00126     }
00127 }