-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
633 additions
and
4 deletions.
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
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
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
11 changes: 11 additions & 0 deletions
11
flashlib.core.app/src/main/java/com/flash3388/flashlib/app/watchdog/FeedReporter.java
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.flash3388.flashlib.app.watchdog; | ||
|
||
import com.flash3388.flashlib.time.Time; | ||
|
||
import java.util.List; | ||
|
||
public interface FeedReporter { | ||
|
||
void reportFeed(String watchdogName); | ||
void reportFeedExpired(String watchdogName, Time feedOverrun, List<TimestampReport> reports); | ||
} |
10 changes: 10 additions & 0 deletions
10
flashlib.core.app/src/main/java/com/flash3388/flashlib/app/watchdog/InternalWatchdog.java
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.flash3388.flashlib.app.watchdog; | ||
|
||
import com.flash3388.flashlib.time.Time; | ||
|
||
public interface InternalWatchdog extends Watchdog { | ||
|
||
Time getTimeLeftToTimeout(); | ||
|
||
void checkFed(); | ||
} |
33 changes: 33 additions & 0 deletions
33
flashlib.core.app/src/main/java/com/flash3388/flashlib/app/watchdog/LoggingFeedReporter.java
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.flash3388.flashlib.app.watchdog; | ||
|
||
import com.flash3388.flashlib.time.Time; | ||
import com.flash3388.flashlib.util.logging.Logging; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.List; | ||
|
||
public class LoggingFeedReporter implements FeedReporter { | ||
|
||
private static final Logger LOGGER = Logging.getLogger("Watchdog"); | ||
|
||
@Override | ||
public void reportFeed(String watchdogName) { | ||
// do not report | ||
} | ||
|
||
@Override | ||
public void reportFeedExpired(String watchdogName, Time feedOverrun, List<TimestampReport> reports) { | ||
StringBuilder builder = new StringBuilder(); | ||
|
||
builder.append("Watchdog ").append(watchdogName).append(" overrun report\n"); | ||
builder.append("Time overrun:\t").append(String.format("%.3fs\n", feedOverrun.valueAsSeconds())); | ||
builder.append("Timestamps:\n"); | ||
|
||
for (TimestampReport report : reports) { | ||
builder.append('\t').append(report.getKey()).append(":") | ||
.append(String.format("%.3fs\n", report.getReportTime().valueAsSeconds())); | ||
} | ||
|
||
LOGGER.warn(builder.toString()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
flashlib.core.app/src/main/java/com/flash3388/flashlib/app/watchdog/MultiFeedReporters.java
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.flash3388.flashlib.app.watchdog; | ||
|
||
import com.flash3388.flashlib.time.Time; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class MultiFeedReporters implements FeedReporter { | ||
|
||
private final Collection<FeedReporter> mReporters; | ||
|
||
public MultiFeedReporters(Collection<FeedReporter> reporters) { | ||
mReporters = reporters; | ||
} | ||
|
||
@Override | ||
public void reportFeed(String watchdogName) { | ||
for (FeedReporter reporter : mReporters) { | ||
reporter.reportFeed(watchdogName); | ||
} | ||
} | ||
|
||
@Override | ||
public void reportFeedExpired(String watchdogName, Time feedOverrun, List<TimestampReport> reports) { | ||
for (FeedReporter reporter : mReporters) { | ||
reporter.reportFeedExpired(watchdogName, feedOverrun, reports); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
flashlib.core.app/src/main/java/com/flash3388/flashlib/app/watchdog/TimestampReport.java
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.flash3388.flashlib.app.watchdog; | ||
|
||
import com.flash3388.flashlib.time.Time; | ||
|
||
public class TimestampReport { | ||
|
||
private final String mKey; | ||
private final Time mReportTime; | ||
|
||
public TimestampReport(String key, Time reportTime) { | ||
mKey = key; | ||
mReportTime = reportTime; | ||
} | ||
|
||
public String getKey() { | ||
return mKey; | ||
} | ||
|
||
public Time getReportTime() { | ||
return mReportTime; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
flashlib.core.app/src/main/java/com/flash3388/flashlib/app/watchdog/Watchdog.java
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.flash3388.flashlib.app.watchdog; | ||
|
||
import com.flash3388.flashlib.time.Time; | ||
|
||
public interface Watchdog { | ||
|
||
/** | ||
* Gets the name of the watchdog. | ||
* | ||
* @return name, representative of the watchdog. | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* Gets the feed timeout of the watchdog. | ||
* | ||
* @return time | ||
*/ | ||
Time getTimeout(); | ||
|
||
/** | ||
* Gets whether the watchdog is currently enabled. | ||
* | ||
* @return <b>true</b> if enabled, <b>false</b> otherwise. | ||
*/ | ||
boolean isEnabled(); | ||
|
||
/** | ||
* Gets whether the feeding timer has expired. Measured according to the last | ||
* call to {@link #feed()}. | ||
* | ||
* @return <b>true</b> if expired, <b>false</b> otherwise. | ||
*/ | ||
boolean isExpired(); | ||
|
||
/** | ||
* Disables the feeding check of the watchdog. | ||
* Should be used when the target for the watchdog is not running or executing a | ||
* segment which should not be measured. | ||
*/ | ||
void disable(); | ||
|
||
/** | ||
* Enables the feeding check of the watchdog. Effectively restarting | ||
* each functionality. | ||
*/ | ||
void enable(); | ||
|
||
/** | ||
* Register a timestamp report. Use this to report on the progress of the target | ||
* for help debugging which parts of the target cause delays in execution. | ||
* | ||
* @param key storage key identifier, should be unique for this timestamp. | ||
*/ | ||
void reportTimestamp(String key); | ||
|
||
/** | ||
* Feeds the watchdog, updating it that the target is still functioning. Should | ||
* be called periodically at specific location to indicate that the target is still | ||
* functioning. | ||
*/ | ||
void feed(); | ||
} |
Oops, something went wrong.