001 package com.khubla.pragmatach.framework.jmx.impl; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 import org.slf4j.Logger; 007 import org.slf4j.LoggerFactory; 008 009 import com.khubla.pragmatach.framework.application.Application; 010 import com.khubla.pragmatach.framework.controller.Controllers; 011 import com.khubla.pragmatach.framework.jmx.SystemStatusMXBean; 012 import com.khubla.pragmatach.framework.plugin.PluginDescriptor; 013 import com.khubla.pragmatach.framework.plugin.PluginDescriptors; 014 import com.khubla.pragmatach.framework.router.PragmatachRoute; 015 import com.khubla.pragmatach.framework.router.PragmatachRoutes; 016 017 /** 018 * @author tome 019 */ 020 public class SystemStatus implements SystemStatusMXBean { 021 /** 022 * logger 023 */ 024 private final Logger logger = LoggerFactory.getLogger(this.getClass()); 025 026 @Override 027 public String[] getConfiguration() { 028 try { 029 final List<String> configurations = new ArrayList<String>(); 030 for (final String key : Application.getConfiguration().getAll().keySet()) { 031 configurations.add(key + ":" + Application.getConfiguration().getAll().get(key)); 032 } 033 final String[] ret = new String[configurations.size()]; 034 configurations.toArray(ret); 035 return ret; 036 } catch (final Exception e) { 037 logger.error("Exception in getConfiguration", e); 038 return null; 039 } 040 } 041 042 @Override 043 public String[] getControllers() { 044 try { 045 final List<String> controllerDescriptions = new ArrayList<String>(); 046 for (final Class<?> controllerClass : Controllers.getInstance().getControllers()) { 047 controllerDescriptions.add(controllerClass.getName()); 048 } 049 final String[] ret = new String[controllerDescriptions.size()]; 050 controllerDescriptions.toArray(ret); 051 return ret; 052 } catch (final Exception e) { 053 logger.error("Exception in getControllers", e); 054 return null; 055 } 056 } 057 058 @Override 059 public String[] getPlugins() { 060 try { 061 final List<String> pluginDescriptions = new ArrayList<String>(); 062 for (final PluginDescriptor plugin : PluginDescriptors.getPlugins().values()) { 063 pluginDescriptions.add(plugin.getName()); 064 } 065 final String[] ret = new String[pluginDescriptions.size()]; 066 pluginDescriptions.toArray(ret); 067 return ret; 068 } catch (final Exception e) { 069 logger.error("Exception in getPlugins", e); 070 return null; 071 } 072 } 073 074 @Override 075 public String[] getRouters() { 076 try { 077 final List<String> routeDescriptions = new ArrayList<String>(); 078 for (final PragmatachRoute pragmatachRoute : PragmatachRoutes.getInstance().getGETRoutes()) { 079 routeDescriptions.add(pragmatachRoute.getDescription()); 080 } 081 for (final PragmatachRoute pragmatachRoute : PragmatachRoutes.getInstance().getPOSTRoutes()) { 082 routeDescriptions.add(pragmatachRoute.getDescription()); 083 } 084 final String[] ret = new String[routeDescriptions.size()]; 085 routeDescriptions.toArray(ret); 086 return ret; 087 } catch (final Exception e) { 088 logger.error("Exception in getRouters", e); 089 return null; 090 } 091 } 092 }