com.avanza.astrix.modules.ObjectCache Maven / Gradle / Ivy
/*
* Copyright 2014 Avanza Bank AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.avanza.astrix.modules;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Manages the life-cycle of each object created by Astrix. Each object created will be cached.
*
* When the object is created (upon cache-miss) the object will be created using the ObjectFactory
* and then the object will be initialized by invoking all @PostConstruct annotated methods.
*
* When the ObjectCache is destroyed all objects in the cache will be destroyed by invoking
* all @PreDestroy annotated methods on every instance in the cache.
*
* @author Elias Lindholm (elilin)
*
*/
public final class ObjectCache {
private static final Logger logger = LoggerFactory.getLogger(ObjectCache.class);
private final ConcurrentMap