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  
18  package org.apache.commons.pool;
19  
20  /**
21   * Factory that creates VisitTracker instances. Used to
22   * test Evictor runs.
23   *
24   */
25  public class VisitTrackerFactory implements PoolableObjectFactory, 
26      KeyedPoolableObjectFactory {
27      private int nextId = 0;
28      public VisitTrackerFactory() {
29          super();
30      }
31      public Object makeObject() {
32          return new VisitTracker(nextId++);
33      }
34      public Object makeObject(Object key) {
35          return new VisitTracker(nextId++, key);
36      }
37      public void destroyObject(Object obj) {
38          ((VisitTracker) obj).destroy();
39      }
40      public void destroyObject(Object key, Object obj) {
41          ((VisitTracker) obj).destroy();
42      }
43      public boolean validateObject(Object obj) {
44          return ((VisitTracker) obj).validate();
45      }
46      public boolean validateObject(Object key, Object obj) {
47          return ((VisitTracker) obj).validate();
48      }
49      public void activateObject(Object obj) throws Exception {
50          ((VisitTracker) obj).activate();
51      }
52      public void activateObject(Object key, Object obj) throws Exception {
53          ((VisitTracker) obj).activate();
54      }
55      public void passivateObject(Object obj) throws Exception {
56          ((VisitTracker) obj).passivate();
57      }
58      public void passivateObject(Object key, Object obj) throws Exception {
59          ((VisitTracker) obj).passivate();
60      }
61      public void resetId() {
62          nextId = 0;
63      }
64  }