GP-1861 - Changed locking to prevent potential out-of-order events

This commit is contained in:
dragonmacher 2022-03-29 15:30:47 -04:00
parent 2d526352ee
commit 1ef3f71dd1
16 changed files with 192 additions and 197 deletions

View file

@ -28,15 +28,19 @@ public class DomainObjectEventQueues {
protected final DomainObject source;
protected final Lock lock;
protected final DomainObjectChangeSupport eventQueue;
protected final Map<EventQueueID, DomainObjectChangeSupport> privateEventQueues = CacheBuilder
.newBuilder().removalListener(this::privateQueueRemoved).weakKeys().build().asMap();
protected final Map<EventQueueID, DomainObjectChangeSupport> privateEventQueues =
CacheBuilder.newBuilder()
.removalListener(this::privateQueueRemoved)
.weakKeys()
.build()
.asMap();
protected volatile boolean eventsEnabled = true;
public DomainObjectEventQueues(DomainObject source, int timeInterval, int bufsize, Lock lock) {
public DomainObjectEventQueues(DomainObject source, int timeInterval, Lock lock) {
this.source = source;
this.lock = lock;
eventQueue = new DomainObjectChangeSupport(source, timeInterval, bufsize, lock);
eventQueue = new DomainObjectChangeSupport(source, timeInterval, lock);
}
private void privateQueueRemoved(
@ -51,18 +55,18 @@ public class DomainObjectEventQueues {
}
}
public synchronized void addListener(DomainObjectListener l) {
public void addListener(DomainObjectListener l) {
eventQueue.addListener(l);
}
public synchronized void removeListener(DomainObjectListener l) {
public void removeListener(DomainObjectListener l) {
eventQueue.removeListener(l);
}
public EventQueueID createPrivateEventQueue(DomainObjectListener listener, int maxDelay) {
EventQueueID id = new EventQueueID();
DomainObjectChangeSupport privateQueue =
new DomainObjectChangeSupport(source, maxDelay, 1000, lock);
new DomainObjectChangeSupport(source, maxDelay, lock);
privateQueue.addListener(listener);
privateEventQueues.put(id, privateQueue);
return id;

View file

@ -29,12 +29,12 @@ public class DBTraceUserData extends DomainObjectAdapterDB implements TraceUserD
}
protected DBTraceUserData(DBTrace trace) throws IOException {
super(new DBHandle(), getName(trace), 500, 1000, trace);
super(new DBHandle(), getName(trace), 500, trace);
// TODO: Create database and such
}
public DBTraceUserData(DBHandle dbh, DBTrace trace, TaskMonitor monitor) {
super(dbh, getName(trace), 500, 1000, trace);
super(dbh, getName(trace), 500, trace);
// TODO Auto-generated constructor stub
}

View file

@ -913,7 +913,7 @@ public class DBTraceProgramView implements TraceProgramView {
this.viewport.setSnap(snap);
this.eventQueues =
new DomainObjectEventQueues(this, TIME_INTERVAL, BUF_SIZE, trace.getLock());
new DomainObjectEventQueues(this, TIME_INTERVAL, trace.getLock());
this.regViewsByThread = new WeakValueHashMap<>();

View file

@ -61,7 +61,7 @@ public class DBTraceProgramViewRegisters implements TraceProgramView {
this.thread = codeSpace.getThread(); // TODO: Bleh, should be parameter
this.eventQueues = new DomainObjectEventQueues(this, DBTraceProgramView.TIME_INTERVAL,
DBTraceProgramView.BUF_SIZE, view.trace.getLock());
view.trace.getLock());
// TODO: Make these create code/memory spaces lazily, to allow null at construction
// NOTE: Use reference manager as example