@Override public SimpleEntry<ConnectionHandle, Boolean> get() { SimpleEntry<ConnectionHandle, Boolean> result = super.get(); // have we got one that's cached and unused? Mark it as in use. if (result == null || result.getValue()){ // ... otherwise grab a new connection ConnectionHandle fallbackConnection = (ConnectionHandle)this.fallbackStrategy.pollConnection(); if (fallbackConnection == null){ return null; } result = new SimpleEntry<ConnectionHandle, Boolean>(fallbackConnection, false); } result.setValue(true); result.getKey().logicallyClosed.set(false); return result; } }
@Override protected SimpleEntry<ConnectionHandle, Boolean> initialValue() { SimpleEntry<ConnectionHandle, Boolean> result = null; ConnectionHandle c = null; // grab a connection from any other configured fallback strategy for (int i=0; i < 4*3; i++){ // there is a slight race with the pool watch creation thread so spin for a bit // no big deal if it keeps failing, we just switch to default connection strategy c = (ConnectionHandle)this.fallbackStrategy.pollConnection(); if (c != null){ break; } // oh-huh? either we are racing while resizing the pool or else no of threads > no of connections. Let's wait a bit // and try again one last time Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } if (c != null){ result = new SimpleEntry<ConnectionHandle, Boolean>(c, false); this.ccs.threadWatch(c); } return result; }