Ah, OK, sorry to be terse!

1. Create a class that implements SolrServer from the SolrJ project:
http://lucene.apache.org/solr/4_1_0/solr-solrj/org/apache/solr/client/solrj/SolrServer.html
2. Make the constructor of that class take as arguments the config you
need to make an HttpSolrServer object and store them in member fields.
3. Make a private field for an HttpSolrServer  instance but leave it null.
4. Create a private method called getSolrServer() that creates an
HttpSolrServer and assigns it to the private field and returns it if
successful, otherwise it catches and logs the exception that is
thrown.
5. For each of the methods in SolrServer that you need to override,
have it call getSolrServer() and call the same method on the returned
instance if it's not null, e.g.,

public UpdateResponse add(SolrInputDocument doc)
                   throws SolrServerException,
                          IOException {

  SolrServer solrServer = getSolrServer();
  if (solrServer != null) {
    return solrServer.add(doc);
  }

  return new UpdateResponse();
}

You may want to return something other than an empty UpdateResponse
when things fail. That's up to you.

6. Refactor your project to use your SolrServer implementation.

That should be it!

Michael Della Bitta

------------------------------------------------
Appinions
18 East 41st Street, 2nd Floor
New York, NY 10017-6271

www.appinions.com

Where Influence Isn’t a Game


On Mon, Feb 4, 2013 at 5:05 PM, Shawn Heisey <s...@elyograg.org> wrote:
> On 2/4/2013 2:38 PM, Michael Della Bitta wrote:
>>
>> Hi Shawn,
>>
>> Why don't you write a delegating SolrServer class that lazily
>> instantiates an HttpSolrServer and catches and logs exceptions when
>> something's down?
>
>
> I only about half understood that, and I'm not sure how to do it.  I'm
> willing to learn, though.
>
> Thanks,
> Shawn
>

Reply via email to