Browse Source

加读写锁

feature/big-screen
alex.sung 5 years ago
parent
commit
60303b7272
  1. 40
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java

40
designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java

@ -14,6 +14,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/** /**
* Created by alex sung on 2019/7/23. * Created by alex sung on 2019/7/23.
@ -21,8 +23,10 @@ import java.util.Set;
public class FileNodeConstants { public class FileNodeConstants {
private static List<String> supportFileType; private static List<String> supportFileType;
private static ReadWriteLock rwl = new ReentrantReadWriteLock();
private FileNodeConstants(){} private FileNodeConstants() {
}
static { static {
initSupportedTypes(); initSupportedTypes();
@ -30,12 +34,7 @@ public class FileNodeConstants {
GeneralContext.listenPluginRunningChanged(new PluginEventListener() { GeneralContext.listenPluginRunningChanged(new PluginEventListener() {
@Override @Override
public void on(PluginEvent pluginEvent) { public void on(PluginEvent pluginEvent) {
supportFileType = new ArrayList<String>(Arrays.asList(FRContext.getFileNodes().getSupportedTypes())); initSupportedTypes();
//通过插件扩展的
Set<App> apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING);
for (App app : apps) {
addAppExtensions(app.defaultExtensions());
}
} }
}, new PluginFilter() { }, new PluginFilter() {
@Override @Override
@ -54,15 +53,30 @@ public class FileNodeConstants {
} }
private static void initSupportedTypes() { private static void initSupportedTypes() {
supportFileType = new ArrayList<String>(Arrays.asList(FRContext.getFileNodes().getSupportedTypes())); try {
//通过插件扩展的 rwl.writeLock().lock();
Set<App> apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING); supportFileType = new ArrayList<String>(Arrays.asList(FRContext.getFileNodes().getSupportedTypes()));
for (App app : apps) { //通过插件扩展的
addAppExtensions(app.defaultExtensions()); Set<App> apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING);
for (App app : apps) {
addAppExtensions(app.defaultExtensions());
}
} catch (Exception ignored) {
//ignored
} finally {
rwl.writeLock().unlock();
} }
} }
public static String[] getSupportFileTypes() { public static String[] getSupportFileTypes() {
return supportFileType.toArray(new String[0]); try {
rwl.readLock().lock();
return supportFileType.toArray(new String[0]);
} catch (Exception ignored) {
//ignored
} finally {
rwl.readLock().unlock();
}
return null;
} }
} }

Loading…
Cancel
Save