Skip to content

Commit

Permalink
Corrected NPE when recording events
Browse files Browse the repository at this point in the history
  • Loading branch information
rhauch committed Dec 22, 2016
1 parent 2ab4f40 commit 988f34e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
strongback.version=1.2.0-Beta2
strongback.version=1.2.0-Beta3
#
# The build will download a specific version of the WPILib given by the following URL
# and install it into the 'libs/wpilib' folder. To use a different version of WPILib,
Expand Down
25 changes: 18 additions & 7 deletions strongback/src/org/strongback/Strongback.java
Original file line number Diff line number Diff line change
Expand Up @@ -1258,10 +1258,12 @@ public String toString() {
return true;
}

private CommandListener createCommandListener() {
if (recordCommands) {
private CommandListener createCommandListener(EventRecorder recorder, boolean recordCommands) {
if (recordCommands && recorder != null) {
return (command, state) -> {
eventRecorder.record(command.getClass().getName(), state.ordinal());
if (command != null) {
recorder.record(command.getClass().getName(), state.ordinal());
}
};
}
return null;
Expand All @@ -1287,26 +1289,35 @@ protected boolean doStart() {
try {
executorDelayCounter.set(0);

// Create the event recorder if needed ...
boolean listenToCommands = false;
if (eventWriter != null) {
eventRecorder = new AsyncEventRecorder(eventWriter, clock);
eventRecorder.execute(CLOCK.currentTimeInMillis());
listenToCommands = recordCommands;
}

// Create the scheduler that runs commands ...
scheduler = new Scheduler(logger, createCommandListener());
scheduler = new Scheduler(logger, createCommandListener(eventRecorder,listenToCommands));
scheduler.execute(CLOCK.currentTimeInMillis());
executables.register(scheduler, SCHEDULER_PRIORITY);

if (useSwitchReactor) {
// Register the switch reactor ...
executables.register(switchReactor, SWITCH_REACTOR_PRIORITY);
switchReactor.execute(CLOCK.currentTimeInMillis());
}

// Create the data recorder if needed ...

if (dataWriterFactorySupplier != null) {
dataRecorderDriver = new DataRecorderDriver(dataRecorderChannels, dataWriterFactorySupplier.get());
dataRecorderDriver.start();
dataRecorderDriver.execute(CLOCK.currentTimeInMillis());
executables.register(dataRecorderDriver, DATA_RECORDER_PRIORITY);
}

// Create the event recorder if needed ...
if (eventWriter != null) {
eventRecorder = new AsyncEventRecorder(eventWriter, clock);
if (eventRecorder != null) {
executables.register(eventRecorder, EVENT_RECORDER_PRIORITY);
}

Expand Down

0 comments on commit 988f34e

Please sign in to comment.