Java Doc for FileLock.java in  » Apache-Harmony-Java-SE » java-package » java » nio » channels » 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 » Apache Harmony Java SE » java package » java.nio.channels 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.nio.channels.FileLock

FileLock
abstract public class FileLock (Code)
A FileLock represents a locked region of a file.

Locks have certain properties that enable collaborating processes to avoid the lost update problem, or reading inconsistent data.

logically, a file lock can be 'exclusive' or 'shared'. Multiple processes can hold shared locks on the same region of a file, but only a single process can hold an exclusive lock on a given region of a file and no other process can simultaneously hold a shared lock overlapping the exclusive lock. An application can determine whether a FileLock is shared or exclusive via the isShared() API.

Locks held by a particular process cannot overlap one another. Applications can determine whether a proposed lock will overlap by using the overlaps(long, long)

Locks are shared amongst all threads in the acquiring process, and are therefore unsuitable for intra-process synchronization.

Once a lock is acquired it is immutable in all its state except isValid(). The lock will initially be valid, but may be rendered invalid by explicit removal of the lock, using release(), or implicitly by closing the channel or exiting the process (terminating the JVM).

Platform dependencies

Locks are intended to be true platform operating system file locks, and therefore locks held by the JVM process will be visible to other OS processes.

The characteristics of the underlying OS locks will show through in the Java implementation. For example, some platforms' locks are 'mandatory' -- meaning the operating system enforces the locks on processes that attempt to access locked regions of file; whereas other platforms' locks are only 'advisory' -- meaning that processes are required to collaborate on ensuring locks are acquired and there is a potential for processes not to play well. The only safe answer is to assume that the platform is adopting advisory locks an always acquire shared locks when reading a region of file.

On some platforms the presence of a lock will prevent the file being memory mapped. On some platforms closing a channel on a given file handle will release all the locks held on that file -- even if there are other channels open on the same file (their locks will be released). The safe option here is to ensure that you only acquire locks on a single channel for a particular file, and that becomes the synchronization point.

Further care should be exercised when locking files maintained on network file systems since they often have further limitations.




Constructor Summary
protected  FileLock(FileChannel channel, long position, long size, boolean shared)
     Constructor for a new file lock instance for a given channel.

Method Summary
final public  FileChannelchannel()
     Answers the lock's FileChannel.
final public  booleanisShared()
     Answers true if the file lock is shared with other processes and false if it is not.
abstract public  booleanisValid()
     Answers whether the receiver is a valid file lock or not.
final public  booleanoverlaps(long start, long length)
     Answers true if the receiver's lock region overlapps the region described in the parameter list,and answers false otherwise.
Parameters:
  start - the starting position for the comparative lock.
Parameters:
  length - the length of the comparative lock.
final public  longposition()
     Answers the lock's starting position in the file.
abstract public  voidrelease()
     Releases this particular lock on the file.
final public  longsize()
     Answers the length of the file lock in bytes.
final public  StringtoString()
     Answers a string that shows the details of the lock suitable for display to an end user.


Constructor Detail
FileLock
protected FileLock(FileChannel channel, long position, long size, boolean shared)(Code)
Constructor for a new file lock instance for a given channel. The constructor enforces the starting position, stretch, and shared status of the lock.
Parameters:
  channel - underlying file channel that holds the lock.
Parameters:
  position - starting point for the lock.
Parameters:
  size - length of lock in number of bytes.
Parameters:
  shared - shared status of lock (true is shared, false is exclusive).




Method Detail
channel
final public FileChannel channel()(Code)
Answers the lock's FileChannel. the channel.



isShared
final public boolean isShared()(Code)
Answers true if the file lock is shared with other processes and false if it is not. true if the lock is a shared lock, and false if it is exclusive.



isValid
abstract public boolean isValid()(Code)
Answers whether the receiver is a valid file lock or not. The lock is valid unless the underlying channel has been closed or it has been explicitly released. true if the lock is valid, and false otherwise.



overlaps
final public boolean overlaps(long start, long length)(Code)
Answers true if the receiver's lock region overlapps the region described in the parameter list,and answers false otherwise.
Parameters:
  start - the starting position for the comparative lock.
Parameters:
  length - the length of the comparative lock. true if there is an overlap, and false otherwise.



position
final public long position()(Code)
Answers the lock's starting position in the file. the lock position.



release
abstract public void release() throws IOException(Code)
Releases this particular lock on the file. If the lock is invalid then this method has no effect. Once released the lock becomes invalid.
throws:
  ClosedChannelException - if the channel is already closed when an attempt to releasethe lock is made.
throws:
  IOException - some other IO exception occurred.



size
final public long size()(Code)
Answers the length of the file lock in bytes. the size of file lock in bytes.



toString
final public String toString()(Code)
Answers a string that shows the details of the lock suitable for display to an end user. the display string.



Methods inherited from java.lang.Object
protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object object)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final public Class<? extends Object> getClass()(Code)(Java Doc)
public int hashCode()(Code)(Java Doc)
final public void notify()(Code)(Java Doc)
final public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final public void wait(long millis, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait(long millis) 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.