001 package org.shiftone.jrat.core; 002 003 004 import org.shiftone.jrat.core.command.CommandletRegistry; 005 import org.shiftone.jrat.core.command.CommandletRegistryFactory; 006 import org.shiftone.jrat.core.jmx.JmxRegistry; 007 import org.shiftone.jrat.core.jmx.JmxRegistryFactory; 008 import org.shiftone.jrat.core.jmx.benchmark.Benchmark; 009 import org.shiftone.jrat.core.jmx.info.JRatInfo; 010 import org.shiftone.jrat.core.output.FileOutputFactory; 011 import org.shiftone.jrat.core.output.FileOutputRegistry; 012 import org.shiftone.jrat.core.shutdown.ShutdownRegistry; 013 import org.shiftone.jrat.inject.bytecode.Transformer; 014 import org.shiftone.jrat.util.log.Logger; 015 import org.shiftone.jrat.util.log.LoggingManager; 016 017 018 /** 019 * @author jeff@shiftone.org (Jeff Drost) 020 */ 021 public class ServiceFactory { 022 023 private static final Logger LOG = Logger.getLogger(ServiceFactory.class); 024 private static ServiceFactory singleton; 025 026 public ServiceFactory() { 027 LOG.info("new"); 028 } 029 030 031 public static synchronized ServiceFactory getInstance() { 032 033 if (singleton == null) { 034 singleton = new ServiceFactory(); 035 } 036 037 return singleton; 038 } 039 040 private CommandletRegistry commandletRegistry; 041 042 public synchronized CommandletRegistry getCommandletRegistry() { 043 044 if (commandletRegistry == null) { 045 046 commandletRegistry = CommandletRegistryFactory.createCommandletRegistry(); 047 048 } 049 050 return commandletRegistry; 051 } 052 053 // -------------------------------------------------------------------- 054 private JmxRegistry jmxRegistry; 055 056 public synchronized JmxRegistry getJmxRegistry() { 057 058 if (jmxRegistry == null) { 059 jmxRegistry = JmxRegistryFactory.createJmxRegistry(); 060 061 jmxRegistry.registerMBean(new JRatInfo(), null); 062 jmxRegistry.registerMBean(new LoggingManager(), null); 063 jmxRegistry.registerMBean(new Benchmark(), null); 064 } 065 066 return jmxRegistry; 067 } 068 069 070 // -------------------------------------------------------------------- 071 private FileOutputRegistry fileOutputRegistry; 072 073 public synchronized FileOutputRegistry getFileOutputRegistry() { 074 075 if (fileOutputRegistry == null) { 076 fileOutputRegistry = new FileOutputRegistry(); 077 078 getJmxRegistry().registerMBean(fileOutputRegistry, null); 079 getShutdownRegistry().registerShutdownListener(fileOutputRegistry); 080 } 081 082 return fileOutputRegistry; 083 } 084 085 086 // -------------------------------------------------------------------- 087 private FileOutputFactory fileOutputFactory; 088 089 public synchronized FileOutputFactory getFileOutputFactory() { 090 091 if (fileOutputFactory == null) { 092 fileOutputFactory = new FileOutputFactory(getFileOutputRegistry()); 093 } 094 095 return fileOutputFactory; 096 } 097 098 099 // -------------------------------------------------------------------- 100 private ShutdownRegistry shutdownRegistry; 101 102 public synchronized ShutdownRegistry getShutdownRegistry() { 103 104 if (shutdownRegistry == null) { 105 shutdownRegistry = new ShutdownRegistry(); 106 107 getJmxRegistry().registerMBean(shutdownRegistry, null); 108 } 109 110 return shutdownRegistry; 111 } 112 113 114 // -------------------------------------------------------------------- 115 private Transformer transformer; 116 117 public synchronized Transformer getTransformer() { 118 119 if (transformer == null) { 120 transformer = new Transformer(); 121 122 getJmxRegistry().registerMBean(transformer, null); 123 getShutdownRegistry().registerShutdownListener(transformer); 124 } 125 126 return transformer; 127 } 128 }