xetorthio/jedis — pull request #462 by HeartSaVioR (2013-09-26 01:58:10+00:00)
Title: Let JedisSentinelPool take care of multi-failover (cleaned ver. of #460)

This pull request is for cleaning dirty commits from #460 into one.

Belows are copied from #460.
----
This pull request issues Pool class.

Below is Pool's initPool() implementation.

```java
public void initPool(final GenericObjectPool.Config poolConfig, PoolableObjectFactory factory) {
if (this.internalPool != null) {
try {
destroy();
} catch (Exception e) {
}
}

this.internalPool = new GenericObjectPool(factory, poolConfig);
}
```

Pool class is just wrapper of GenericObjectPool, so initPool()'s behavior seems fine.
But another classes that extends Pool may have additional things, and these have to clean up when destroy() called.
JedisSentinelPool has additional things, MasterListeners, and destroy() cleans up MasterListeners.
MasterListeners are independent from Pool(means internalPool) itself, so reinitialize internalPool should not affect MasterListeners.
And if initPool() has to clean up additional things, extended classes are responsible to take care of it.

In Pool.initPool(), it should not call destroy() methods.
Because when using JedisSentinelPool object, JedisSentinelPool.destroy() called and affect MasterListeners!

We can replace destroy() in Pool.initPool() to other method that cleans up internal pool.

```java
public void initPool(final GenericObjectPool.Config poolConfig, PoolableObjectFactory factory) {
if (this.internalPool != null) {
try {
closeInternalPool();
} catch (Exception e) {
}
}

this.internalPool = new GenericObjectPool(factory, poolConfig);
}

public void destroy() {
closeInternalPool();
}

protected void closeInternalPool() {
try {
internalPool.close();
} catch (Exception e) {
throw new JedisException("Could not destroy the pool", e);
}
}
```

Modifying Pool class does not need restarting MasterListeners, and fix #459, and everything is OK.

I modified unit test to failover twice and success.
To run failover twice without external operation, master needs to have two slaves. (another one)
I configured Makefile and pom.xml, HostAndPortUtil, etc.