org/objectweb/proactive/core/util/ThreadStoreImpl.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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     // -- PRIVATE METHODS -----------------------------------------------
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         // set open to the default value
00125         open = defaultOpenState;
00126     }
00127 }

Generated on Mon Jan 22 15:16:10 2007 for ProActive by  doxygen 1.5.1