@@ -51,6 +51,7 @@ void TfBuilderDevice::Init()
5151
5252void TfBuilderDevice::Reset ()
5353{
54+ mMemI ->stop ();
5455 mMemI .reset ();
5556}
5657
@@ -69,10 +70,15 @@ void TfBuilderDevice::InitTask()
6970
7071 auto &lStatus = mDiscoveryConfig ->status ();
7172 lStatus.mutable_info ()->set_type (TfBuilder);
72- lStatus.mutable_info ()->set_process_id (Config::getIdOption (*GetConfig ()));
73+ lStatus.mutable_info ()->set_process_id (Config::getIdOption (TfBuilder, *GetConfig ()));
7374 lStatus.mutable_info ()->set_ip_address (Config::getNetworkIfAddressOption (*GetConfig ()));
7475
75- mPartitionId = Config::getPartitionOption (*GetConfig ());
76+ // wait for "partition-id"
77+ while (!Config::getPartitionOption (*GetConfig ())) {
78+ WDDLOG (" TfBuilder waiting on 'discovery-partition' config parameter." );
79+ std::this_thread::sleep_for (1s);
80+ }
81+ mPartitionId = *Config::getPartitionOption (*GetConfig ());
7682 lStatus.mutable_partition ()->set_partition_id (mPartitionId );
7783
7884 // File sink
@@ -110,15 +116,14 @@ void TfBuilderDevice::InitTask()
110116 mStandalone = true ;
111117 IDDLOG (" Not sending to DPL." );
112118 }
113-
114- // start the info thread
115- mInfoThread = create_thread_member (" tfb_info" , &TfBuilderDevice::InfoThread, this );
116119 }
117120}
118121
119122void TfBuilderDevice::PreRun ()
120123{
121- start ();
124+ if (!start ()) {
125+ mShouldExit = true ;
126+ }
122127}
123128
124129bool TfBuilderDevice::start ()
@@ -136,7 +141,6 @@ bool TfBuilderDevice::start()
136141
137142 // we reached the scheduler instance, initialize everything else
138143 mRunning = true ;
139- auto lShmTransport = this ->AddTransport (fair::mq::Transport::SHM);
140144
141145 mTfBuilder = std::make_unique<TimeFrameBuilder>(MemI (), mTfBufferSize , 512 << 20 /* config */ , dplEnabled ());
142146
@@ -154,19 +158,23 @@ bool TfBuilderDevice::start()
154158 if (!mFlpInputHandler ->start (mDiscoveryConfig )) {
155159 mShouldExit = true ;
156160 EDDLOG (" Could not initialize input connections. Exiting." );
157- throw " Input connection error" ;
158161 return false ;
159162 }
160163
161164 // start file source
162165 mFileSource .start (MemI (), mStandalone ? false : mDplEnabled );
163166
167+ // start the info thread
168+ mInfoThread = create_thread_member (" tfb_info" , &TfBuilderDevice::InfoThread, this );
169+
164170 return true ;
165171}
166172
167173void TfBuilderDevice::stop ()
168174{
169- mRpc ->stopAcceptingTfs ();
175+ if (mRpc ) {
176+ mRpc ->stopAcceptingTfs ();
177+ }
170178
171179 if (mTfDplAdapter ) {
172180 mTfDplAdapter ->stop ();
@@ -177,41 +185,58 @@ void TfBuilderDevice::stop()
177185 }
178186
179187 mRunning = false ;
188+ DDDLOG (" TfBuilderDevice::stop(): mRunning is false." );
180189
181190 // Stop the pipeline
182191 stopPipeline ();
183192
184193 // stop output handlers
185- mFlpInputHandler ->stop (mDiscoveryConfig );
194+ if (mFlpInputHandler ) {
195+ mFlpInputHandler ->stop (mDiscoveryConfig );
196+ }
197+ DDDLOG (" TfBuilderDevice::stop(): Input handler stopped." );
186198 // signal and wait for the output thread
187199 mFileSink .stop ();
188200 // join on fwd thread
189201 if (mTfFwdThread .joinable ()) {
190202 mTfFwdThread .join ();
191203 }
204+ DDDLOG (" TfBuilderDevice::stop(): Forward thread stopped." );
192205
193206 // wait for the info thread
194207 if (mInfoThread .joinable ()) {
195208 mInfoThread .join ();
196209 }
210+ DDDLOG (" TfBuilderDevice::stop(): Info thread stopped." );
197211
198212 // stop the RPCs
199- mRpc ->stop ();
213+ if (mRpc ) {
214+ mRpc ->stop ();
215+ }
216+ DDDLOG (" TfBuilderDevice::stop(): RPC clients stopped." );
200217
201218 mDiscoveryConfig .reset ();
202219
203- DDDLOG (" Reset () done ... " );
220+ DDDLOG (" TfBuilderDevice () stopped ... " );
204221}
205222
206223void TfBuilderDevice::ResetTask ()
207224{
208225 stop ();
226+ DDDLOG (" ResetTask()" );
227+ }
228+
229+ // Get here when ConditionalRun returns false
230+ void TfBuilderDevice::PostRun ()
231+ {
232+ stop ();
233+ DDDLOG (" PostRun()" );
209234}
210235
211236bool TfBuilderDevice::ConditionalRun ()
212237{
213- if (mShouldExit ) {
214- mRunning = false ;
238+ if (mShouldExit || mRpc -> isTerminateRequested () ) {
239+ // mRunning = false;
215240 return false ;
216241 }
217242
@@ -279,10 +304,7 @@ void TfBuilderDevice::TfForwardThread()
279304
280305void TfBuilderDevice::InfoThread ()
281306{
282- // wait for the device to go into RUNNING state
283- WaitForRunningState ();
284-
285- while (IsRunningState ()) {
307+ while (mRunning ) {
286308
287309 IDDLOG (" TimeFrame size_mean={} in_frequency_mean={:.4} queued_stf={}" ,
288310 mTfSizeSamples .Mean (), mTfTimeSamples .MeanStepFreq (), getPipelineSize ());
0 commit comments