Coverage Report - net.wotonomy.foundation.NSLock
 
Classes in this File Line Coverage Branch Coverage Complexity
NSLock
0% 
0% 
1.375
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2002 Israfil consulting Services Corporation
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, see http://www.gnu.org
 17  
 
 18  
 $Id: NSLock.java 893 2006-02-16 13:22:23 +0000 (Thu, 16 Feb 2006) cgruber $
 19  
 
 20  
 */
 21  
 
 22  
 package net.wotonomy.foundation;
 23  
 
 24  
 import EDU.oswego.cs.dl.util.concurrent.Mutex;
 25  
 
 26  
 /**
 27  
 * A simple mutually-exclusive lock. Currently an API-compliance 
 28  
 * subclass of an external Mutex class, conforming to the API and 
 29  
 * behavior of com.webobjects.foundation.NSLock.  This class implements
 30  
 * the NSLocking protocol (interface), and is implemented using 
 31  
 * Doug Lea's concurrent programming package.  
 32  
 *
 33  
 * @author cgruber@israfil.net
 34  
 * @author $Author: cgruber $
 35  
 * @version $Revision: 893 $
 36  
 * 
 37  
 */
 38  
 
 39  
 public class NSLock extends Mutex implements NSLocking {
 40  
 
 41  
 
 42  0
     public NSLock() {
 43  0
     }
 44  
 
 45  
     public synchronized void lock() {
 46  
         try {
 47  0
             acquire();
 48  0
         } catch (InterruptedException interruptedexception) {
 49  0
             notify();
 50  0
         }
 51  0
     }
 52  
 
 53  
     public synchronized void unlock() {
 54  0
         release();
 55  0
     }
 56  
 
 57  
     public synchronized boolean tryLock() {
 58  0
         return tryLock(0);
 59  
     }
 60  
 
 61  
     public synchronized boolean tryLock(long l) {
 62  
         try {
 63  0
             return attempt(l);
 64  0
         } catch (InterruptedException interruptedexception) {
 65  0
             notify();
 66  0
             return false;
 67  
         }
 68  
     }
 69  
 
 70  
     public boolean tryLock(NSTimestamp nstimestamp) {
 71  0
         return tryLock(nstimestamp.getTime() - System.currentTimeMillis());
 72  
     }
 73  
 
 74  
     public String toString() {
 75  0
                 return getClass().getName() + " <" + (inuse_ ? "Locked" : "Unlocked") + ">";
 76  
     }
 77  
 
 78  
     public synchronized boolean isLocked() {
 79  0
                 return inuse_;
 80  
     }
 81  
 
 82  
 }
 83  
 
 84  
 /*
 85  
  * $Log$
 86  
  * Revision 1.2  2006/02/16 13:15:00  cgruber
 87  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 88  
  *
 89  
  * Revision 1.1  2002/07/14 21:56:16  mpowers
 90  
  * Contributions from cgruber.
 91  
  *
 92  
  * Revision 1.4  2002/06/25 19:03:02  cgruber
 93  
  * Internal documentation fixes.
 94  
  *
 95  
  * Revision 1.3  2002/06/25 18:52:56  cgruber
 96  
  * Fix javadocs that resulted from bad cut-and-paste of the 
 97  
  * boilerplate.
 98  
  *
 99  
  * Revision 1.2  2002/06/25 17:45:52  cgruber
 100  
  * Add implementation of NSLock using Doug Lea's concurrent 
 101  
  * programming APIs.
 102  
  *
 103  
  * Revision 1.1  2002/06/25 07:52:57  cgruber
 104  
  * Add quite a few abstract classes, interfaces, and classes.  All 
 105  
  * API consistent with WebObjects, but with no implementation, nor 
 106  
  * any private or package access members from the original.
 107  
  *
 108  
  */