Client connection closed when using factory pattern


(Hans) #1

When getting the ES client by calling static method Es.getClient() - which
in turn calls static method Es.createClient() to create the client and
populates the corresponding static field if not existing - the
nodesService.closed property of the returned client is true.

When calling static method Es.createClient() directly everything works just
fine.

Has anyone any idea about why this is happening?

Using 0.18.7.

--


(Hans) #2

Seems like JVM by default persists static members between requests - can
anyone confirm this? Quite surprising from my PHP perspective ...

Is there a legal way to check the private nodesService.closed property
w/out using reflection?

--


(Ivan Brusic) #3

Which library are you using? To my knowledge, the official Java library
does not have getClient() or createClient() calls

It would be up to your application to control how a client is
created/accessed/persisted. IMHO, an application should maintain a
singleton instance to an ElasticSearch client. And yes, a static member is
persisted for the lifetime of the JVM. PHP is primarily a web-only
language, so many of its concepts relate to the HTTP request lifecycle. Not
so with the JVM, which is far more than HTTP.

Ivan

On Wed, Oct 17, 2012 at 5:55 AM, Hans hansmandal@googlemail.com wrote:

Seems like JVM by default persists static members between requests - can
anyone confirm this? Quite surprising from my PHP perspective ...

Is there a legal way to check the private nodesService.closed property
w/out using reflection?

--

--


(Hans) #4

Thx for your answer! After being hit by the insight that JVM persists
static members between requests I could easily work around - you just have
to know (as always) ... :slight_smile:

--


(system) #5