You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by deansg <de...@gmail.com> on 2015/12/04 14:28:19 UTC

"OnException" extension to SearchComponents / finalize on search components

I was recently writing a SearchComponent that performs a certain action in
the prepare method when in distributed context, and then must perform
another action after the query finished running to clean up (one of the
finishStage calls). I realized that if the SearchHandler on the server
throws an exception (because of another SearchComponent, for example) before
reaching finishStage, then I am in a problem since my component didnd't get
to clean-up after itself. I thought of two solutions to the problem and I
would like to know if they're any good:

1. I would write a class extending SearchComponent that has an "onException"
type of method. Then, I would write another class extending SearchHandler
that would surround handleRequestBody with a try-catch block and call
onException on the special SearchComponents, giving my component another
chance to clean up. This solution works for me, but extending a class such
as SearchHandler is kind of going against the regular Solr community.

2. I can put my cleaning-up logic in some finalizable object, and attach
that object to the ResponseBuilder. Then, I know that my component will
clean-up after itself eventually. However, I don't fully like this solution
either, first because attaching an object to the response builder for this
reason is abuse, and also because I know that finalize() should always be
avoided as much as possible.

What do you guys think?



--
View this message in context: http://lucene.472066.n3.nabble.com/OnException-extension-to-SearchComponents-finalize-on-search-components-tp4243575.html
Sent from the Solr - User mailing list archive at Nabble.com.