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

The following examples show how to use org.openide.util.Mutex#Action . 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: ProjectProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void fireChange() {
    if (!cs.hasListeners()) {
        return;
    }
    final Mutex.Action<Void> action = new Mutex.Action<Void>() {
        public Void run() {
            cs.fireChange();
            return null;
        }
    };
    if (ProjectManager.mutex().isWriteAccess()) {
        // Run it right now. postReadRequest would be too late.
        ProjectManager.mutex().readAccess(action);
    } else if (ProjectManager.mutex().isReadAccess()) {
        // Run immediately also. No need to switch to read access.
        action.run();
    } else {
        // Not safe to acquire a new lock, so run later in read access.
        RP.post(new Runnable() {
            public void run() {
                ProjectManager.mutex().readAccess(action);
            }
        });
    }
}
 
Example 2
Source File: PropertyUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void fireChange() {
    cachedTime = -1L; // force reload
    if (!cs.hasListeners()) {
        return;
    }
    final Mutex.Action<Void> action = new Mutex.Action<Void>() {
        public Void run() {
            cs.fireChange();
            return null;
        }
    };
    if (ProjectManager.mutex().isWriteAccess()) {
        // Run it right now. postReadRequest would be too late.
        ProjectManager.mutex().readAccess(action);
    } else if (ProjectManager.mutex().isReadAccess()) {
        // Run immediately also. No need to switch to read access.
        action.run();
    } else {
        // Not safe to acquire a new lock, so run later in read access.
        RP.post(new Runnable() {
            public void run() {
                ProjectManager.mutex().readAccess(action);
            }
        });
    }
}
 
Example 3
Source File: Evaluator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override final void propertyChange(PropertyChangeEvent evt) {
    String p = evt.getPropertyName();
    if (p != null && !p.startsWith("nbjdk.") && !p.startsWith("platforms.") && // NOI18N
            !p.equals(ClassPath.PROP_ENTRIES) && !p.equals(JavaPlatformManager.PROP_INSTALLED_PLATFORMS)) {
        return;
    }
    if (!changeSupport.hasListeners()) {
        return;
    }
    final Mutex.Action<Void> action = new Mutex.Action<Void>() {
        public @Override Void run() {
            changeSupport.fireChange();
            return null;
        }
    };
    // See ProjectProperties.PP.fireChange for explanation of this threading stuff:
    if (ProjectManager.mutex().isWriteAccess()) {
        ProjectManager.mutex().readAccess(action);
    } else if (ProjectManager.mutex().isReadAccess()) {
        action.run();
    } else {
        RP.post(new Runnable() {
            public @Override void run() {
                ProjectManager.mutex().readAccess(action);
            }
        });
    }
}
 
Example 4
Source File: ClassPathProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private <T> T runGuarded(@NonNull final Mutex.Action<T> action) {
    return ProjectManager.mutex().readAccess(new Mutex.Action<T>(){
        @Override
        public T run() {
            synchronized(cpLock) {
                return action.run();
            }
        }
    });
}
 
Example 5
Source File: BeforeSaveTasks.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static <T> T runWithOnSaveTasksDisabled(Mutex.Action<T> run) {
    Boolean originalIgnore = ignoreOnSaveTasks.get();
    ignoreOnSaveTasks.set(true);
    try {
        return run.run();
    } finally {
        ignoreOnSaveTasks.set(originalIgnore);
    }
}
 
Example 6
Source File: AntProjectHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Fire a change of external provenance to all listeners.
 * When run under read or write access to <code>ProjectManager.mutex()</code>
 * property change is fired synchronously, otherwise fire asynchronously
 * under acquired read lock.
 * @param path path to the changed file (XML or properties)
 */
void fireExternalChange(final String path) {
    final Mutex.Action<Void> action = new ActionImpl(this, path);
    if (ProjectManager.mutex().isWriteAccess() || ProjectLibraryProvider.FIRE_CHANGES_SYNCH) {
        // Run it right now. postReadRequest would be too late.
        ProjectManager.mutex().readAccess(action);
    } else if (ProjectManager.mutex().isReadAccess()) {
        // Run immediately also. No need to switch to read access.
        action.run();
    } else {
        // Not safe to acquire a new lock, so run later in read access.
        rp().post(new RunnableImpl(action));
    }
}
 
Example 7
Source File: Utilities.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**Don't use unless you know what you are doing.
 * 
 * @since 3.34
 */
public static <T> T runWithOnSaveTasksDisabled(Mutex.Action<T> run) {
    return BeforeSaveTasks.runWithOnSaveTasksDisabled(run);
}