Java Doc for GenericLock.java in  » Database-JDBC-Connection-Pool » Apache-commons-transaction-1.2 » org » apache » commons » transaction » locking » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » Apache commons transaction 1.2 » org.apache.commons.transaction.locking 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.transaction.locking.GenericLock

All known Subclasses:   org.apache.commons.transaction.locking.ReadWriteLock,  org.apache.commons.transaction.locking.ReadWriteUpgradeLock,
GenericLock
public class GenericLock implements MultiLevelLock2(Code)
A generic implementain of a simple multi level lock.

The idea is to have an ascending number of lock levels ranging from 0 to maxLockLevel as specified in GenericLock.GenericLock(Object,int,LoggerFacade) : the higher the lock level the stronger and more restrictive the lock. To determine which lock may coexist with other locks you have to imagine matching pairs of lock levels. For each pair both parts allow for all lock levels less than or equal to the matching other part. Pairs are composed by the lowest and highest level not yet part of a pair and successively applying this method until no lock level is left. For an even amount of levels each level is part of exactly one pair. For an odd amount the middle level is paired with itself. The highst lock level may coexist with the lowest one (0) which by definition means NO LOCK. This implies that you will have to specify at least one other lock level and thus set maxLockLevel to at least 1.

Although this may sound complicated, in practice this is quite simple. Let us imagine you have three lock levels:

  • 0:NO LOCK (always needed by the implementation of this lock)
  • 1:SHARED
  • 2:EXCLUSIVE
Accordingly, you will have to set maxLockLevel to 2. Now, there are two pairs of levels
  • NO LOCK with EXCLUSIVE
  • SHARED with SHARED
This means when the current highest lock level is NO LOCK everything less or equal to EXCLUSIVE is allowed - which means every other lock level. On the other side EXCLUSIVE allows exacly for NO LOCK- which means nothing else. In conclusion, SHARED allows for SHARED or NO LOCK, but not for EXCLUSIVE. To make this very clear have a look at this table, where o means compatible or can coexist and x means incompatible or can not coexist:

NO LOCK SHARED EXCLUSIVE
NO LOCK o o o
SHARED o o x
EXCLUSIVE o x x

Additionally, there are preferences for specific locks you can pass to GenericLock.acquire(Object,int,boolean,int,boolean,long) . This means whenever more thanone party waits for a lock you can specify which one is to be preferred. This gives you every freedom you might need to specifcy e.g.

  • priority to parties either applying for higher or lower lock levels
  • priority not only to higher or lower locks, but to a specific level
  • completely random preferences


version:
   $Id: GenericLock.java 493628 2007-01-07 01:42:48Z joerg $

Inner Class :protected static class LockOwner

Field Summary
protected  LoggerFacadelogger
    
protected  Mapowners
    
protected  ObjectresourceId
    
protected  intwaiters
    
protected  ListwaitingOwners
    

Constructor Summary
public  GenericLock(Object resourceId, int maxLockLevel, LoggerFacade logger)
     Creates a new lock.

Method Summary
public synchronized  booleanacquire(Object ownerId, int targetLockLevel, boolean wait, boolean reentrant, long timeoutMSecs)
    
public synchronized  booleanacquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, long timeoutMSecs)
    
public synchronized  booleanacquire(Object ownerId, int targetLockLevel, boolean preferred, long timeoutMSecs)
     Tries to blockingly acquire a lock which can be preferred.
public synchronized  booleanacquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, boolean preferred, long timeoutMSecs)
    
public  booleanequals(Object o)
    
protected  SetgetConflictingOwners(Object ownerId, int targetLockLevel, int compatibility)
    
protected  SetgetConflictingOwners(LockOwner myOwner, Collection ownersToTest)
    
protected  CollectiongetConflictingWaiters(Object ownerId)
    
public  intgetLevelMaxLock()
     Gets the highst lock level possible.
public  intgetLevelMinLock()
     Gets the lowest lock level possible.
public  intgetLockLevel(Object ownerId)
    
protected synchronized  LockOwnergetMaxLevelOwner()
    
protected synchronized  LockOwnergetMaxLevelOwner(LockOwner reentrantOwner, boolean preferred)
    
protected synchronized  LockOwnergetMaxLevelOwner(int supportLockLevel, boolean preferred)
    
protected synchronized  LockOwnergetMaxLevelOwner(LockOwner reentrantOwner, int supportLockLevel, boolean preferred)
    
public  ObjectgetOwner()
    
public  ObjectgetResourceId()
     Gets the resource assotiated to this lock.
public  booleanhas(Object ownerId, int lockLevel)
    
public  inthashCode()
    
protected  booleanisCompatible(int targetLockLevel, int currentLockLevel)
    
protected  voidregisterWaiter(LockOwner waitingOwner)
    
public synchronized  booleanrelease(Object ownerId)
    
protected synchronized  voidsetLockLevel(Object ownerId, LockOwner lock, int targetLockLevel, int compatibility, boolean intention)
    
public  booleantest(Object ownerId, int targetLockLevel, int compatibility)
    
public synchronized  StringtoString()
    
protected  booleantryLock(Object ownerId, int targetLockLevel, int compatibility, boolean preferred)
    
protected synchronized  booleantryLock(Object ownerId, int targetLockLevel, int compatibility, boolean preferred, boolean tryOnly)
    
protected  voidunregisterWaiter(LockOwner waitingOwner)
    

Field Detail
logger
protected LoggerFacade logger(Code)



owners
protected Map owners(Code)



resourceId
protected Object resourceId(Code)



waiters
protected int waiters(Code)



waitingOwners
protected List waitingOwners(Code)




Constructor Detail
GenericLock
public GenericLock(Object resourceId, int maxLockLevel, LoggerFacade logger)(Code)
Creates a new lock.
Parameters:
  resourceId - identifier for the resource associated to this lock
Parameters:
  maxLockLevel - highest allowed lock level as described in class intro
Parameters:
  logger - generic logger used for all kind of debug logging




Method Detail
acquire
public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, boolean reentrant, long timeoutMSecs) throws InterruptedException(Code)

See Also:   org.apache.commons.transaction.locking.MultiLevelLock.acquire(java.lang.Objectintbooleanbooleanlong)



acquire
public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, long timeoutMSecs) throws InterruptedException(Code)

See Also:   GenericLock.acquire(Object,int,boolean,int,boolean,long)



acquire
public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean preferred, long timeoutMSecs) throws InterruptedException(Code)
Tries to blockingly acquire a lock which can be preferred.
See Also:   GenericLock.acquire(Object,int,boolean,int,boolean,long)
See Also:   
since:
   1.1



acquire
public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, boolean preferred, long timeoutMSecs) throws InterruptedException(Code)

See Also:   org.apache.commons.transaction.locking.MultiLevelLock2.acquire(Objectintbooleanintbooleanlong)
since:
   1.1



equals
public boolean equals(Object o)(Code)



getConflictingOwners
protected Set getConflictingOwners(Object ownerId, int targetLockLevel, int compatibility)(Code)



getConflictingOwners
protected Set getConflictingOwners(LockOwner myOwner, Collection ownersToTest)(Code)



getConflictingWaiters
protected Collection getConflictingWaiters(Object ownerId)(Code)



getLevelMaxLock
public int getLevelMaxLock()(Code)
Gets the highst lock level possible. maximum lock level



getLevelMinLock
public int getLevelMinLock()(Code)
Gets the lowest lock level possible. minimum lock level



getLockLevel
public int getLockLevel(Object ownerId)(Code)

See Also:   org.apache.commons.transaction.locking.MultiLevelLock.getLockLevel(Object)



getMaxLevelOwner
protected synchronized LockOwner getMaxLevelOwner()(Code)



getMaxLevelOwner
protected synchronized LockOwner getMaxLevelOwner(LockOwner reentrantOwner, boolean preferred)(Code)



getMaxLevelOwner
protected synchronized LockOwner getMaxLevelOwner(int supportLockLevel, boolean preferred)(Code)



getMaxLevelOwner
protected synchronized LockOwner getMaxLevelOwner(LockOwner reentrantOwner, int supportLockLevel, boolean preferred)(Code)



getOwner
public Object getOwner()(Code)



getResourceId
public Object getResourceId()(Code)
Gets the resource assotiated to this lock. identifier for the resource associated to this lock



has
public boolean has(Object ownerId, int lockLevel)(Code)

See Also:   MultiLevelLock2.has(Objectint)



hashCode
public int hashCode()(Code)



isCompatible
protected boolean isCompatible(int targetLockLevel, int currentLockLevel)(Code)



registerWaiter
protected void registerWaiter(LockOwner waitingOwner)(Code)



release
public synchronized boolean release(Object ownerId)(Code)

See Also:   org.apache.commons.transaction.locking.MultiLevelLock.release(Object)



setLockLevel
protected synchronized void setLockLevel(Object ownerId, LockOwner lock, int targetLockLevel, int compatibility, boolean intention)(Code)



test
public boolean test(Object ownerId, int targetLockLevel, int compatibility)(Code)

See Also:   MultiLevelLock2.test(Objectintint)



toString
public synchronized String toString()(Code)



tryLock
protected boolean tryLock(Object ownerId, int targetLockLevel, int compatibility, boolean preferred)(Code)



tryLock
protected synchronized boolean tryLock(Object ownerId, int targetLockLevel, int compatibility, boolean preferred, boolean tryOnly)(Code)



unregisterWaiter
protected void unregisterWaiter(LockOwner waitingOwner)(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.