Question

What's the best way to fail in the activate() method of my declarative service when I know the failure is unrecoverable? Specifically: my service is configurable via configadmin with metatype properties. If the configuration is invalid (say a malformed URL for example) what's the best practice way to fail? My current practice is to throw an IllegalArgumentException. Is there a better way? Does the DS host pay attention to the exception type, or are all exceptions treated the same?

The 4.2 spec simply says "If the activate method throws an exception, SCR must log an error message containing the exception with the Log Service, if present, and the component configuration is not activated." That suggests to me that I can just throw any exception and it doesn't really matter which one.

I've noticed that DS will retry the activate method under some circumstances, like if one of the other dependencies changes. Is there any mechanism to tell the infrastructure don't bother unless the configuration is fixed? Or should I just not worry about it and just accept that my activator will be called a few extra times?

Was it helpful?

Solution

Any exception is fine.

I think you just accept that your activator may be tried again. When the configuration is fixed may happen at any time. You could disable your component, but then how would you know when to reenable it?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top