use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testStressConcurrentAccess.
public void testStressConcurrentAccess() throws Throwable {
final File tempDirectory = createTempDirectory();
VirtualFilePointer fileToCreatePointer = createPointerByFile(tempDirectory, null);
assertNotNull(fileToCreatePointer);
VirtualFilePointerListener listener = new VirtualFilePointerListener() {
};
long start = System.currentTimeMillis();
int i;
for (i = 0; System.currentTimeMillis() < start + 15_000; i++) {
Disposable disposable = Disposer.newDisposable();
// supply listener to separate pointers under one root so that it will be removed on dispose
VirtualFilePointerImpl bb = (VirtualFilePointerImpl) VirtualFilePointerManager.getInstance().create(fileToCreatePointer.getUrl() + "/bb", disposable, listener);
if (i % 1000 == 0)
LOG.info("i = " + i);
int NThreads = Runtime.getRuntime().availableProcessors();
CountDownLatch ready = new CountDownLatch(NThreads);
Runnable read = () -> {
try {
ready.countDown();
while (run) {
bb.myNode.myLastUpdated = -15;
bb.getUrl();
}
} catch (Throwable e) {
exception = e;
}
};
run = true;
List<Thread> threads = IntStream.range(0, NThreads).mapToObj(n -> new Thread(read, "reader" + n)).collect(Collectors.toList());
threads.forEach(Thread::start);
ready.await();
VirtualFilePointer bc = VirtualFilePointerManager.getInstance().create(fileToCreatePointer.getUrl() + "/b/c", disposable, listener);
run = false;
ConcurrencyUtil.joinAll(threads);
if (exception != null)
throw exception;
Disposer.dispose(disposable);
}
System.out.println("final i = " + i);
}
use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.
the class CodeInsightTestUtil method addTemplate.
public static void addTemplate(final Template template, Disposable parentDisposable) {
final TemplateSettings settings = TemplateSettings.getInstance();
settings.addTemplate(template);
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
settings.removeTemplate(template);
}
});
}
use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.
the class ParsingTestCase method registerApplicationService.
protected <T> void registerApplicationService(final Class<T> aClass, T object) {
getApplication().registerService(aClass, object);
Disposer.register(myProject, new Disposable() {
@Override
public void dispose() {
getApplication().getPicoContainer().unregisterComponent(aClass.getName());
}
});
}
use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.
the class ParsingTestCase method addExplicitExtension.
protected <T> void addExplicitExtension(final LanguageExtension<T> instance, final Language language, final T object) {
instance.addExplicitExtension(language, object);
Disposer.register(myProject, new Disposable() {
@Override
public void dispose() {
instance.removeExplicitExtension(language, object);
}
});
}
use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.
the class Disposer method register.
public static void register(@NotNull Disposable parent, @NotNull Disposable child, @NonNls @Nullable final String key) {
ourTree.register(parent, child);
if (key != null) {
Disposable v = get(key);
if (v != null)
throw new IllegalArgumentException("Key " + key + " already registered: " + v);
ourKeyDisposables.put(key, child);
register(child, new Disposable() {
@Override
public void dispose() {
ourKeyDisposables.remove(key);
}
});
}
}
Aggregations