1 17 package org.alfresco.filesys.locking; 18 19 24 public class FileLock 25 { 26 27 29 public static final long LockWholeFile = 0xFFFFFFFFFFFFFFFFL; 30 31 33 private long m_offset; 34 private long m_length; 35 36 38 private int m_pid; 39 40 47 public FileLock(long offset, long len, int pid) 48 { 49 setOffset(offset); 50 setLength(len); 51 setProcessId(pid); 52 } 53 54 59 public final long getOffset() 60 { 61 return m_offset; 62 } 63 64 69 public final void setOffset(long offset) 70 { 71 m_offset = offset; 72 } 73 74 79 public final long getLength() 80 { 81 return m_length; 82 } 83 84 89 public final void setLength(long len) 90 { 91 if (len < 0) 92 m_length = LockWholeFile; 93 else 94 m_length = len; 95 } 96 97 102 public final int getProcessId() 103 { 104 return m_pid; 105 } 106 107 112 public final boolean isWholeFile() 113 { 114 return m_length == LockWholeFile ? true : false; 115 } 116 117 122 public final void setProcessId(int pid) 123 { 124 m_pid = pid; 125 } 126 127 132 public final boolean hasOverlap(FileLock lock) 133 { 134 return hasOverlap(lock.getOffset(), lock.getLength()); 135 } 136 137 143 public final boolean hasOverlap(long offset, long len) 144 { 145 146 148 if (isWholeFile()) 149 return true; 150 151 153 long endOff = getOffset() + getLength(); 154 155 if (getOffset() < offset && endOff < offset) 156 return false; 157 158 endOff = offset + len; 159 160 if (getOffset() > endOff) 161 return false; 162 163 165 return true; 166 } 167 168 173 public String toString() 174 { 175 StringBuffer str = new StringBuffer (); 176 177 str.append("[PID="); 178 str.append(getProcessId()); 179 str.append(",Offset="); 180 str.append(getOffset()); 181 str.append(",Len="); 182 str.append(getLength()); 183 str.append("]"); 184 185 return str.toString(); 186 } 187 } | Popular Tags |