1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 module hunt.pool.BasePooledObjectFactory;
18 
19 /**
20  * A base implementation of <code>PoolableObjectFactory</code>.
21  * <p>
22  * All operations defined here are essentially no-op's.
23  * <p>
24  * This class is immutable, and therefore thread-safe
25  *
26  * @param <T> Type of element managed in this factory.
27  *
28  * @see PooledObjectFactory
29  * @see BaseKeyedPooledObjectFactory
30  *
31  */
32 abstract class BasePooledObjectFactory(T) : BaseObject, PooledObjectFactory!(T) {
33     /**
34      * Creates an object instance, to be wrapped in a {@link PooledObject}.
35      * <p>This method <strong>must</strong> support concurrent, multi-threaded
36      * activation.</p>
37      *
38      * @return an instance to be served by the pool
39      *
40      * @throws Exception if there is a problem creating a new instance,
41      *    this will be propagated to the code requesting an object.
42      */
43     abstract T create();
44 
45     /**
46      * Wrap the provided instance with an implementation of
47      * {@link PooledObject}.
48      *
49      * @param obj the instance to wrap
50      *
51      * @return The provided instance, wrapped by a {@link PooledObject}
52      */
53     abstract PooledObject!(T) wrap(T obj);
54 
55     override
56     PooledObject!(T) makeObject(){
57         return wrap(create());
58     }
59 
60     /**
61      *  No-op.
62      *
63      *  @param p ignored
64      */
65     override
66     void destroyObject(PooledObject!(T) p)
67 {
68         // The default implementation is a no-op.
69     }
70 
71     /**
72      * This implementation always returns {@code true}.
73      *
74      * @param p ignored
75      *
76      * @return {@code true}
77      */
78     override
79     bool validateObject(PooledObject!(T) p) {
80         return true;
81     }
82 
83     /**
84      *  No-op.
85      *
86      *  @param p ignored
87      */
88     override
89     void activateObject(PooledObject!(T) p){
90         // The default implementation is a no-op.
91     }
92 
93     /**
94      *  No-op.
95      *
96      * @param p ignored
97      */
98     override
99     void passivateObject(PooledObject!(T) p)
100 {
101         // The default implementation is a no-op.
102     }
103 }