-
Notifications
You must be signed in to change notification settings - Fork 338
Add LogRecord table update callbacks #2159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,6 @@ | |
| import net.sourceforge.ganttproject.storage.ServerCommitResponse; | ||
| import net.sourceforge.ganttproject.task.CustomColumnsStorage; | ||
| import net.sourceforge.ganttproject.task.Task; | ||
| import net.sourceforge.ganttproject.task.event.TaskListenerAdapter; | ||
| import net.sourceforge.ganttproject.undo.GPUndoListener; | ||
| import org.apache.commons.lang3.tuple.ImmutablePair; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
@@ -208,10 +207,6 @@ public GanttProject(boolean isOnlyViewer) { | |
| getWebSocket().register(null); | ||
| getWebSocket().onCommitResponseReceived(this::fireXlogReceived); | ||
| getWebSocket().onBaseTxnIdReceived(this::onBaseTxnIdReceived); | ||
| var taskListenerAdapter = new TaskListenerAdapter(); | ||
| // TODO: add listeners sensibly. | ||
| taskListenerAdapter.setTaskAddedHandler(event -> this.sendProjectStateLogs()); | ||
| getTaskManager().addTaskListener(taskListenerAdapter); | ||
| } | ||
|
|
||
| area = new GanttGraphicArea(this, getTaskManager(), getZoomManager(), getUndoManager(), | ||
|
|
@@ -956,33 +951,62 @@ public void refresh() { | |
| super.repaint(); | ||
| } | ||
|
|
||
| // TODO: Accumulate changes instead of sending it every time. | ||
| private interface TxnSendListener { | ||
| void onSendCompleted(); | ||
| } | ||
|
|
||
| private final AtomicReference<TxnSendListener> txnSendingListener = new AtomicReference<>(); | ||
|
|
||
| private Unit sendProjectStateLogs() { | ||
| gpLogger.debug("Sending project state logs"); | ||
| if (txnSendingListener.get() != null) return Unit.INSTANCE; | ||
| try { | ||
| var baseTxnCommitInfo = myBaseTxnCommitInfo.get(); | ||
| var txns = myProjectDatabase.fetchTransactions(baseTxnCommitInfo.right + 1, 1); | ||
| if (!txns.isEmpty()) { | ||
| getWebSocket().sendLogs(new InputXlog( | ||
| baseTxnCommitInfo.left, | ||
| "userId", | ||
| "refid", | ||
| txns | ||
| )); | ||
| var listener = new TxnSendListener() { | ||
| @Override | ||
| public void onSendCompleted() { | ||
| txnSendingListener.compareAndSet(this, null); | ||
| } | ||
| }; | ||
| if (txnSendingListener.compareAndSet(null, listener)) { | ||
| getWebSocket().sendLogs(new InputXlog( | ||
| baseTxnCommitInfo.left, | ||
| "userId", | ||
| "refid", | ||
| txns | ||
| )); | ||
| } | ||
| } | ||
| } catch (ProjectDatabaseException e) { | ||
| gpLogger.error("Failed to send logs", new Object[]{}, ImmutableMap.of(), e); | ||
|
dbarashev marked this conversation as resolved.
|
||
| } | ||
| return Unit.INSTANCE; | ||
| } | ||
|
|
||
| @Override | ||
| protected Unit onProjectLogUpdate() { | ||
| if (isColloboqueLocalTest()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like that we have more and more these checks. I thought that we would have just a few differences between the "local test" and "prod" modes (url, authentication), but now it seems that we will just not do anything in prod.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this check? And maybe the super call too?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, in this case we shall check "if we are working with an online document, in any sense", not "is it a local online document setup". We probably need to modify the local dev server so that it could respond to project read and write operations, just like a regular GP Cloud server. In this case the check may look like |
||
| super.onProjectLogUpdate(); | ||
| sendProjectStateLogs(); | ||
| } | ||
| return Unit.INSTANCE; | ||
| } | ||
|
|
||
| private Unit fireXlogReceived(ServerCommitResponse response) { | ||
| myBaseTxnCommitInfo.update(response.getBaseTxnId(), response.getNewBaseTxnId(), 1); | ||
| txnSendingListener.get().onSendCompleted(); | ||
| sendProjectStateLogs(); | ||
| return Unit.INSTANCE; | ||
| } | ||
|
|
||
| private Unit onBaseTxnIdReceived(String baseTxnId) { | ||
| myBaseTxnCommitInfo.update("", baseTxnId, 0); | ||
| var listener = txnSendingListener.get(); | ||
| // Websocket is [re-]started. Previous messages are discarded. | ||
| if (listener != null) listener.onSendCompleted(); | ||
| sendProjectStateLogs(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears that the comment above (previous messages are discarded) and these two lines (sendCompleted, sendLogs) are kinda controversial. We obviously need to make sure that the state which we have locally matches the server state which corresponds to this
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
| return Unit.INSTANCE; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.