1 /* 2 * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP 3 * [See end of file] 4 */ 5 6 /** 7 * A model lock. 8 * Critical section support for multithreaed access to a model 9 * within a single JVM. See also transactions support. 10 * 11 * Examples if application code: 12 * <pre> 13 * try { 14 * model.enterCriticalSection(ModelLock.READ) ; 15 * ... 16 * } finally { model.leaveCriticalSection() ; } 17 * </pre> 18 * 19 * Nested locks are provided for: 20 * <pre> 21 * try { 22 * model.enterCriticalSection(ModelLock.WRITE) ; 23 * libraryCall() ; 24 * ... 25 * } finally { model.leaveCriticalSection() ; } 26 * 27 * void libraryCall() 28 * { 29 * try { 30 * model.enterCriticalSection(ModelLock.READ) ; 31 * ... do library stuff ... 32 * } finally { model.leaveCriticalSection() ; } 33 * } 34 * </pre> 35 * Iterators should be used inside a critical section and not passed outside 36 * the concurrency controlled block. 37 * <pre> 38 * try { 39 * model.enterCriticalSection(ModelLock.READ) ; 40 * StmtIterator sIter = ... ; 41 * for ( ; sIter.next; ) 42 * { 43 * ... 44 * } 45 * sIter.close() ; 46 * } finally { model.leaveCriticalSection() ; } 47 * </pre> 48 * 49 * Note that if a library operation needs a write lock, the application must either have no 50 * locks or a write lock when calling. Lock promotion is not supported - it can lead to 51 * deadlock. 52 * 53 * The hard work of locking is done by the 54 * <a HREF="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html">util.concurrent</a>. 55 * This is a convenience wrapper that provides nested locks, a special case of reentrant locks, 56 * that does some checking. 57 * 58 * @author Andy Seaborne 59 * @version $Id: ModelLock.java,v 1.4 2005/02/21 12:14:09 andy_seaborne Exp $ 60 */ 61 62 63 package com.hp.hpl.jena.rdf.model ; 64 65 public interface ModelLock 66 { 67 /** Descriptive name for lock requests - read lock */ 68 public static final boolean READ = true ; 69 70 /** Descriptive name for lock requests - write lock */ 71 public static final boolean WRITE = false ; 72 73 74 /** Enter a critical section. 75 * The application must call leaveCriticialSection. 76 * @see #leaveCriticalSection 77 * 78 * @param readLockRequested true implies a read lock,false implies write lock. 79 */ 80 81 public void enterCriticalSection(boolean readLockRequested) ; 82 83 /** Leave a critical section. Releases the lock form the matching enterCriticalSection 84 * @see #enterCriticalSection 85 */ 86 87 public void leaveCriticalSection() ; 88 } 89 90 91 /* 92 * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP 93 * All rights reserved. 94 * 95 * Redistribution and use in source and binary forms, with or without 96 * modification, are permitted provided that the following conditions 97 * are met: 98 * 1. Redistributions of source code must retain the above copyright 99 * notice, this list of conditions and the following disclaimer. 100 * 2. Redistributions in binary form must reproduce the above copyright 101 * notice, this list of conditions and the following disclaimer in the 102 * documentation and/or other materials provided with the distribution. 103 * 3. The name of the author may not be used to endorse or promote products 104 * derived from this software without specific prior written permission. 105 * 106 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 107 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 108 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 109 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 110 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 111 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 112 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 113 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 114 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 115 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 116 */ 117 118