DESCRIPTION

Update Spring FactoryBean to properly support isSingleton property

Motivation
----------
The current MemcachedClientFactoryBean is marked as a singleton to Spring but
does not respect the flag. It is creating a new instance with every call to
getObject(). According to the Spring Javadoc a FactoryBean marked with
isSingleton true should always return the same reference. By doing this it
will also expose an ability to safely shutdown a client instance.

Modifications
-------------
The class was updated to implement the Spring InitializingBean and
DesposableBean interfaces. These interfaces provide the two key lifecycle
methods to create and shutdown the client object. The afterPropertiesSet is
called after the FactoryBean is constructed and all of the properties have
been set. This will create the client object and store it in a field so the
same reference can be returned. The destroy method is called when closing the
Spring context. It will call the client's shutdown method. I have also added a
new property that allows a caller to specify the number of seconds to wait
before shutting down the client. This is a well established Spring pattern
that is used in many of their own FactoryBean implementations.

Result
------
A more accurate Factory bean that respects the Spring lifecycle and provides
a safe shutdown mechanism.

Change-Id: I9ae2d71ae7d3fe899bce8ec8200e215aa987400d
Reviewed-on: http://review.couchbase.org/44144
Reviewed-by: Natasha Sullivan xxx@xxx.xxx
Tested-by: Natasha Sullivan xxx@xxx.xxx


COMMENTS

author: Natasha Sullivan
date: 2014-12-10 12:03:29.245000000

Change has been successfully cherry-picked as 95833c9927d9996d5f3e781f2441a7df16cb8479

-------------------------------------
