xref: /OpenGrok/opengrok-indexer/src/main/java/org/opengrok/indexer/util/ObjectValidator.java (revision d1e826faf91bd41ab1a6d05ec6a5e19cb9865010)
1 /*
2  * The contents of this file are Copyright (c) 2012, Swaranga Sarma, DZone MVB
3  * made available under free license,
4  * http://javawithswaranga.blogspot.com/2011/10/generic-and-concurrent-object-pool.html
5  * https://dzone.com/articles/generic-and-concurrent-object : "Feel free to use
6  * it, change it, add more implementations. Happy coding!"
7  * Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
8  */
9 
10 package org.opengrok.indexer.util;
11 
12 /**
13   * Represents an API for validation of an object of the pool and for its
14   * subsequently cleanup to invalidate it.
15   * @author Swaranga
16   * @param <T> the type of objects to validate and cleanup
17   */
18 public interface ObjectValidator<T> {
19 
20     /**
21      * Checks whether the object is valid.
22      * @param t the object to check.
23      * @return true if the object is valid
24      */
isValid(T t)25     boolean isValid(T t);
26 
27     /**
28      * Performs any cleanup activities
29      * before discarding the object.
30      * For example before discarding
31      * database connection objects,
32      * the pool will want to close the connections.
33      * This is done via the
34      * invalidate() method.
35      * @param t the object to cleanup
36      */
invalidate(T t)37     void invalidate(T t);
38 }
39