-
Notifications
You must be signed in to change notification settings - Fork 1
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
Added feature to shutdown the logger properly if the server crashes unexpectedly #16
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,12 @@ | |
|
||
public class YoVariableLoggerListener implements YoVariablesUpdatedListener | ||
{ | ||
/** | ||
* We wait this long before shutting down the logger, this prevents logging forever in the case where the server didn't | ||
* shut down properly. | ||
*/ | ||
private static final int TICKS_WITHOUT_DATA_BEFORE_SHUTDOWN = 5000; | ||
|
||
private static final int FLUSH_EVERY_N_PACKETS = 250; | ||
public static final long STATUS_PACKET_RATE = Conversions.secondsToNanoseconds(5.0); | ||
private static final long VIDEO_RECORDING_TIMEOUT = Conversions.secondsToNanoseconds(1.0); | ||
|
@@ -81,6 +87,8 @@ public class YoVariableLoggerListener implements YoVariablesUpdatedListener | |
private long currentIndex = 0; | ||
|
||
private long lastReceivedTimestamp = Long.MIN_VALUE; | ||
private long ticksWithoutNewTimestamp = 0; | ||
private boolean alreadyShutDown = false; | ||
|
||
private final Announcement request; | ||
private final Consumer<Announcement> doneListener; | ||
|
@@ -433,6 +441,11 @@ public void disconnected() | |
|
||
doneListener.accept(request); | ||
} | ||
|
||
if (alreadyShutDown) | ||
{ | ||
LogTools.info("This may have already shutdown properly due to the server losing power for an extended amount of time"); | ||
} | ||
} | ||
|
||
private final ExecutorService executor = Executors.newCachedThreadPool(); | ||
|
@@ -563,13 +576,26 @@ public void receivedTimestampOnly(long timestamp) | |
{ | ||
synchronized (timestampUpdater) | ||
{ | ||
// We haven't received any new timestamps, shutdown the logger gracefully | ||
if (ticksWithoutNewTimestamp == TICKS_WITHOUT_DATA_BEFORE_SHUTDOWN) | ||
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. can you make this 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. Ya good call |
||
{ | ||
LogTools.warn("Whoa whoa whoa, haven't received new timestamps in a while, maybe the server crashed without proper shutdown, stopping the logger..."); | ||
disconnected(); | ||
alreadyShutDown = true; | ||
} | ||
|
||
if (timestamp > lastReceivedTimestamp) // Check if this a newer timestamp. UDP is out of order and the TCP packets also call this function | ||
{ | ||
for (int i = 0; i < videoDataLoggers.size(); i++) | ||
{ | ||
videoDataLoggers.get(i).timestampChanged(timestamp); | ||
} | ||
lastReceivedTimestamp = timestamp; | ||
ticksWithoutNewTimestamp = 0; | ||
} | ||
else | ||
{ | ||
ticksWithoutNewTimestamp++; | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily because of loss of power. I think you should just make this say
This may have already shutdown properly because the connection to the YoVariableServer was lost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, went with: "This may have already shutdown because the connection to the server was lost"