org.openide.util.MutexException Java Examples

The following examples show how to use org.openide.util.MutexException. 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: DefaultMutexImplementation.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void writeAccess(Runnable runnable) {
    if (wrapper != null) {
        try {
            doWrapperAccess(null, runnable, false);
        } catch (MutexException ex) {
            throw new IllegalStateException(ex);
        }
        return;
    }

    Thread t = Thread.currentThread();
    writeEnter(t, 0);

    try {
        runnable.run();
    } finally {
        leave(t);
    }
}
 
Example #2
Source File: NbPlatform.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Set a new location for this platform's harness.
 */
public void setHarnessLocation(final File harness) throws IOException {
    if (harness.equals(this.harness)) {
        return;
    }
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            @Override public Void run() throws IOException {
                EditableProperties props = PropertyUtils.getGlobalProperties();
                storeHarnessLocation(id, nbdestdir, harness, props);
                PropertyUtils.putGlobalProperties(props);
                return null;
            }
        });
    } catch (MutexException e) {
        throw (IOException) e.getException();
    }
    this.harness = harness;
    harnessVersion = null;
}
 
Example #3
Source File: CopySupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Transferable paste() throws IOException {
    if (java.awt.EventQueue.isDispatchThread()) {
        return doPaste();
    }
    else { // reinvoke synchronously in AWT thread
        try {
            return Mutex.EVENT.readAccess(this);
        }
        catch (MutexException ex) {
            Exception e = ex.getException();
            if (e instanceof IOException)
                throw (IOException) e;
            else { // should not happen, ignore
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
                return transferable;
            }
        }
    }
}
 
Example #4
Source File: FormModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void undo() throws CannotUndoException {
    if (java.awt.EventQueue.isDispatchThread()) {
        superUndo();
    }
    else {
        try {
            Mutex.EVENT.readAccess(runUndo);
        }
        catch (MutexException ex) {
            Exception e = ex.getException();
            if (e instanceof CannotUndoException)
                throw (CannotUndoException) e;
            else // should not happen, ignore
                e.printStackTrace();
        }
    }
}
 
Example #5
Source File: AbstractGroovyExtender.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void storeEditableProperties(final Project prj, final  String propertiesPath, final EditableProperties ep)
    throws IOException {
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            @Override
            public Void run() throws IOException {
                FileObject propertiesFo = prj.getProjectDirectory().getFileObject(propertiesPath);
                if (propertiesFo!=null) {
                    OutputStream os = null;
                    try {
                        os = propertiesFo.getOutputStream();
                        ep.store(os);
                    } finally {
                        if (os != null) {
                            os.close();
                        }
                    }
                }
                return null;
            }
        });
    } catch (MutexException ex) {
    }
}
 
Example #6
Source File: GrailsProjectProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void save() {
    try {
        // store properties
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws IOException {
                saveProperties();
                return null;
            }
        });
        ProjectManager.getDefault().saveProject(project);
    } catch (MutexException e) {
        Exceptions.printStackTrace((IOException) e.getException());
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example #7
Source File: ApplicationMetadataModelImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public <R> R runReadAction(final MetadataModelAction<ApplicationMetadata, R> action) throws MetadataModelException, IOException {
    try {
        // see javadoc of this class
        return ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<R>() {
            public R run() throws Exception {
                enterRunReadAction();
                try {
                    return action.run(metadata);
                } finally {
                    leaveRunReadAction();
                }
            }
        });
    } catch (MutexException mutexException) {
        throw new MetadataModelException(mutexException.getException());
    }
}
 
Example #8
Source File: NbPlatform.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void putGlobalProperty(final String key, final String value) throws IOException {
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            @Override public Void run() throws IOException {
                EditableProperties props = PropertyUtils.getGlobalProperties();
                if ("".equals(value)) { // NOI18N
                    props.remove(key);
                } else {
                    props.setProperty(key, value);
                }
                PropertyUtils.putGlobalProperties(props);
                return null;
            }
        });
    } catch (MutexException e) {
        throw (IOException) e.getException();
    }
}
 
Example #9
Source File: JFXProjectUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Update FX build script.
 * @param proj
 * @return
 * @throws IOException 
 */
public static FileObject updateJfxImpl(final @NonNull Project proj) throws IOException {
    final FileObject projDir = proj.getProjectDirectory();
    final List<FileObject> updates = new ArrayList<FileObject>();
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            @Override
            public Void run() throws Exception {        
                projDir.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
                    public void run() throws IOException {        
                        if(!JFXProjectUtils.isJFXImplCurrent(proj)) {
                            FileObject updated = JFXProjectUtils.doUpdateJfxImpl(proj);
                            if(updated != null) {
                                updates.add(updated);
                            }
                        }
                    }
                });
                return null;
            }
        });
    } catch (MutexException ex) {
        Exceptions.printStackTrace(ex);
    }
    return updates.isEmpty() ? null : updates.get(0);
}
 
Example #10
Source File: AutomaticModuleNameCompilerOptionsQueryImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NonNull
private FileObject createManifest() throws IOException {
    try {
        return ProjectManager.mutex().writeAccess((Mutex.ExceptionAction<FileObject>)() -> {
            String path = project.getEvaluator().getProperty(ProjectProperties.MANIFEST_FILE);
            if (path == null) {
                path = "manifest.mf";   //NOI18N
                final EditableProperties props = project.getUpdateHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                props.setProperty(ProjectProperties.MANIFEST_FILE, path);
                project.getUpdateHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
                ProjectManager.getDefault().saveProject(project);
            }
            File f =  project.getUpdateHelper().getAntProjectHelper().resolveFile(path);
            return FileUtil.createData(f);
        });
    } catch (MutexException e) {
        throw e.getCause() instanceof IOException ?
                (IOException) e.getCause() :
                new IOException(e.getCause());
    }
}
 
Example #11
Source File: J2SEModularProjectGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new empty J2SE modular project.
 * @param dir the top-level directory (need not yet exist but if it does it must be empty)
 * @param name the name for the project
 * @return the helper object permitting it to be further customized
 * @throws IOException in case something went wrong
 */
public static AntProjectHelper createProject(final File dir, final String name, final JavaPlatform platform) throws IOException {
    Parameters.notNull("dir", dir); //NOI18N
    Parameters.notNull("name", name);   //NOI18N
    
    final FileObject dirFO = FileUtil.createFolder(dir);
    final AntProjectHelper[] h = new AntProjectHelper[1];
    dirFO.getFileSystem().runAtomicAction(() -> {
        final SpecificationVersion sourceLevel = getSourceLevel(platform);
        h[0] = createProject(dirFO, name, sourceLevel, "src", "classes", "tests", platform.getProperties().get(PROP_PLATFORM_ANT_NAME));   //NOI18N
        final J2SEModularProject p = (J2SEModularProject) ProjectManager.getDefault().findProject(dirFO);
        ProjectManager.getDefault().saveProject(p);
        try {
            ProjectManager.mutex().writeAccess((Mutex.ExceptionAction<Void>) () -> {
                ProjectManager.getDefault().saveProject (p);
                ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_MODULES);
                return null;
            });
        } catch (MutexException ex) {
            Exceptions.printStackTrace(ex.getException());
        }
        
        dirFO.createFolder("src"); //NOI18N
    });
    return h[0];
}
 
Example #12
Source File: J2SEConfigurationProviderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private static void setActiveConfiguration(
        ProjectConfigurationProvider<?> pcp,
        final ProjectConfiguration pc) throws IOException {
    final ProjectConfigurationProvider _pcp = pcp;
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            @Override
            public Void run() throws Exception {
                _pcp.setActiveConfiguration(pc);
                return null;
            }
        });
    } catch (MutexException me) {
        final Throwable inner = me.getCause();
        throw (inner instanceof IOException) ?
           (IOException) inner :
           new IOException (inner);
    }
}
 
Example #13
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 #14
Source File: JWSProjectPropertiesUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static <C extends ProjectConfiguration> void setActiveConfig(final ProjectConfigurationProvider<C> provider, String displayName) throws IOException {
    Collection<C> configs = provider.getConfigurations();
    for (final C c : configs) {
        if (displayName.equals(c.getDisplayName())) {
            try {
                ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
                    @Override
                    public Void run() throws Exception {
                        provider.setActiveConfiguration(c);
                        return null;
                    }
                });
            } catch (MutexException mex) {
                throw (IOException) mex.getException();
            }
        }
    }
}
 
Example #15
Source File: EnablePreviewAntProj.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void storeEditableProperties(final Project prj, final String propertiesPath, final EditableProperties ep)
        throws IOException {
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            @Override
            public Void run() throws IOException {
                FileObject propertiesFo = prj.getProjectDirectory().getFileObject(propertiesPath);
                if (propertiesFo != null) {
                    OutputStream os = null;
                    try {
                        os = propertiesFo.getOutputStream();
                        ep.store(os);
                    } finally {
                        if (os != null) {
                            os.close();
                        }
                    }
                }
                return null;
            }
        });
    } catch (MutexException ex) {
    }
}
 
Example #16
Source File: SuiteUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns suite for the given suite component. May return
 * <code>null</code>.
 * <p>Acquires read access.</p>
 */
public static SuiteProject findSuite(final Project suiteComponent) throws IOException {
    try {
        return ProjectManager.mutex().readAccess(new Mutex.ExceptionAction<SuiteProject>(){
            public SuiteProject run() throws Exception {
                Project suite = null;
                File suiteDir = SuiteUtils.getSuiteDirectory(suiteComponent);
                if (suiteDir != null) {
                    FileObject fo = FileUtil.toFileObject(suiteDir);
                    if (fo == null) {
                        Util.err.log(ErrorManager.WARNING, "Module in the \"" + // NOI18N
                                FileUtil.toFile(suiteComponent.getProjectDirectory()).getAbsolutePath() +
                                "\" directory claims to be a subcomponent of a suite in the \"" + // NOI18N
                                suiteDir.getAbsolutePath() + "\" which does not exist however."); // NOI18N
                    } else {
                        suite = ProjectManager.getDefault().findProject(fo);
                    }
                }
                return suite instanceof SuiteProject ? (SuiteProject) suite : /* #80786 */null;
            }
        });
    } catch (MutexException e) {
        throw (IOException) e.getException();
    }
}
 
Example #17
Source File: SuiteUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Removes module from its current suite if the given module is a suite
 * component. Does nothing otherwise.
 * <p>Acquires write access.</p>
 */
public static void removeModuleFromSuite(final NbModuleProject suiteComponent) throws IOException {
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws Exception {
                SuiteProject suite = SuiteUtils.findSuite(suiteComponent);
                if (suite != null) {
                    // detach module from its current suite
                    SuiteProperties suiteProps = new SuiteProperties(suite, suite.getHelper(),
                            suite.getEvaluator(), getSubProjects(suite));
                    removeModule(suiteComponent, suiteProps);
                    suiteProps.storeProperties();
                    ProjectManager.getDefault().saveProject(suite);
                } else {
                    removeModule(suiteComponent, null);
                }
                return null;
            }
        });
    } catch (MutexException e) {
        throw (IOException) e.getException();
    }
}
 
Example #18
Source File: SuiteUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the given module to the given suite if it is not already contained
 * there. If the module is already suite component of another suite it will
 * be appropriatelly removed from it (i.e moved from module's current suite
 * to the given suite).
 * <p>Acquires write access.</p>
 */
public static void addModule(final SuiteProject suite, final NbModuleProject project) throws IOException {
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws Exception {
                final SuiteProperties suiteProps = new SuiteProperties(suite, suite.getHelper(),
                        suite.getEvaluator(), getSubProjects(suite));
                if (!SuiteUtils.contains(suite, project)) {
                    SuiteUtils utils = new SuiteUtils(suiteProps);
                    utils.addModule(project);
                    suiteProps.storeProperties();
                } else {
                    Util.err.log("Module \"" + project + "\" or a module with the same CNB is already contained in the suite."); // NOI18N
                }
                ProjectManager.getDefault().saveProject(suite);
                return null;
            }
        });
    } catch (MutexException e) {
        throw (IOException) e.getException();
    }
}
 
Example #19
Source File: NbMutexEventProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Notify exception and returns new MutexException */
private static MutexException notifyException(Throwable t) {
    if (t instanceof InvocationTargetException) {
        t = unfoldInvocationTargetException((InvocationTargetException) t);
    }

    if (t instanceof Error) {
        annotateEventStack(t);
        throw (Error) t;
    }

    if (t instanceof RuntimeException) {
        annotateEventStack(t);
        throw (RuntimeException) t;
    }

    MutexException exc = new MutexException((Exception) t);
    exc.initCause(t);

    return exc;
}
 
Example #20
Source File: SystemFileSystemTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected @Override void setUp() throws Exception {
    // XXX simplify all this and move to org.openide.filesystems.RepositoryTest
    mgr = org.netbeans.core.startup.Main.getModuleSystem().getManager();
    org.netbeans.core.startup.Main.initializeURLFactory ();
    try {
        mgr.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            @Override
            public Void run() throws Exception {
                File data = new File(getDataDir(), "projects");
                File jars = getWorkDir();
                satJar = SetupHid.createTestJAR(data, jars, "sfs-attr-test", null);
                satModule = mgr.create(satJar, new ModuleHistory(satJar.getAbsolutePath()), false, false, false);
                assertEquals("no problems installing sfs-attr-test.jar", Collections.EMPTY_SET, satModule.getProblems());
                mgr.enable(satModule);
                return null;
            }
        });
    } catch (MutexException me) {
        throw me.getException();
    }
}
 
Example #21
Source File: MetaInfServicesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected @Override void setUp() throws Exception {
    //System.err.println("setUp");
    //Thread.dumpStack();
    clearWorkDir();
    // Load Plain.
    // Make a couple of modules.
    mgr = org.netbeans.core.startup.Main.getModuleSystem().getManager();
    try {
        mgr.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws Exception {
                File data = new File(getDataDir(), "lookup");
                File jars = getWorkDir();
                File jar1 = SetupHid.createTestJAR(data, jars, "services-jar-1", null);
                File jar2 = SetupHid.createTestJAR(data, jars, "services-jar-2", null, jar1);
                m1 = mgr.create(jar1, new ModuleHistory(jar1.getAbsolutePath()), false, false, false);
                m2 = mgr.create(jar2, new ModuleHistory(jar2.getAbsolutePath()), false, false, false);
                return null;
            }
        });
    } catch (MutexException me) {
        throw me.getException();
    }
    assertEquals(Collections.EMPTY_SET, m1.getProblems());
}
 
Example #22
Source File: MetaInfServicesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected @Override void tearDown() throws Exception {
    try {
        mgr.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws Exception {
                if (m2.isEnabled()) mgr.disable(m2);
                mgr.delete(m2);
                if (m1.isEnabled()) mgr.disable(m1);
                mgr.delete(m1);
                return null;
            }
        });
    } catch (MutexException me) {
        throw me.getException();
    }
    m1 = null;
    m2 = null;
    mgr = null;
}
 
Example #23
Source File: MetaInfServicesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void twiddle(final Module m, final int action) throws Exception {
    try {
        mgr.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws Exception {
                switch (action) {
                case TWIDDLE_ENABLE:
                    mgr.enable(m);
                    break;
                case TWIDDLE_DISABLE:
                    mgr.disable(m);
                    break;
                default:
                    throw new IllegalArgumentException("bad action: " + action);
                }
                return null;
            }
        });
    } catch (MutexException me) {
        throw me.getException();
    }
}
 
Example #24
Source File: InstanceDataObjectModuleTestHid.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected @Override void setUp() throws Exception {
    ERR = ErrManager.getDefault().getInstance("TEST-" + getName());
    
    mgr = org.netbeans.core.startup.Main.getModuleSystem().getManager();
    File data = new File(getDataDir(), "lookup");
    File jars = getWorkDir();
    final File jar1 = SetupHid.createTestJAR(data, jars, "test1", null);
    final File jar2 = SetupHid.createTestJAR(data, jars, "test2", null);
    try {
        mgr.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws Exception {
                m1 = mgr.create(jar1, new ModuleHistory(jar1.getAbsolutePath()), false, false, false);
                if (!m1.getProblems().isEmpty()) throw new IllegalStateException("m1 is uninstallable: " + m1.getProblems());
                m2 = mgr.create(jar2, new ModuleHistory(jar2.getAbsolutePath()), false, false, false);
                return null;
            }
        });
    } catch (MutexException me) {
        throw me.getException();
    }
    
    ERR.log("setup finished");
}
 
Example #25
Source File: ApplicationMetadataModelImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public <R> R runReadAction(final MetadataModelAction<ApplicationMetadata, R> action) throws MetadataModelException, IOException {
    try {
        // see javadoc of this class
        return ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<R>() {
            @Override
            public R run() throws Exception {
                enterRunReadAction();
                try {
                    return action.run(metadata);
                } finally {
                    leaveRunReadAction();
                }
            }
        });
    } catch (MutexException mutexException) {
        throw new MetadataModelException(mutexException.getException());
    }
}
 
Example #26
Source File: ProjectLibraryProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static FileObject getSharedLibFolder(final File libBaseFolder, final Library lib) throws IOException {
    FileObject sharedLibFolder;
    try {
        sharedLibFolder = ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<FileObject>() {
            public FileObject run() throws IOException {
                FileObject lf = FileUtil.toFileObject(libBaseFolder);
                if (lf == null) {
                    lf = FileUtil.createFolder(libBaseFolder);
                }
                return lf.createFolder(getUniqueName(lf, lib.getName(), null));
            }
        });
    } catch (MutexException ex) {
        throw (IOException)ex.getException();
    }
    return sharedLibFolder;
}
 
Example #27
Source File: SuiteProjectGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void createSuiteProject(final File projectDir, final String platformID, final boolean application) throws IOException {
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            public Void run() throws IOException {
                final FileObject dirFO = FileUtil.createFolder(projectDir);
                if (ProjectManager.getDefault().findProject(dirFO) != null) {
                    throw new IllegalArgumentException("Already a project in " + dirFO); // NOI18N
                }
                createSuiteProjectXML(dirFO);
                createPlatformProperties(dirFO, platformID);
                createProjectProperties(dirFO);
                ModuleList.refresh();
                ProjectManager.getDefault().clearNonProjectCache();
                if (application) {
                    initApplication(dirFO, platformID);
                }
                return null;
            }
        });
    } catch (MutexException e) {
        throw (IOException) e.getException();
    }
}
 
Example #28
Source File: DefaultMutexImplementation.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void readAccess(Runnable runnable) {
    if (wrapper != null) {
        try {
            doWrapperAccess(null, runnable, true);
            return;
        } catch (MutexException ex) {
            throw new IllegalStateException(ex);
        }
    }
    Thread t = Thread.currentThread();
    readEnter(t, 0);

    try {
        runnable.run();
    } finally {
        leave(t);
    }
}
 
Example #29
Source File: CopySupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Transferable paste() throws IOException {
    if (java.awt.EventQueue.isDispatchThread())
        return doPaste();
    else { // reinvoke synchronously in AWT thread
        try {
            return Mutex.EVENT.readAccess(this);
        }
        catch (MutexException ex) {
            Exception e = ex.getException();
            if (e instanceof IOException)
                throw (IOException) e;
            else { // should not happen, ignore
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
                return ExTransferable.EMPTY;
            }
        }
    }
}
 
Example #30
Source File: EvaluatorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testGetPlatformInPMWriteAccessDeadlock173345() throws Exception {
    final Logger LOG = Logger.getLogger(this.getClass().getName());
    Logger observer = Logger.getLogger("observer");
    Log.enable(LOG.getName(), Level.ALL);

    String mt = "THREAD: Test Watch Dog: testGetPlatformInPMWriteAccessDeadlock173345 MSG:";
    String wt = "THREAD: worker MSG:";
    String order =
        mt + "before NbPlatform.getPlatforms" +
        wt + "got PM write access";
    Log.controlFlow(LOG, observer, order, 0);
    NbPlatform.reset();
    Thread t = new Thread("worker") {

        @Override
        public void run() {
            try {
                ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
                    public @Override Void run() throws Exception {
                        LOG.log(Level.FINE, "got PM write access");
                        NbPlatform.getPlatforms();
                        LOG.log(Level.FINE, "after NbPlatform.getPlatforms");
                        return null;
                    }
                });
            } catch (MutexException ex) {
                throw new RuntimeException(ex);
            }
        }
    };
    t.start();
    LOG.log(Level.FINE, "before NbPlatform.getPlatforms");
    NbPlatform.getPlatforms();
    LOG.log(Level.FINE, "after NbPlatform.getPlatforms");
    t.join();
}