1010import org .apache .catalina .Session ;
1111import org .apache .catalina .session .ManagerBase ;
1212
13+ import org .apache .commons .pool2 .impl .GenericObjectPoolConfig ;
14+ import org .apache .commons .pool2 .impl .BaseObjectPoolConfig ;
15+
1316import redis .clients .util .Pool ;
1417import redis .clients .jedis .JedisPool ;
1518import redis .clients .jedis .JedisSentinelPool ;
@@ -44,6 +47,7 @@ public class RedisSessionManager extends ManagerBase implements Lifecycle {
4447 Set <String > sentinelSet = null ;
4548
4649 protected Pool <Jedis > connectionPool ;
50+ protected JedisPoolConfig connectionPoolConfig = new JedisPoolConfig ();
4751
4852 protected RedisSessionHandlerValve handlerValve ;
4953 protected ThreadLocal <RedisSession > currentSession = new ThreadLocal <>();
@@ -579,16 +583,15 @@ public void processExpires() {
579583
580584 private void initializeDatabaseConnection () throws LifecycleException {
581585 try {
582- // TODO: Allow configuration of pool (such as size...)
583586 if (getSentinelMaster () != null ) {
584587 Set <String > sentinelSet = getSentinelSet ();
585588 if (sentinelSet != null && sentinelSet .size () > 0 ) {
586- connectionPool = new JedisSentinelPool (getSentinelMaster (), sentinelSet , new JedisPoolConfig () , getTimeout (), getPassword ());
589+ connectionPool = new JedisSentinelPool (getSentinelMaster (), sentinelSet , this . connectionPoolConfig , getTimeout (), getPassword ());
587590 } else {
588591 throw new LifecycleException ("Error configuring Redis Sentinel connection pool: expected both `sentinelMaster` and `sentiels` to be configured" );
589592 }
590593 } else {
591- connectionPool = new JedisPool (new JedisPoolConfig () , getHost (), getPort (), getTimeout (), getPassword ());
594+ connectionPool = new JedisPool (this . connectionPoolConfig , getHost (), getPort (), getTimeout (), getPassword ());
592595 }
593596 } catch (Exception e ) {
594597 e .printStackTrace ();
@@ -613,4 +616,152 @@ private void initializeSerializer() throws ClassNotFoundException, IllegalAccess
613616 }
614617 serializer .setClassLoader (classLoader );
615618 }
619+
620+
621+ // Connection Pool Config Accessors
622+
623+ // - from org.apache.commons.pool2.impl.GenericObjectPoolConfig
624+
625+ public int getConnectionPoolMaxTotal () {
626+ return this .connectionPoolConfig .getMaxTotal ();
627+ }
628+
629+ public void setConnectionPoolMaxTotal (int connectionPoolMaxTotal ) {
630+ this .connectionPoolConfig .setMaxTotal (connectionPoolMaxTotal );
631+ }
632+
633+ public int getConnectionPoolMaxIdle () {
634+ return this .connectionPoolConfig .getMaxIdle ();
635+ }
636+
637+ public void setConnectionPoolMaxIdle (int connectionPoolMaxIdle ) {
638+ this .connectionPoolConfig .setMaxIdle (connectionPoolMaxIdle );
639+ }
640+
641+ public int getConnectionPoolMinIdle () {
642+ return this .connectionPoolConfig .getMinIdle ();
643+ }
644+
645+ public void setConnectionPoolMinIdle (int connectionPoolMinIdle ) {
646+ this .connectionPoolConfig .setMinIdle (connectionPoolMinIdle );
647+ }
648+
649+
650+ // - from org.apache.commons.pool2.impl.BaseObjectPoolConfig
651+
652+ public boolean getLifo () {
653+ return this .connectionPoolConfig .getLifo ();
654+ }
655+ public void setLifo (boolean lifo ) {
656+ this .connectionPoolConfig .setLifo (lifo );
657+ }
658+ public long getMaxWaitMillis () {
659+ return this .connectionPoolConfig .getMaxWaitMillis ();
660+ }
661+
662+ public void setMaxWaitMillis (long maxWaitMillis ) {
663+ this .connectionPoolConfig .setMaxWaitMillis (maxWaitMillis );
664+ }
665+
666+ public long getMinEvictableIdleTimeMillis () {
667+ return this .connectionPoolConfig .getMinEvictableIdleTimeMillis ();
668+ }
669+
670+ public void setMinEvictableIdleTimeMillis (long minEvictableIdleTimeMillis ) {
671+ this .connectionPoolConfig .setMinEvictableIdleTimeMillis (minEvictableIdleTimeMillis );
672+ }
673+
674+ public long getSoftMinEvictableIdleTimeMillis () {
675+ return this .connectionPoolConfig .getSoftMinEvictableIdleTimeMillis ();
676+ }
677+
678+ public void setSoftMinEvictableIdleTimeMillis (long softMinEvictableIdleTimeMillis ) {
679+ this .connectionPoolConfig .setSoftMinEvictableIdleTimeMillis (softMinEvictableIdleTimeMillis );
680+ }
681+
682+ public int getNumTestsPerEvictionRun () {
683+ return this .connectionPoolConfig .getNumTestsPerEvictionRun ();
684+ }
685+
686+ public void setNumTestsPerEvictionRun (int numTestsPerEvictionRun ) {
687+ this .connectionPoolConfig .setNumTestsPerEvictionRun (numTestsPerEvictionRun );
688+ }
689+
690+ public boolean getTestOnCreate () {
691+ return this .connectionPoolConfig .getTestOnCreate ();
692+ }
693+
694+ public void setTestOnCreate (boolean testOnCreate ) {
695+ this .connectionPoolConfig .setTestOnCreate (testOnCreate );
696+ }
697+
698+ public boolean getTestOnBorrow () {
699+ return this .connectionPoolConfig .getTestOnBorrow ();
700+ }
701+
702+ public void setTestOnBorrow (boolean testOnBorrow ) {
703+ this .connectionPoolConfig .setTestOnBorrow (testOnBorrow );
704+ }
705+
706+ public boolean getTestOnReturn () {
707+ return this .connectionPoolConfig .getTestOnReturn ();
708+ }
709+
710+ public void setTestOnReturn (boolean testOnReturn ) {
711+ this .connectionPoolConfig .setTestOnReturn (testOnReturn );
712+ }
713+
714+ public boolean getTestWhileIdle () {
715+ return this .connectionPoolConfig .getTestWhileIdle ();
716+ }
717+
718+ public void setTestWhileIdle (boolean testWhileIdle ) {
719+ this .connectionPoolConfig .setTestWhileIdle (testWhileIdle );
720+ }
721+
722+ public long getTimeBetweenEvictionRunsMillis () {
723+ return this .connectionPoolConfig .getTimeBetweenEvictionRunsMillis ();
724+ }
725+
726+ public void setTimeBetweenEvictionRunsMillis (long timeBetweenEvictionRunsMillis ) {
727+ this .connectionPoolConfig .setTimeBetweenEvictionRunsMillis (timeBetweenEvictionRunsMillis );
728+ }
729+
730+ public String getEvictionPolicyClassName () {
731+ return this .connectionPoolConfig .getEvictionPolicyClassName ();
732+ }
733+
734+ public void setEvictionPolicyClassName (String evictionPolicyClassName ) {
735+ this .connectionPoolConfig .setEvictionPolicyClassName (evictionPolicyClassName );
736+ }
737+
738+ public boolean getBlockWhenExhausted () {
739+ return this .connectionPoolConfig .getBlockWhenExhausted ();
740+ }
741+
742+ public void setBlockWhenExhausted (boolean blockWhenExhausted ) {
743+ this .connectionPoolConfig .setBlockWhenExhausted (blockWhenExhausted );
744+ }
745+
746+ public boolean getJmxEnabled () {
747+ return this .connectionPoolConfig .getJmxEnabled ();
748+ }
749+
750+ public void setJmxEnabled (boolean jmxEnabled ) {
751+ this .connectionPoolConfig .setJmxEnabled (jmxEnabled );
752+ }
753+ public String getJmxNameBase () {
754+ return this .connectionPoolConfig .getJmxNameBase ();
755+ }
756+ public void setJmxNameBase (String jmxNameBase ) {
757+ this .connectionPoolConfig .setJmxNameBase (jmxNameBase );
758+ }
759+
760+ public String getJmxNamePrefix () {
761+ return this .connectionPoolConfig .getJmxNamePrefix ();
762+ }
763+
764+ public void setJmxNamePrefix (String jmxNamePrefix ) {
765+ this .connectionPoolConfig .setJmxNamePrefix (jmxNamePrefix );
766+ }
616767}
0 commit comments