mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RunConfigurations: log files updating moved out of the UI thread
This commit is contained in:
@@ -3,10 +3,10 @@ package com.intellij.diagnostic.logging;
|
||||
import com.intellij.execution.configurations.LogFileOptions;
|
||||
import com.intellij.execution.configurations.RunConfigurationBase;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.util.Alarm;
|
||||
import gnu.trove.THashSet;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
@@ -17,11 +17,13 @@ import java.util.*;
|
||||
* Date: 01-Feb-2006
|
||||
*/
|
||||
public class LogFilesManager {
|
||||
private static final int UPDATE_INTERVAL = 500;
|
||||
|
||||
private final Map<LogFileOptions, Set<String>> myLogFileManagerMap = new LinkedHashMap<LogFileOptions, Set<String>>();
|
||||
private final Map<LogFileOptions, RunConfigurationBase> myLogFileToConfiguration = new HashMap<LogFileOptions, RunConfigurationBase>();
|
||||
private final Runnable myUpdateRequest;
|
||||
private final LogConsoleManager myManager;
|
||||
private Alarm myUpdateAlarm = new Alarm();
|
||||
private Alarm myUpdateAlarm = new Alarm(Alarm.ThreadToUse.OWN_THREAD);
|
||||
|
||||
public LogFilesManager(final Project project, LogConsoleManager manager) {
|
||||
myManager = manager;
|
||||
@@ -30,28 +32,33 @@ public class LogFilesManager {
|
||||
if (project.isDisposed()) return;
|
||||
if (myUpdateAlarm == null) return; //already disposed
|
||||
myUpdateAlarm.cancelAllRequests();
|
||||
for (LogFileOptions logFile : myLogFileManagerMap.keySet()) {
|
||||
for (final LogFileOptions logFile : myLogFileManagerMap.keySet()) {
|
||||
final Set<String> oldFiles = myLogFileManagerMap.get(logFile);
|
||||
final Set<String> newFiles = logFile.getPaths();
|
||||
addConfigurationConsoles(logFile, new Condition<String>(){
|
||||
public boolean value(final String file) {
|
||||
return !oldFiles.contains(file);
|
||||
final Set<String> newFiles = logFile.getPaths(); // should not be called in UI thread
|
||||
myLogFileManagerMap.put(logFile, newFiles);
|
||||
|
||||
final Set<String> obsoleteFiles = new THashSet<String>(oldFiles);
|
||||
obsoleteFiles.removeAll(newFiles);
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
addConfigurationConsoles(logFile, new Condition<String>() {
|
||||
public boolean value(final String file) {
|
||||
return !oldFiles.contains(file);
|
||||
}
|
||||
});
|
||||
for (String each : obsoleteFiles) {
|
||||
myManager.removeLogConsole(each);
|
||||
}
|
||||
myUpdateAlarm.addRequest(myUpdateRequest, UPDATE_INTERVAL);
|
||||
}
|
||||
});
|
||||
for (String oldFile : oldFiles) {
|
||||
if (!newFiles.contains(oldFile)){
|
||||
myManager.removeLogConsole(oldFile);
|
||||
}
|
||||
}
|
||||
oldFiles.clear();
|
||||
oldFiles.addAll(newFiles);
|
||||
}
|
||||
myUpdateAlarm.addRequest(myUpdateRequest, 300, ModalityState.NON_MODAL);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void registerFileMatcher(final RunConfigurationBase runConfiguration){
|
||||
public void registerFileMatcher(final RunConfigurationBase runConfiguration) {
|
||||
final ArrayList<LogFileOptions> logFiles = runConfiguration.getAllLogFiles();
|
||||
for (LogFileOptions logFile : logFiles) {
|
||||
if (logFile.isEnabled()) {
|
||||
@@ -59,17 +66,13 @@ public class LogFilesManager {
|
||||
myLogFileToConfiguration.put(logFile, runConfiguration);
|
||||
}
|
||||
}
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
Alarm updateAlarm = myUpdateAlarm;
|
||||
if (updateAlarm != null) {
|
||||
updateAlarm.addRequest(myUpdateRequest, 300, ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
});
|
||||
Alarm updateAlarm = myUpdateAlarm;
|
||||
if (updateAlarm != null) {
|
||||
updateAlarm.addRequest(myUpdateRequest, UPDATE_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterFileMatcher(){
|
||||
public void unregisterFileMatcher() {
|
||||
if (myUpdateAlarm != null) {
|
||||
myUpdateAlarm.cancelAllRequests();
|
||||
myUpdateAlarm = null;
|
||||
|
||||
Reference in New Issue
Block a user