001 package org.shiftone.jrat.core.config; 002 003 import org.shiftone.jrat.core.MethodKey; 004 import org.shiftone.jrat.core.spi.MethodHandler; 005 import org.shiftone.jrat.core.spi.MethodHandlerFactory; 006 import org.shiftone.jrat.core.spi.RuntimeContext; 007 import org.shiftone.jrat.util.log.Logger; 008 009 import java.util.HashMap; 010 import java.util.Map; 011 012 /** 013 * @author jeff@shiftone.org (Jeff Drost) 014 */ 015 public class CacheMethodHandlerFactory implements MethodHandlerFactory { 016 017 private static final Logger LOG = Logger.getLogger(CacheMethodHandlerFactory.class); 018 private final MethodHandlerFactory methodHandlerFactory; 019 private Map cache = new HashMap(); 020 021 public CacheMethodHandlerFactory(MethodHandlerFactory methodHandlerFactory) { 022 this.methodHandlerFactory = methodHandlerFactory; 023 } 024 025 public synchronized MethodHandler createMethodHandler(MethodKey methodKey) throws Exception { 026 027 MethodHandler methodHandler = (MethodHandler) cache.get(methodKey); 028 029 if (methodHandler == null) { 030 031 methodHandler = methodHandlerFactory.createMethodHandler(methodKey); 032 033 } 034 035 return methodHandler; 036 } 037 038 public void startup(RuntimeContext context) throws Exception { 039 LOG.info("startup"); 040 methodHandlerFactory.startup(context); 041 } 042 }