@@ -209,6 +209,31 @@ struct ExpirationHandlerHelpers {
209209 {
210210 return [](DeviceState&, ConfigParamRegistry const &) { return LifetimeHelpers::fetchFromObjectRegistry (); };
211211 }
212+
213+ // / This behaves as data. I.e. we never create it unless data arrives.
214+ static RouteConfigurator::CreationConfigurator createOptionalConfigurator ()
215+ {
216+ return [](DeviceState&, ConfigParamRegistry const &) { return LifetimeHelpers::dataDrivenCreation (); };
217+ }
218+
219+ // / This will always exipire an optional record when no data is received.
220+ static RouteConfigurator::DanglingConfigurator danglingOptionalConfigurator ()
221+ {
222+ return [](DeviceState&, ConfigParamRegistry const &) { return LifetimeHelpers::expireAlways (); };
223+ }
224+
225+ // / When the record expires, simply create a dummy entry.
226+ static RouteConfigurator::ExpirationConfigurator expiringOptionalConfigurator (InputSpec const & spec, std::string const & sourceChannel)
227+ {
228+ auto m = std::get_if<ConcreteDataMatcher>(&spec.matcher );
229+ if (m == nullptr ) {
230+ throw runtime_error (" InputSpec for Enumeration must be fully qualified" );
231+ }
232+ // We copy the matcher to avoid lifetime issues.
233+ return [matcher = *m, sourceChannel](DeviceState&, ConfigParamRegistry const &) {
234+ return LifetimeHelpers::dummy (matcher, sourceChannel);
235+ };
236+ }
212237};
213238
214239// / This creates a string to configure channels of a FairMQDevice
@@ -638,6 +663,12 @@ void DeviceSpecHelpers::processInEdgeActions(std::vector<DeviceSpec>& devices,
638663 ExpirationHandlerHelpers::danglingTransientConfigurator (),
639664 ExpirationHandlerHelpers::expiringTransientConfigurator (inputSpec)};
640665 break ;
666+ case Lifetime::Optional:
667+ route.configurator = {
668+ ExpirationHandlerHelpers::createOptionalConfigurator (),
669+ ExpirationHandlerHelpers::danglingOptionalConfigurator (),
670+ ExpirationHandlerHelpers::expiringOptionalConfigurator (inputSpec, sourceChannel)};
671+ break ;
641672 default :
642673 break ;
643674 }
0 commit comments