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 Mikhail Khludnev <mk...@griddynamics.com> on 2011/12/21 20:06:42 UTC

best practice to introducing singletons inside of Solr (IoC)

Hello,

I need to introduce several singletons inside of Solr and make them
available for my own SearchHandlers, Components, and even QParsers, etc.

Right now I use some kind of fake SolrRequestHandler which loads on init()
and available everywhere through
solrCore.getRequestHandler("wellknownName"). Then I downcast it everywhere
and access the required methods. The same is possible with fake
SearchComponent.
Particularly my singletons are some additional fields schema (pretty
sophisticated), and kind of request/response encoding facility.
The typical Java hammer for such pins is Spring, but I've found puzzling to
use
http://static.springframework.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/context/support/WebApplicationContextUtils.html

What's the best way to do that?

-- 
Sincerely yours
Mikhail Khludnev
Lucid Certified
Apache Lucene/Solr Developer
Grid Dynamics

<http://www.griddynamics.com>
 <mk...@griddynamics.com>

Re: best practice to introducing singletons inside of Solr (IoC)

Posted by Chris Hostetter <ho...@fucit.org>.
: Ok. Let me try with plain java one. Possibly I'll need more tight
: integration like injecting a core into the singleton, etc. But I don't know
: yet.

yeah ... it really depends on what you mean by "singleton" ...

	...single instance in entire JVM?
	...single instance in each webapp?
	...single instance in each solr core?

If you want the first or the second, standard java patterns will be your 
best bet, but you'll need to be careful with the classpath and make sure 
your class is loaded at the appropriate level (and in the first case: 
can't directly know about any Solr specific classes).

If you want one instance per solr core, that is part of the solr core 
lifecycle (so a new one is created if/when the core is replaced) i 
think the approach of an explicitly named request handler is simplest way 
to go.  

-Hoss

Re: best practice to introducing singletons inside of Solr (IoC)

Posted by Mikhail Khludnev <mk...@griddynamics.com>.
Erick,

Ok. Let me try with plain java one. Possibly I'll need more tight
integration like injecting a core into the singleton, etc. But I don't know
yet.

Thanks for your efforts.

On Wed, Dec 28, 2011 at 5:48 PM, Erick Erickson <er...@gmail.com>wrote:

> I must be missing something here. Why would this be any different from
> any other singleton? I just did a little experiment where I implemented
> the classic singleton pattern in a RequestHandler and accessed
> from a Filter (both plugins) with no problem at all, just the usual
> blah var = MySingleton.getInstance();
> var.whatever....
>
> There was non need to get Solr cores involved at all. Of course this
> was just a simple experiment, YMMV..
>
> Best
> Erick
>
> On Tue, Dec 27, 2011 at 11:52 PM, Mikhail Khludnev
> <mk...@griddynamics.com> wrote:
> > Colleagues,
> >
> > Don't hesitate to emit your opinion. Please!
> >
> > Regards
> >
> > On Wed, Dec 21, 2011 at 11:06 PM, Mikhail Khludnev <
> > mkhludnev@griddynamics.com> wrote:
> >
> >> Hello,
> >>
> >> I need to introduce several singletons inside of Solr and make them
> >> available for my own SearchHandlers, Components, and even QParsers, etc.
> >>
> >> Right now I use some kind of fake SolrRequestHandler which loads on
> init()
> >> and available everywhere through
> >> solrCore.getRequestHandler("wellknownName"). Then I downcast it
> everywhere
> >> and access the required methods. The same is possible with fake
> >> SearchComponent.
> >> Particularly my singletons are some additional fields schema (pretty
> >> sophisticated), and kind of request/response encoding facility.
> >> The typical Java hammer for such pins is Spring, but I've found puzzling
> >> to use
> >>
> http://static.springframework.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/context/support/WebApplicationContextUtils.html
> >>
> >> What's the best way to do that?
> >>
> >> --
> >> Sincerely yours
> >> Mikhail Khludnev
> >> Lucid Certified
> >> Apache Lucene/Solr Developer
> >> Grid Dynamics
> >>
> >> <http://www.griddynamics.com>
> >>  <mk...@griddynamics.com>
> >>
> >>
> >
> >
> > --
> > Sincerely yours
> > Mikhail Khludnev
> > Lucid Certified
> > Apache Lucene/Solr Developer
> > Grid Dynamics
> >
> > <http://www.griddynamics.com>
> >  <mk...@griddynamics.com>
>



-- 
Sincerely yours
Mikhail Khludnev
Lucid Certified
Apache Lucene/Solr Developer
Grid Dynamics

<http://www.griddynamics.com>
 <mk...@griddynamics.com>

Re: best practice to introducing singletons inside of Solr (IoC)

Posted by Erick Erickson <er...@gmail.com>.
I must be missing something here. Why would this be any different from
any other singleton? I just did a little experiment where I implemented
the classic singleton pattern in a RequestHandler and accessed
from a Filter (both plugins) with no problem at all, just the usual
blah var = MySingleton.getInstance();
var.whatever....

There was non need to get Solr cores involved at all. Of course this
was just a simple experiment, YMMV..

Best
Erick

On Tue, Dec 27, 2011 at 11:52 PM, Mikhail Khludnev
<mk...@griddynamics.com> wrote:
> Colleagues,
>
> Don't hesitate to emit your opinion. Please!
>
> Regards
>
> On Wed, Dec 21, 2011 at 11:06 PM, Mikhail Khludnev <
> mkhludnev@griddynamics.com> wrote:
>
>> Hello,
>>
>> I need to introduce several singletons inside of Solr and make them
>> available for my own SearchHandlers, Components, and even QParsers, etc.
>>
>> Right now I use some kind of fake SolrRequestHandler which loads on init()
>> and available everywhere through
>> solrCore.getRequestHandler("wellknownName"). Then I downcast it everywhere
>> and access the required methods. The same is possible with fake
>> SearchComponent.
>> Particularly my singletons are some additional fields schema (pretty
>> sophisticated), and kind of request/response encoding facility.
>> The typical Java hammer for such pins is Spring, but I've found puzzling
>> to use
>> http://static.springframework.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/context/support/WebApplicationContextUtils.html
>>
>> What's the best way to do that?
>>
>> --
>> Sincerely yours
>> Mikhail Khludnev
>> Lucid Certified
>> Apache Lucene/Solr Developer
>> Grid Dynamics
>>
>> <http://www.griddynamics.com>
>>  <mk...@griddynamics.com>
>>
>>
>
>
> --
> Sincerely yours
> Mikhail Khludnev
> Lucid Certified
> Apache Lucene/Solr Developer
> Grid Dynamics
>
> <http://www.griddynamics.com>
>  <mk...@griddynamics.com>

Re: best practice to introducing singletons inside of Solr (IoC)

Posted by Mikhail Khludnev <mk...@griddynamics.com>.
Colleagues,

Don't hesitate to emit your opinion. Please!

Regards

On Wed, Dec 21, 2011 at 11:06 PM, Mikhail Khludnev <
mkhludnev@griddynamics.com> wrote:

> Hello,
>
> I need to introduce several singletons inside of Solr and make them
> available for my own SearchHandlers, Components, and even QParsers, etc.
>
> Right now I use some kind of fake SolrRequestHandler which loads on init()
> and available everywhere through
> solrCore.getRequestHandler("wellknownName"). Then I downcast it everywhere
> and access the required methods. The same is possible with fake
> SearchComponent.
> Particularly my singletons are some additional fields schema (pretty
> sophisticated), and kind of request/response encoding facility.
> The typical Java hammer for such pins is Spring, but I've found puzzling
> to use
> http://static.springframework.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/context/support/WebApplicationContextUtils.html
>
> What's the best way to do that?
>
> --
> Sincerely yours
> Mikhail Khludnev
> Lucid Certified
> Apache Lucene/Solr Developer
> Grid Dynamics
>
> <http://www.griddynamics.com>
>  <mk...@griddynamics.com>
>
>


-- 
Sincerely yours
Mikhail Khludnev
Lucid Certified
Apache Lucene/Solr Developer
Grid Dynamics

<http://www.griddynamics.com>
 <mk...@griddynamics.com>