@Override public void destroyObject(PooledObject<Object> p) throws Exception { destroyPrototypeInstance(p.getObject()); }
@Override public void activateObject(PooledObject<FTPClient> p) throws Exception { p.getObject().sendNoOp(); }
@Override public void passivateObject(Event.Type key, PooledObject<Event> pooledObject) throws Exception { final Event event = pooledObject.getObject(); switch (event.type) { case BEFORE: unsafe.putObject(event, targetFieldInBeforeEventOffset, null); unsafe.putObject(event, argumentArrayFieldInBeforeEventOffset, null); break; case IMMEDIATELY_THROWS: case THROWS: unsafe.putObject(event, throwableFieldInThrowsEventOffset, null); break; case IMMEDIATELY_RETURN: case RETURN: unsafe.putObject(event, objectFieldInReturnEventOffset, null); } }
@Override public boolean validateObject(PooledObject<T> p) { return p.getObject().isOpen(); } }
@Override public void destroyObject(final PreparedContextKey key, final PooledObject<PreparedContext> p) { PreparedContext cachedContext = p.getObject(); cachedContext.close(); }
@Override public void destroyObject(PooledObject<T> p) throws Exception { p.getObject().close(); }
@Override public void destroyObject(PooledObject<IMetaStoreClient> client) { client.getObject().close(); }
@Override public void destroyObject(final PooledObject<StatefulConnection<byte[], byte[]>> obj) throws Exception { try { obj.getObject().close(); } catch (Exception e) { // Errors may happen if returning a broken resource } }
@Override public boolean validateObject(PooledObject<ShardedJedis> pooledShardedJedis) { try { ShardedJedis jedis = pooledShardedJedis.getObject(); for (Jedis shard : jedis.getAllShards()) { if (!shard.ping().equals("PONG")) { return false; } } return true; } catch (Exception ex) { return false; } }
@Override public void activateObject(PooledObject<Jedis> pooledJedis) throws Exception { final BinaryJedis jedis = pooledJedis.getObject(); if (jedis.getDB() != database) { jedis.select(database); } }
@Override public boolean validateObject(PooledObject<XMPPPacketReader> po) { // reset the input for the pooled parser try { po.getObject().getXPPParser().resetInput(); return true; } catch (XmlPullParserException xppe) { Log.error("Failed to reset pooled parser; evicting from pool", xppe); return false; } }
@Override public void destroyObject( PooledObject<SMPPSession> pooledObject ) throws Exception { final SMPPSession session = pooledObject.getObject(); Log.debug( "Destroying a pooled session with ID '{}'.", session.getSessionId() ); session.unbindAndClose(); }
@Override public boolean validateObject( PooledObject<SMPPSession> pooledObject ) { final SMPPSession session = pooledObject.getObject(); final boolean isValid = session.getSessionState().isTransmittable(); // updated by the SMPPSession internal enquireLink timer. Log.debug( "Ran a check to see if session with ID '{}' is valid. Outcome: {}", session.getSessionId(), isValid ); return isValid; }
@Override public void destroyObject(PooledObject<Jedis> pooledJedis) throws Exception { final BinaryJedis jedis = pooledJedis.getObject(); if (jedis.isConnected()) { try { try { jedis.quit(); } catch (Exception e) { } jedis.disconnect(); } catch (Exception e) { } } }
@Override public void destroyObject(PooledObject<ShardedJedis> pooledShardedJedis) throws Exception { final ShardedJedis shardedJedis = pooledShardedJedis.getObject(); for (Jedis jedis : shardedJedis.getAllShards()) { try { try { jedis.quit(); } catch (Exception e) { } jedis.disconnect(); } catch (Exception e) { } } }
@Override public boolean validateObject(PooledObject<Jedis> pooledJedis) { final BinaryJedis jedis = pooledJedis.getObject(); try { HostAndPort hostAndPort = this.hostAndPort.get(); String connectionHost = jedis.getClient().getHost(); int connectionPort = jedis.getClient().getPort(); return hostAndPort.getHost().equals(connectionHost) && hostAndPort.getPort() == connectionPort && jedis.isConnected() && jedis.ping().equals("PONG"); } catch (final Exception e) { return false; } } }