Java Code Examples for org.openide.util.Mutex#Privileged

The following examples show how to use org.openide.util.Mutex#Privileged . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseFileObj.java    From netbeans with Apache License 2.0 6 votes vote down vote up
final void invalidateFO(boolean fire, final boolean expected, boolean createNewFN) {
    //fileobject is invalidated
    FolderObj parent = getExistingParent();
    if (parent != null) {
        ChildrenCache childrenCache = parent.getChildrenCache();
        final Mutex.Privileged mutexPrivileged = (childrenCache != null) ? childrenCache.getMutexPrivileged() : null;
        if (mutexPrivileged != null) {
            mutexPrivileged.enterWriteAccess();
        }
        try {
            childrenCache.getChild(getFileName().getFile().getName(), true);
        } finally {
            if (mutexPrivileged != null) {
                mutexPrivileged.exitWriteAccess();
            }
        }
    }
    setValid(false);
    if (createNewFN) {
        NamingFactory.fromFile(getFileName().getParent(), getFileName().getFile(), true);
    }
    if (fire) {
        notifyDeleted(expected);
    }
}
 
Example 2
Source File: FileObjectFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BaseFileObj getFileObject(FileInfo fInfo, Caller caller) {
    File file = fInfo.getFile();
    FolderObj parent = BaseFileObj.getExistingParentFor(file, this);
    FileNaming child = null;
    boolean isInitializedCache = true;
    if (parent != null) {
        final ChildrenCache childrenCache = parent.getChildrenCache();
        final Mutex.Privileged mutexPrivileged = childrenCache.getMutexPrivileged();
        Runnable[] task = new Runnable[1];
        for (int i = 0; i < 2; i++) {
            if (i == 1) {
                if (task[0] != null) {
                    task[0].run(); // some computation off the lock needed
                } else {
                    break;
                }
            }
            mutexPrivileged.enterReadAccess();
            try {
                final String nameExt = BaseFileObj.getNameExt(file);
                isInitializedCache = childrenCache.isCacheInitialized();
                child = childrenCache.getChild(nameExt, false, task);
            } finally {
                mutexPrivileged.exitReadAccess();
            }
        }
    }
    int initTouch = (isInitializedCache) ? -1 : (child != null ? 1 : 0);        
    if (initTouch == -1  && FileBasedFileSystem.isModificationInProgress()) {
        initTouch = file.exists() ? 1 : 0;
    }
    return issueIfExist(file, caller, parent, child, initTouch, caller.asynchFire());
}
 
Example 3
Source File: BaseFileObj.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void delete(final FileLock lock, ProvidedExtensions.DeleteHandler deleteHandler) throws IOException {        
    final File f = getFileName().getFile();

    final FolderObj existingParent = getExistingParent();
    final ChildrenCache childrenCache = (existingParent != null) ? existingParent.getChildrenCache() : null;
    final Mutex.Privileged mutexPrivileged = (childrenCache != null) ? childrenCache.getMutexPrivileged() : null;

    if (mutexPrivileged != null) {
        mutexPrivileged.enterWriteAccess();
    }
    try {
        if (!checkLock(lock)) {
            FSException.io("EXC_InvalidLock", lock, getPath()); // NOI18N                
        }

        boolean deleteStatus = (deleteHandler != null) ? deleteHandler.delete(f) : deleteFile(f);
        if (!deleteStatus) {
            FileObject parent = getExistingParent();
            String parentPath = (parent != null) ? parent.getPath() : f.getParentFile().getAbsolutePath();
            FSException.io("EXC_CannotDelete", f.getName(), parentPath);// NOI18N            
        } 
        BaseFileObj.attribs.deleteAttributes(f.getAbsolutePath().replace('\\', '/'));//NOI18N
        if (childrenCache != null) {
            if (deleteHandler != null) {
                childrenCache.removeChild(getFileName());
            } else {
                childrenCache.getChild(BaseFileObj.getNameExt(f), true);
            }
        }
    } finally {
        if (mutexPrivileged != null) {
            mutexPrivileged.exitWriteAccess();
        }
    }

    setValid(false);
    fireFileDeletedEvent(false);

}
 
Example 4
Source File: FolderObj.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(final FileLock lock, ProvidedExtensions.DeleteHandler deleteHandler) throws IOException {
    final Deque<FileObject> all = new ArrayDeque<FileObject>();

    final File file = getFileName().getFile();
    if (!deleteFile(file, all, getFactory(), deleteHandler)) {
        FileObject parent = getExistingParent();
        String parentPath = (parent != null) ? parent.getPath() : file.getParentFile().getAbsolutePath();
        FSException.io("EXC_CannotDelete", file.getName(), parentPath);// NOI18N            
    }

    BaseFileObj.attribs.deleteAttributes(file.getAbsolutePath().replace('\\', '/'));//NOI18N
    setValid(false);
    for (FileObject fo : all) {
        final BaseFileObj toDel = (BaseFileObj) fo;            
        final FolderObj existingParent = toDel.getExistingParent();            
        final ChildrenCache childrenCache = (existingParent != null) ? existingParent.getChildrenCache() : null;            
        if (childrenCache != null) {
            final Mutex.Privileged mutexPrivileged = (childrenCache != null) ? childrenCache.getMutexPrivileged() : null;
            if (mutexPrivileged != null) {
                mutexPrivileged.enterWriteAccess();
            }
            try {      
                if (deleteHandler != null) {
                    childrenCache.removeChild(toDel.getFileName());
                } else {
                    childrenCache.getChild(BaseFileObj.getNameExt(file), true);
                }
                
                
            } finally {
                if (mutexPrivileged != null) {
                    mutexPrivileged.exitWriteAccess();
                }
            }
        }                
        toDel.setValid(false);
        toDel.fireFileDeletedEvent(false);
    }        
}
 
Example 5
Source File: ModuleManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Classes in this package can, if careful, use the privileged form.
 * @since JST-PENDING this had to be made public as the package is now split in two
 */
public final Mutex.Privileged mutexPrivileged() {
    return MUTEX_PRIVILEGED;
}
 
Example 6
Source File: FolderObj.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public final FileObject createFolderImpl(final String name) throws java.io.IOException {
    if (name.indexOf('\\') != -1 || name.indexOf('/') != -1) {//NOI18N
        throw new IllegalArgumentException(name);
    }
    
    FolderObj retVal = null;
    File folder2Create;
    final ChildrenCache childrenCache = getChildrenCache();
    
    final Mutex.Privileged mutexPrivileged = childrenCache.getMutexPrivileged();

    final File myFile = getFileName().getFile();
    folder2Create = BaseFileObj.getFile( myFile, name, null);
    getProvidedExtensions().beforeCreate(this, folder2Create.getName(), true);
    mutexPrivileged.enterWriteAccess();

    try {
        if (!myFile.canWrite()) {
            FSException.io("EXC_CannotCreateFolder", folder2Create.getName(), getPath());// NOI18N
        }
        Watcher.lock(this);
        createFolder(folder2Create, name);

        FileNaming childName = this.getChildrenCache().getChild(folder2Create.getName(), true);
        if (childName != null && !childName.isDirectory()) {
            childName = NamingFactory.fromFile(getFileName(), folder2Create, true);
        }            
        if (childName != null) {
            childName = NamingFactory.checkCaseSensitivity(childName, folder2Create);
        }
    } finally {
        mutexPrivileged.exitWriteAccess();
    }

    final FileObjectFactory factory = getFactory();
    if (factory != null) {
        BaseFileObj exists = factory.getValidFileObject(folder2Create, FileObjectFactory.Caller.Others);
        if (exists instanceof FolderObj) {
            retVal = (FolderObj)exists;
        } else {
            FSException.io("EXC_CannotCreateFolder", folder2Create.getName(), getPath());// NOI18N                           
        }
    }
    if (retVal != null) {
        retVal.fireFileFolderCreatedEvent(false);
    } else {
        FSException.io("EXC_CannotCreateFolder", folder2Create.getName(), getPath());// NOI18N                           
    }
    getProvidedExtensions().createSuccess(retVal);
    return retVal;
}
 
Example 7
Source File: FolderObj.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public final FileObject createDataImpl(final String name, final String ext) throws java.io.IOException {
    if (name.indexOf('\\') != -1 || name.indexOf('/') != -1) {//NOI18N
        throw new IOException("Requested name contains invalid characters: " + name); // NOI18N
    }
    
    final ChildrenCache childrenCache = getChildrenCache();        
    final Mutex.Privileged mutexPrivileged = childrenCache.getMutexPrivileged();
    
    ProvidedExtensions extensions =  getProvidedExtensions();
    File file2Create;
    file2Create = BaseFileObj.getFile(getFileName().getFile(), name, ext);
    extensions.beforeCreate(this, file2Create.getName(), false);
    mutexPrivileged.enterWriteAccess();

    FileObj retVal;
    FileNaming childName;
    try {
        Watcher.lock(this);
        createData(file2Create);
        childName = getChildrenCache().getChild(file2Create.getName(), true);
        if (childName != null && childName.isDirectory()) {
            childName = NamingFactory.fromFile(getFileName(), file2Create, true);
        }
        if (childName != null) {
            childName = NamingFactory.checkCaseSensitivity(childName, file2Create);
        }

    } finally {
        mutexPrivileged.exitWriteAccess();
    }

    final FileObjectFactory factory = getFactory();
    retVal = null;
    if (factory != null) {
        final BaseFileObj fo = factory.getValidFileObject(file2Create, FileObjectFactory.Caller.Others);
        try {
            retVal = (FileObj) fo;
        } catch (ClassCastException ex) {
            boolean dir = file2Create.isDirectory();
            boolean file = file2Create.isFile();
            Exceptions.attachMessage(ex, "isDir: " + dir); // NOI18N
            Exceptions.attachMessage(ex, "isFile: " + file); // NOI18N
            Exceptions.attachMessage(ex, "file: " + file2Create); // NOI18N
            Exceptions.attachMessage(ex, "fo: " + fo); // NOI18N
            Exceptions.attachMessage(ex, "fn: " + Integer.toHexString(System.identityHashCode(childName))); // NOI18N
            Exceptions.attachMessage(ex, "dump: " + NamingFactory.dumpId(childName.getId())); // NOI18N
            throw ex;
        }
    }

    if (retVal != null) {            
        if (retVal instanceof FileObj) {
            retVal.setLastModified(file2Create.lastModified(), file2Create, false);
        }
        retVal.fireFileDataCreatedEvent(false);
    } else {
        FSException.io("EXC_CannotCreateData", file2Create.getName(), getPath());// NOI18N
    }
    getProvidedExtensions().createSuccess(retVal);
    return retVal;
}
 
Example 8
Source File: ChildrenSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public final Mutex.Privileged getMutexPrivileged() {
    return mutexPrivileged;
}
 
Example 9
Source File: BuildMutexImpl.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public Mutex.Privileged getPrivileged() {
    return privileged;
}
 
Example 10
Source File: ChildrenCache.java    From netbeans with Apache License 2.0 votes vote down vote up
Mutex.Privileged getMutexPrivileged(); 
Example 11
Source File: BuildMutex.java    From NBANDROID-V2 with Apache License 2.0 votes vote down vote up
public Mutex.Privileged getPrivileged();