diff options
| author | Benjamin Culkin <scorpress@gmail.com> | 2024-05-19 17:56:33 -0400 |
|---|---|---|
| committer | Benjamin Culkin <scorpress@gmail.com> | 2024-05-19 17:56:33 -0400 |
| commit | aedc34d55462a75e329bbf342251ff6504cd117e (patch) | |
| tree | bcc8f1f2352582717b484df302aeea6696b8f000 /projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSLock.java | |
Initial import from SVN
Diffstat (limited to 'projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSLock.java')
| -rw-r--r-- | projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSLock.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSLock.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSLock.java new file mode 100644 index 0000000..e6a5147 --- /dev/null +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSLock.java @@ -0,0 +1,108 @@ +/* +Wotonomy: OpenStep design patterns for pure Java applications. +Copyright (C) 2002 Israfil consulting Services Corporation + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, see http://www.gnu.org + +$Id: NSLock.java 893 2006-02-16 13:22:23Z cgruber $ + +*/ + +package net.wotonomy.foundation; + +import EDU.oswego.cs.dl.util.concurrent.Mutex; + +/** +* A simple mutually-exclusive lock. Currently an API-compliance +* subclass of an external Mutex class, conforming to the API and +* behavior of com.webobjects.foundation.NSLock. This class implements +* the NSLocking protocol (interface), and is implemented using +* Doug Lea's concurrent programming package. +* +* @author cgruber@israfil.net +* @author $Author: cgruber $ +* @version $Revision: 893 $ +* +*/ + +public class NSLock extends Mutex implements NSLocking { + + + public NSLock() { + } + + public synchronized void lock() { + try { + acquire(); + } catch (InterruptedException interruptedexception) { + notify(); + } + } + + public synchronized void unlock() { + release(); + } + + public synchronized boolean tryLock() { + return tryLock(0); + } + + public synchronized boolean tryLock(long l) { + try { + return attempt(l); + } catch (InterruptedException interruptedexception) { + notify(); + return false; + } + } + + public boolean tryLock(NSTimestamp nstimestamp) { + return tryLock(nstimestamp.getTime() - System.currentTimeMillis()); + } + + public String toString() { + return getClass().getName() + " <" + (inuse_ ? "Locked" : "Unlocked") + ">"; + } + + public synchronized boolean isLocked() { + return inuse_; + } + +} + +/* + * $Log$ + * Revision 1.2 2006/02/16 13:15:00 cgruber + * Check in all sources in eclipse-friendly maven-enabled packages. + * + * Revision 1.1 2002/07/14 21:56:16 mpowers + * Contributions from cgruber. + * + * Revision 1.4 2002/06/25 19:03:02 cgruber + * Internal documentation fixes. + * + * Revision 1.3 2002/06/25 18:52:56 cgruber + * Fix javadocs that resulted from bad cut-and-paste of the + * boilerplate. + * + * Revision 1.2 2002/06/25 17:45:52 cgruber + * Add implementation of NSLock using Doug Lea's concurrent + * programming APIs. + * + * Revision 1.1 2002/06/25 07:52:57 cgruber + * Add quite a few abstract classes, interfaces, and classes. All + * API consistent with WebObjects, but with no implementation, nor + * any private or package access members from the original. + * + */ |
