001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.pool; 019 020 /** 021 * Factory that creates VisitTracker instances. Used to 022 * test Evictor runs. 023 * 024 */ 025 public class VisitTrackerFactory implements PoolableObjectFactory, 026 KeyedPoolableObjectFactory { 027 private int nextId = 0; 028 public VisitTrackerFactory() { 029 super(); 030 } 031 public Object makeObject() { 032 return new VisitTracker(nextId++); 033 } 034 public Object makeObject(Object key) { 035 return new VisitTracker(nextId++, key); 036 } 037 public void destroyObject(Object obj) { 038 ((VisitTracker) obj).destroy(); 039 } 040 public void destroyObject(Object key, Object obj) { 041 ((VisitTracker) obj).destroy(); 042 } 043 public boolean validateObject(Object obj) { 044 return ((VisitTracker) obj).validate(); 045 } 046 public boolean validateObject(Object key, Object obj) { 047 return ((VisitTracker) obj).validate(); 048 } 049 public void activateObject(Object obj) throws Exception { 050 ((VisitTracker) obj).activate(); 051 } 052 public void activateObject(Object key, Object obj) throws Exception { 053 ((VisitTracker) obj).activate(); 054 } 055 public void passivateObject(Object obj) throws Exception { 056 ((VisitTracker) obj).passivate(); 057 } 058 public void passivateObject(Object key, Object obj) throws Exception { 059 ((VisitTracker) obj).passivate(); 060 } 061 public void resetId() { 062 nextId = 0; 063 } 064 }