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

The following examples show how to use org.openide.util.Mutex#ExceptionAction . 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: ModuleList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Runs given action both in Project read lock and synchronized on given cache
 * @param protectedCache Synchronized cache list, e.g. sourceLists, binaryLists, etc.
 * @param action Action to run
 * @return created or cached module list
 * @throws java.io.IOException
 */
private static ModuleList runProtected(final Object protectedCache, final Mutex.ExceptionAction<ModuleList> action) throws IOException {
    try {
        LOG.log(Level.FINER, "runProtected: sync 0");
        return ProjectManager.mutex().readAccess(new Mutex.ExceptionAction<ModuleList>() {
            public ModuleList run() throws Exception {
                LOG.log(Level.FINER, "runProtected: sync 1");
                synchronized (protectedCache) {
                    return action.run();
                }
            }
        });
    } catch (MutexException e){
        throw (IOException) e.getException();
    }
}
 
Example 2
Source File: RunWhenScanFinishedSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public DeferredTask (
        @NonNull final Collection<Source> sources,
        @NonNull final Mutex.ExceptionAction<Void> task,
        @NonNull final ScanSync sync,
        @NonNull final Lookup context) {
    assert sources != null;
    assert task != null;
    assert sync != null;
    assert context != null;

    this.sources = sources;
    this.task = task;
    this.sync = sync;
    this.context = context;
}
 
Example 3
Source File: NbMutexEventProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T writeAccess(Mutex.ExceptionAction<T> action) throws MutexException {
    return doEventAccess(action);         
}
 
Example 4
Source File: NbMutexEventProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T readAccess(Mutex.ExceptionAction<T> action) throws MutexException {
    return doEventAccess(action);
}
 
Example 5
Source File: LazyMutexImplementation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T writeAccess(Mutex.ExceptionAction<T> action) throws MutexException {
    return getDelegate().writeAccess(action);
}
 
Example 6
Source File: LazyMutexImplementation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T readAccess(Mutex.ExceptionAction<T> action) throws MutexException {
    return getDelegate().readAccess(action);
}
 
Example 7
Source File: Compact2MutexEventProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T writeAccess(Mutex.ExceptionAction<T> action) throws MutexException {
    return handle();
}
 
Example 8
Source File: Compact2MutexEventProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T readAccess(Mutex.ExceptionAction<T> action) throws MutexException {
    return handle();
}
 
Example 9
Source File: RunWhenScanFinishedSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NonNull
public static Future<Void> runWhenScanFinished (
        @NonNull final Mutex.ExceptionAction<Void> task,
        @NonNull final Collection<Source> sources) throws ParseException {
    assert task != null;
    assert sources != null;
    final ScanSync sync = new ScanSync (task);
    final DeferredTask r = new DeferredTask (sources, task, sync, Lookup.getDefault());
    //0) Add speculatively task to be performed at the end of background scan
    todo.add (r);
    boolean indexing = TaskProcessor.getIndexerBridge().isIndexing();
    if (indexing) {
        return sync;
    }
    //1) Try to aquire javac lock, if successfull no task is running
    //   perform the given taks synchronously if it wasn't already performed
    //   by background scan.
    final boolean locked = lock.readLock().tryLock();
    if (locked) {
        try {
            LOG.log(
                Level.FINE,
                "runWhenScanFinished:entry",    //NOI18N
                task);
            if (todo.remove(r)) {
                try {
                    TaskProcessor.runUserTask(task, sources);
                } finally {
                    sync.taskFinished();
                }
            }
            LOG.log(
                Level.FINE,
                "runWhenScanFinished:exit",     //NOI18N
                task);
        } finally {
            lock.readLock().unlock();
        }
    }
    return sync;
}
 
Example 10
Source File: RunWhenScanFinishedSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ScanSync (final Mutex.ExceptionAction<Void> task) {
    assert task != null;
    this.task = task;
    this.sync = new CountDownLatch (1);
    this.canceled = new AtomicBoolean (false);
}
 
Example 11
Source File: MutexImplementation.java    From netbeans with Apache License 2.0 votes vote down vote up
<T> T writeAccess(Mutex.ExceptionAction<T> action) throws MutexException; 
Example 12
Source File: MutexImplementation.java    From netbeans with Apache License 2.0 votes vote down vote up
<T> T readAccess(Mutex.ExceptionAction<T> action) throws MutexException;