import org.simantics.db.Resource;
import org.simantics.db.Session;
import org.simantics.db.common.session.SessionEventListenerAdapter;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.procedure.Procedure;
+import org.simantics.db.service.QueryControl;
import org.simantics.db.service.SessionEventSupport;
import org.simantics.scenegraph.INode;
import org.simantics.scenegraph.g2d.G2DSceneGraph;
import org.simantics.utils.datastructures.disposable.IDisposable;
import org.simantics.utils.threads.IThreadWorkQueue;
import org.simantics.utils.threads.ThreadUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ProfileObserver implements EvaluationContext {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ProfileObserver.class);
+
private final Session session;
/**
private volatile boolean dirty = true;
private volatile boolean disposed = false;
+ private boolean needSynchronizedUpdates = false;
private List<Pair<Style, Object>> updates = new ArrayList<>();
private boolean updateAll;
this.sceneGraph = sceneGraph;
this.constants.putAll(constants);
this.notification = notification;
+ this.needSynchronizedUpdates = session.getService(QueryControl.class).getAmountOfQueryThreads() > 1;
attachSessionListener();
public void update(Style style, Object item) {
if (DebugPolicy.DEBUG_PROFILE_OBSERVER_UPDATE)
System.out.println("Profile observer marked dirty.");
-
- updates.add(Pair.make(style, item));
+
+ if (needSynchronizedUpdates) {
+ synchronized (updates) {
+ updates.add(Pair.make(style, item));
+ }
+ } else {
+ updates.add(Pair.make(style, item));
+ }
//updateAll = true;
dirty = true;
}
e.apply(ProfileObserver.this);
}
updateAll = false;
- updates.clear();
+ if (needSynchronizedUpdates) {
+ synchronized (updates) {
+ updates.clear();
+ }
+ } else {
+ updates.clear();
+ }
} else {
- List<Pair<Style, Object>> updatesCopy = new ArrayList<>(updates);
- updates.clear();
+ List<Pair<Style, Object>> updatesCopy;
+ if (needSynchronizedUpdates) {
+ synchronized (updates) {
+ updatesCopy = new ArrayList<>(updates);
+ updates.clear();
+ }
+ } else {
+ updatesCopy = new ArrayList<>(updates);
+ updates.clear();
+ }
+
for (Pair<Style, Object> update : updatesCopy) {
Style style = update.first;
Object item = update.second;
@Override
public void exception(Throwable t) {
- Logger.defaultLogError(t);
+ LOGGER.error("RuntimeProfileActiveEntries request failed", t);
}
});
}
@Override
public void exception(Throwable throwable) {
- Logger.defaultLogError(throwable);
+ LOGGER.error("Exception occurred during diagram profile observation", throwable);
}
@SuppressWarnings("unchecked")