Java Code Examples for org.apache.commons.pool2.PooledObject#getCreateTime()

The following examples show how to use org.apache.commons.pool2.PooledObject#getCreateTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PooledSocketFactory.java    From timely with Apache License 2.0 5 votes vote down vote up
@Override
public boolean validateObject(PooledObject<Socket> pooledObject) {
    if (connectionTimeToLive > -1) {
        if (System.currentTimeMillis() > pooledObject.getCreateTime() + connectionTimeToLive) {
            return false;
        }
    }
    Socket socket = (Socket) pooledObject.getObject();
    return socket != null && !socket.isClosed();
}
 
Example 2
Source File: ProcessFactory.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void activateObject(PooledObject<PhantomJSProcess> pooledObject) throws Exception
{
	super.activateObject(pooledObject);
	
	PhantomJSProcess process = pooledObject.getObject();
	if (process.hasEnded())
	{
		if (log.isDebugEnabled())
		{
			log.debug(process.getId() + " has ended");
		}
		
		throw new JRRuntimeException("Process " + process.getId() + " has ended");
	}
	
	long borrowedCount = ((DefaultPooledObject<PhantomJSProcess>) pooledObject).getBorrowedCount();
	if (borrowedCount >= expirationCount)
	{
		if (log.isDebugEnabled())
		{
			log.debug(process.getId() + " borrow count " + borrowedCount 
					+ " exceeded expiration count " + expirationCount);
		}
		
		throw new JRRuntimeException("Process " + process.getId() + " borrow count exceeded");
	}
	
	long now = System.currentTimeMillis();
	if (now >= pooledObject.getCreateTime() + expirationTime)
	{
		if (log.isDebugEnabled())
		{
			log.debug(process.getId() + " expiration time " + expirationTime 
					+ " from " + pooledObject.getCreateTime() + " exceeded");
		}
		
		throw new JRRuntimeException("Process " + process.getId() + " expiration time exceeded");
	}
}
 
Example 3
Source File: KeyedCPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
private void validateLifetime(final PooledObject<PooledConnectionAndInfo> p) throws Exception {
    if (maxConnLifetimeMillis > 0) {
        final long lifetime = System.currentTimeMillis() - p.getCreateTime();
        if (lifetime > maxConnLifetimeMillis) {
            throw new Exception(Utils.getMessage("connectionFactory.lifetimeExceeded", Long.valueOf(lifetime),
                    Long.valueOf(maxConnLifetimeMillis)));
        }
    }
}
 
Example 4
Source File: CPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
private void validateLifetime(final PooledObject<PooledConnectionAndInfo> p) throws Exception {
    if (maxConnLifetimeMillis > 0) {
        final long lifetime = System.currentTimeMillis() - p.getCreateTime();
        if (lifetime > maxConnLifetimeMillis) {
            throw new Exception(Utils.getMessage("connectionFactory.lifetimeExceeded", Long.valueOf(lifetime),
                    Long.valueOf(maxConnLifetimeMillis)));
        }
    }
}
 
Example 5
Source File: PoolableConnectionFactory.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
private void validateLifetime(final PooledObject<PoolableConnection> p) throws Exception {
    if (maxConnLifetimeMillis > 0) {
        final long lifetime = System.currentTimeMillis() - p.getCreateTime();
        if (lifetime > maxConnLifetimeMillis) {
            throw new LifetimeExceededException(Utils.getMessage("connectionFactory.lifetimeExceeded",
                    Long.valueOf(lifetime), Long.valueOf(maxConnLifetimeMillis)));
        }
    }
}