@@ -180,42 +180,55 @@ private void start() {
180
180
// possible during startup.
181
181
registrar .start (slaveServer .toNodeIdentifier ());
182
182
183
- // During startup, we wait for 1) the RosoutLogger and 2) the TimeProvider.
184
- final CountDownLatch latch = new CountDownLatch (2 );
183
+ // Wait for the logger to register with the master. This ensures the master is running before
184
+ // requesting the use_sim_time parameter.
185
+ final CountDownLatch rosoutLatch = new CountDownLatch (1 );
185
186
186
187
log = new RosoutLogger (this );
187
188
log .getPublisher ().addListener (new DefaultPublisherListener <rosgraph_msgs .Log >() {
188
189
@ Override
189
190
public void onMasterRegistrationSuccess (Publisher <rosgraph_msgs .Log > registrant ) {
190
- latch .countDown ();
191
+ rosoutLatch .countDown ();
191
192
}
192
193
});
193
194
195
+ try {
196
+ rosoutLatch .await ();
197
+ } catch (InterruptedException e ) {
198
+ signalOnError (e );
199
+ shutdown ();
200
+ return ;
201
+ }
202
+
194
203
boolean useSimTime = false ;
195
204
try {
196
205
useSimTime =
197
206
parameterTree .has (Parameters .USE_SIM_TIME )
198
207
&& parameterTree .getBoolean (Parameters .USE_SIM_TIME );
199
208
} catch (Exception e ) {
200
209
signalOnError (e );
210
+ shutdown ();
211
+ return ;
201
212
}
213
+
214
+ final CountDownLatch timeLatch = new CountDownLatch (1 );
202
215
if (useSimTime ) {
203
216
ClockTopicTimeProvider clockTopicTimeProvider = new ClockTopicTimeProvider (this );
204
217
clockTopicTimeProvider .getSubscriber ().addSubscriberListener (
205
218
new DefaultSubscriberListener <rosgraph_msgs .Clock >() {
206
219
@ Override
207
220
public void onMasterRegistrationSuccess (Subscriber <rosgraph_msgs .Clock > subscriber ) {
208
- latch .countDown ();
221
+ timeLatch .countDown ();
209
222
}
210
223
});
211
224
timeProvider = clockTopicTimeProvider ;
212
225
} else {
213
226
timeProvider = nodeConfiguration .getTimeProvider ();
214
- latch .countDown ();
227
+ timeLatch .countDown ();
215
228
}
216
229
217
230
try {
218
- latch .await ();
231
+ timeLatch .await ();
219
232
} catch (InterruptedException e ) {
220
233
signalOnError (e );
221
234
shutdown ();
0 commit comments