All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fireflysource.common.pool.Pool Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
package com.fireflysource.common.pool;


import com.fireflysource.common.lifecycle.LifeCycle;
import com.fireflysource.common.track.FixedTimeLeakDetector;

import java.util.concurrent.CompletableFuture;

/**
 * Represents a cached pool of objects.
 */
public interface Pool extends LifeCycle {

    /**
     * Get the object asynchronously.
     *
     * @return The pooled object.
     */
    CompletableFuture> poll();

    /**
     * Releases the object and puts it back to the pool.
     * 

* The mechanism of putting the object back to the pool is generally * asynchronous. * * @param pooledObject the object to return to the pool * @return The release future result. */ CompletableFuture release(PooledObject pooledObject); /** * Check the pooled object. If return true, the object is valid. * * @param pooledObject The pooled object * @return if return true, the object is valid. */ boolean isValid(PooledObject pooledObject); /** * Get the current pool size * * @return Current pool size */ int size(); /** * If return true, the pool is empty * * @return If return true, the pool is empty */ boolean isEmpty(); /** * Get the leak detector * * @return the leak detector */ FixedTimeLeakDetector> getLeakDetector(); /** * Get the created object count. * * @return The created object count. */ int getCreatedObjectCount(); /** * Represents the functionality to validate an object of the pool * * @param The pooled object */ @FunctionalInterface interface Validator { /** * Checks whether the object is valid. * * @param pooledObject the object to check. * @return true if the object is valid else false. */ boolean isValid(PooledObject pooledObject); } /** * Cleanup the pooled object * * @param The pooled object */ @FunctionalInterface interface Dispose { /** * Performs any cleanup activities before discarding the object. For * example before discarding database connection objects, the pool will * want to close the connections. * * @param pooledObject the object to cleanup */ void destroy(PooledObject pooledObject); } /** * A factory to create a new object * * @param The pooled object */ @FunctionalInterface interface ObjectFactory { /** * Create a new object in the future. * * @return a new instance of an object of type T. */ CompletableFuture> createNew(Pool pool); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy