public synchronized FileLock lock() throws IOException { if (lock != null) { FileLock f = (FileLock) lock.get(); if (f != null) { FileAlreadyLockedException alreadyLockedException = new FileAlreadyLockedException(getPath()); alreadyLockedException.initCause(lockedBy); throw alreadyLockedException; } } Set<? extends FileSystem> set = getMultiFileSystem().createLocksOn(getPath()); MfLock l = new MfLock(leader, delegates(), set); lock = new WeakReference<MfLock>(l); assert (lockedBy = new Throwable("Locked by:")) != null; //NOI18N return l; }
/** Releases lock for old file object and * takes new one from newFo */ public void changeLocks(FileObject old, FileObject n) throws IOException { FileLock l = map.remove(old); if (l != null) { l.releaseLock(); } addLock(n); }
leader.rename(l.findLock(leader), name, ext); getMultiFileSystem().unmaskFileOnAll(single, newFullName); copyContent(this, leader); l.changeLocks(previousLeader, leader);
leader.rename (l.findLock (leader), name, ext); getMultiFileSystem ().unmaskFileOnAll (single, newFullName); copyContent (this,leader); l.changeLocks (previousLeader, leader);
leader.rename (l.findLock (leader), name, ext); getMultiFileSystem ().unmaskFileOnAll (single, newFullName); copyContent (this,leader); l.changeLocks (previousLeader, leader);
/** * auxiliary method that returns true if mask is needed and deletes all delegates * on writable layers if deleteDelegates is true. * @param lock * @param deleteDelegates if true all delegates on writable layers will be deleted * @throws IOException is thrown if lock is not valid. * @return true if mask is necessary*/ private boolean needsMask(FileLock lock, boolean deleteDelegates) throws IOException{ MfLock lck = testLock(lock); Enumeration e = getMultiFileSystem().delegates(getPath()); boolean needsMask = false; while (e.hasMoreElements()) { FileObject fo = (FileObject) e.nextElement(); FileLock lockForFo = lck.findLock(fo); if (lockForFo == null) { // we will need to create mask needsMask = true; } else { if (deleteDelegates) fo.delete(lockForFo); } } return needsMask; }
/** Converts the file to be writable. * The file has to be locked! * * @return file object (new leader) that is writable * @exception IOException if the object cannot be writable */ private FileObject writable () throws IOException { MultiFileSystem fs = getMultiFileSystem (); FileSystem single = fs.createWritableOn (getPath ()); if (single != leader.getFileSystem()) { // if writing to a file that is not on writable fs => // copy it if (leader.isFolder()) { leader = FileUtil.createFolder (root (single), getPath ()); } else { FileObject folder = FileUtil.createFolder(root (single), getParent ().getPath ()); leader = leader.copy (folder, leader.getName (), leader.getExt ()); } MfLock l = (MfLock)(lock == null ? null : lock.get ()); if (l != null) { // update the lock l.addLock (leader); } } return leader; }
/** Converts the file to be writable. * The file has to be locked! * * @return file object (new leader) that is writable * @exception IOException if the object cannot be writable */ private FileObject writable () throws IOException { MultiFileSystem fs = getMultiFileSystem (); FileSystem single = fs.createWritableOn (getPath ()); if (single != leader.getFileSystem()) { // if writing to a file that is not on writable fs => // copy it if (leader.isFolder()) { leader = FileUtil.createFolder (root (single), getPath ()); } else { FileObject folder = FileUtil.createFolder(root (single), getParent ().getPath ()); leader = leader.copy (folder, leader.getName (), leader.getExt ()); } MfLock l = (MfLock)(lock == null ? null : lock.get ()); if (l != null) { // update the lock l.addLock (leader); } } return leader; }
/** * auxiliary method that returns true if mask is needed and deletes all delegates * on writable layers if deleteDelegates is true. * @param lock * @param deleteDelegates if true all delegates on writable layers will be deleted * @throws IOException is thrown if lock is not valid. * @return true if mask is necessary*/ private boolean needsMask(FileLock lock, boolean deleteDelegates) throws IOException{ MfLock lck = testLock(lock); Enumeration e = getMultiFileSystem().delegates(getPath()); boolean needsMask = false; while (e.hasMoreElements()) { FileObject fo = (FileObject) e.nextElement(); FileLock lockForFo = lck.findLock(fo); if (lockForFo == null) { // we will need to create mask needsMask = true; } else { if (deleteDelegates) fo.delete(lockForFo); } } return needsMask; }
public OutputStream getOutputStream (FileLock lock) throws java.io.IOException { MfLock l; FileLock lWritable; FileObject fo; try { getFileSystem ().beginAtomicAction (markAtomicAction); synchronized (this) { l = testLock (lock); // this can also change lock in l.lock fo = writable (); lWritable = l.findLock (fo); } return fo.getOutputStream (lWritable); } finally { getFileSystem ().finishAtomicAction (); } }
public OutputStream getOutputStream (FileLock lock) throws java.io.IOException { MfLock l; FileLock lWritable; FileObject fo; try { getFileSystem ().beginAtomicAction (markAtomicAction); synchronized (this) { l = testLock (lock); // this can also change lock in l.lock fo = writable (); lWritable = l.findLock (fo); } return fo.getOutputStream (lWritable); } finally { getFileSystem ().finishAtomicAction (); } }
public synchronized FileLock lock () throws IOException { if (lock != null) { FileLock f = (FileLock)lock.get (); if (f != null) { // [PENDING] construct localized message throw new FileAlreadyLockedException (getPath ()); } } java.util.Set set = getMultiFileSystem ().createLocksOn (getPath ()); FileLock l = new MfLock (leader, delegates (), set); lock = new WeakReference (l); // Thread.dumpStack (); // System.out.println ("Locking file: " + this); // NOI18N return l; }
public synchronized FileLock lock () throws IOException { if (lock != null) { FileLock f = (FileLock)lock.get (); if (f != null) { // [PENDING] construct localized message throw new FileAlreadyLockedException (getPath ()); } } java.util.Set set = getMultiFileSystem ().createLocksOn (getPath ()); FileLock l = new MfLock (leader, delegates (), set); lock = new WeakReference (l); // Thread.dumpStack (); // System.out.println ("Locking file: " + this); // NOI18N return l; }
public String toString() { return super.toString() + " for " + MultiFileObject.this + " valid=" + isValid(); // NOI18N } }
public String toString() { return super.toString() + " for " + MultiFileObject.this + " valid=" + isValid(); // NOI18N } }
/** Releases lock for old file object and * takes new one from newFo */ public void changeLocks ( FileObject old, FileObject n ) throws IOException { FileLock l = (FileLock)map.remove (old); if (l != null) { l.releaseLock(); } addLock (n); }
/** Releases lock for old file object and * takes new one from newFo */ public void changeLocks ( FileObject old, FileObject n ) throws IOException { FileLock l = (FileLock)map.remove (old); if (l != null) { l.releaseLock(); } addLock (n); }
public void releaseLock () { if (this.isValid()) { super.releaseLock(); releaseLockForDelegates(); if (getCurrentMfLock() == this) { // clears the reference to this lock from the file object MultiFileObject.this.lock = null; } } }