001 package org.shiftone.jrat.core.spi; 002 003 004 import org.shiftone.jrat.core.MethodKey; 005 import org.shiftone.jrat.core.shutdown.ShutdownListener; 006 import org.shiftone.jrat.util.log.Logger; 007 008 009 /** 010 * @author jeff@shiftone.org (Jeff Drost) 011 */ 012 public abstract class AbstractMethodHandlerFactory implements MethodHandlerFactory, ShutdownListener { 013 014 private static final Logger LOG = Logger.getLogger(AbstractMethodHandlerFactory.class); 015 private static final String FACTORY_POSTFIX = "Factory"; 016 private RuntimeContext context = null; 017 private String outputFile = getDefaultOutputFile(); 018 019 public abstract MethodHandler createMethodHandler(MethodKey methodKey); 020 021 022 // ------------------------------------------------------------ 023 public RuntimeContext getContext() { 024 return context; 025 } 026 027 028 private String getDefaultOutputFile() { 029 030 Class klass = this.getClass(); 031 String klassName = klass.getName(); 032 int lastDot = klassName.lastIndexOf("."); 033 String name = (lastDot == -1) 034 ? klassName 035 : klassName.substring(lastDot + 1); 036 037 if (name.endsWith(FACTORY_POSTFIX)) { 038 name = name.substring(0, name.length() - FACTORY_POSTFIX.length()); 039 } 040 041 return name + ".jrat"; 042 } 043 044 045 public void setOutputFile(String outputFile) { 046 this.outputFile = outputFile; 047 } 048 049 public String getOutputFile() { 050 return outputFile; 051 } 052 053 054 // ------------------------------------------------------------ 055 public void shutdown() { 056 LOG.info("shutdown"); 057 } 058 059 060 public void flush() { 061 LOG.info("flush"); 062 } 063 064 065 public void startup(RuntimeContext context) throws Exception { 066 067 this.context = context; 068 069 context.registerShutdownListener(this); 070 } 071 }