1 26 package com.lutris.appserver.server; 27 28 import java.io.IOException ; 29 import java.lang.reflect.Constructor ; 30 import java.lang.reflect.Method ; 31 import java.util.Enumeration ; 32 import java.util.Hashtable ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 import java.util.ListIterator ; 36 import java.util.StringTokenizer ; 37 38 import javax.management.Attribute ; 39 import javax.management.AttributeChangeNotification ; 40 import javax.management.AttributeList ; 41 import javax.management.AttributeNotFoundException ; 42 import javax.management.DynamicMBean ; 43 import javax.management.InvalidAttributeValueException ; 44 import javax.management.MBeanAttributeInfo ; 45 import javax.management.MBeanConstructorInfo ; 46 import javax.management.MBeanException ; 47 import javax.management.MBeanInfo ; 48 import javax.management.MBeanNotificationInfo ; 49 import javax.management.MBeanOperationInfo ; 50 import javax.management.MBeanParameterInfo ; 51 import javax.management.MBeanServer ; 52 import javax.management.MBeanServerFactory ; 53 import javax.management.Notification ; 54 import javax.management.NotificationBroadcasterSupport ; 55 import javax.management.ObjectName ; 56 import javax.management.ReflectionException ; 57 import javax.management.RuntimeOperationsException ; 58 import javax.servlet.Servlet ; 59 import javax.servlet.ServletContext ; 60 import javax.servlet.ServletException ; 61 import javax.servlet.http.HttpServletRequest ; 62 import javax.servlet.http.HttpServletResponse ; 63 64 import org.enhydra.util.ConfigFileInterface; 65 import org.enhydra.util.DOTable; 66 import org.enhydra.util.Utils; 67 import org.enhydra.util.EafConfigMBean; 68 import org.enhydra.util.jivan.JivanFactory; 69 import org.enhydra.xml.xmlc.XMLCFactory; 70 import org.enhydra.xml.xmlc.XMLCStdFactory; 71 import org.enhydra.xml.xmlc.deferredparsing.DocumentLoaderImpl; 72 import org.enhydra.xml.xmlc.deferredparsing.XMLCDeferredParsingFactory; 73 74 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException; 75 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 76 import com.lutris.appserver.server.httpPresentation.HttpPresentationException; 77 import com.lutris.appserver.server.httpPresentation.HttpPresentationManager; 78 import com.lutris.appserver.server.session.MemoryPersistence; 79 import com.lutris.appserver.server.session.Session; 80 import com.lutris.appserver.server.session.SessionException; 81 import com.lutris.appserver.server.session.SessionManager; 82 import com.lutris.appserver.server.sessionEnhydra.StandardSessionManager; 83 import com.lutris.appserver.server.sql.DatabaseManager; 84 import com.lutris.classloader.MultiClassLoader; 85 import com.lutris.logging.EnhydraXMLCLogger; 86 import com.lutris.logging.LogChannel; 87 import com.lutris.logging.Logger; 88 import com.lutris.util.Config; 89 import com.lutris.util.KeywordValueException; 90 91 98 public abstract class StandardApplication 99 implements Application { 100 103 private static final String sysConLoggerName = "SysOut"; 104 private static final String STANDARD_DATABASE_MANAGER_CLASS_NAME = 105 "com.lutris.appserver.server.sql.StandardDatabaseManager"; 106 109 protected boolean sendCookieForNewSession = true; 110 114 protected String appName = null; 115 119 protected int state = STOPPED; 120 125 protected SessionManager sessionManager; 126 130 protected HttpPresentationManager presentationManager; 131 136 protected DatabaseManager databaseManager; 137 143 protected Config config; 144 150 protected String defaultUrl; 151 154 protected LogChannel logChannel; 155 protected Logger logger; 156 159 protected static LogChannel loggerSys; 160 163 protected ApplicationData data = new ApplicationData(); 164 167 protected XMLCFactory xmlcFactory; 168 169 172 protected JivanFactory jivanFactory; 173 174 175 protected MBeanServer server = null; 176 protected ApplicationConfigMBean appConfigMBean; 177 protected DatabaseManagerMBean databaseManagerMBean; 178 protected PresentationManagerMBean presentationManagerMBean; 179 protected SessionManagerMBean sessionManagerMBean; 180 protected DatabaseMBean databaseMBean; 181 protected TableMBean tableMBean; 182 protected ContextMBean contextMBean; 183 184 188 private boolean isMemoryPersistence = false; 189 190 193 public StandardApplication() {} 194 195 202 public int getState() { 203 return state; 204 } 205 206 212 public void setCookieForNewSession(boolean flag) { 213 sendCookieForNewSession = flag; 214 } 215 216 222 public Config getConfig() { 223 return config; 224 } 225 226 231 public void setName(String applName) { 232 appName = applName; 233 } 234 235 243 public String getName() { 244 return appName; 245 } 246 247 252 public void setLogChannel(LogChannel chan) { 253 logChannel = chan; 254 } 255 256 262 public LogChannel getLogChannel() { 263 return logChannel; 264 } 265 266 275 public synchronized void startup(Config appConfig) throws 276 ApplicationException { 277 if (state == RUNNING) { 278 return; } 280 printCopyrightHeader(); 281 284 Config sessionConfig, databaseConfig = null; 285 try { 286 if (appConfig.containsKey("Application")) { 287 defaultUrl = appConfig.getString("Application.DefaultUrl"); 288 } 289 sessionConfig = (Config) appConfig.getSection("SessionManager"); 290 } 293 catch (KeywordValueException except) { 294 throw new ApplicationException(except); 295 } 296 try { 298 databaseConfig = (Config) appConfig.getSection("DatabaseManager"); 299 if (databaseConfig != null && appName != null) { 300 databaseConfig.set("DatabaseManager.AppName", (Object ) appName); 301 } 302 } catch (KeywordValueException except) { 303 logChannel.write(Logger.DEBUG, 304 "Application configured without DatabaseManager."); 305 } 306 307 310 sessionManager = createSessionManager(sessionConfig); 311 312 315 boolean hasDatabaseConfig = databaseConfig != null; 316 317 if (hasDatabaseConfig) { 318 databaseManager = createDatabaseManager(databaseConfig); 319 } 320 321 324 config = appConfig; 325 326 329 registerApplicationMBean(); 330 registerSessionManagerMBean(); 331 registerPresentationManagerMBean(); 332 registerContextMBean(); 333 334 if (hasDatabaseConfig) { 335 registerDatabaseManagerMBean(); 336 registerTableMBeans(); 337 String [] dbNames = databaseManager.getLogicalDatabaseNames(); 338 for (int i=0;i<dbNames.length;i++){ 339 registerDatabaseMBean(dbNames[i]); 340 } 341 } 342 343 state = RUNNING; 344 } 345 346 public void printCopyrightHeader() { 347 351 } 352 353 365 public synchronized void restartup(Config appConfig) throws 366 ApplicationException { 367 throw new ApplicationException("no support for INCOMPLETE state"); 368 } 369 370 374 public synchronized void shutdown() { 375 if (state == STOPPED) { 376 return; } 378 379 try{ 381 unRegisterApplicationMBean(); 382 unRegisterSessionManagerMBean(); 383 unRegisterPresentationManagerMBean(); 384 unRegisterDatabaseManagerMBean(); 385 unRegisterContextMBean(); 386 387 if (databaseManager!=null) { 388 unRegisterTableMBeans(); 389 unRegisterDatabaseManagerMBean(); 390 String [] dbNames = databaseManager.getLogicalDatabaseNames(); 391 for (int i=0;i<dbNames.length;i++){ 392 unRegisterDatabaseMBean(dbNames[i]); 393 } 394 } 395 396 }catch (Exception e) { 397 logChannel.write(Logger.DEBUG, e.toString()); 398 } 399 400 if (sessionManager != null) { 401 sessionManager.shutdown(); 402 sessionManager = null; 403 } 404 if (databaseManager != null) { 405 databaseManager.shutdown(); 406 databaseManager = null; 407 } 408 409 state = STOPPED; 410 } 411 412 413 417 public synchronized void shutdownWithoutMBeanUnRegistration() { 418 if (state == STOPPED) { 419 return; } 421 422 if (sessionManager != null) { 423 sessionManager.shutdown(); 424 sessionManager = null; 425 } 426 if (databaseManager != null) { 427 databaseManager.shutdown(); 428 databaseManager = null; 429 } 430 431 state = STOPPED; 432 } 433 434 448 protected SessionManager createSessionManager(Config sessionMgrConfig) throws 449 ApplicationException { 450 if (sessionMgrConfig == null) { 451 sessionMgrConfig = new Config(); 452 } 453 try { 454 458 String sessionMgr; 459 if (sessionMgrConfig.containsKey("Class")) { 460 sessionMgr = sessionMgrConfig.getString("Class"); 461 } 462 else { 463 sessionMgr = 464 "com.lutris.appserver.server.sessionEnhydra.StandardSessionManager"; 465 } 466 Class sessionMgrClass = Class.forName(sessionMgr); 467 Class [] constructorParameterTypes = new Class [3]; 468 constructorParameterTypes[0] = Class.forName( 469 "com.lutris.appserver.server.Application"); 470 constructorParameterTypes[1] = Class.forName("com.lutris.util.Config"); 471 constructorParameterTypes[2] = Class.forName( 472 "com.lutris.logging.LogChannel"); 473 Constructor sessionMgrConstructor = sessionMgrClass.getConstructor( 474 constructorParameterTypes); 475 if (sessionMgrConfig.containsKey("MemoryPersistence")) { 476 String mp = sessionMgrConfig.getString("MemoryPersistence"); 477 if (mp.equals("true")) { 478 isMemoryPersistence = true; 479 } 480 } 481 SessionManager sm = null; 482 if (this.appName != null) { 483 sm = MemoryPersistence.getSessionManager(this.appName); 484 } 485 if (isMemoryPersistence && (sm != null)) { 486 return sm; 487 } 488 else { 489 Object [] parameters = new Object [3]; 491 parameters[0] = this; 492 parameters[1] = sessionMgrConfig; 493 parameters[2] = logChannel; 494 SessionManager sessionManager = (SessionManager) sessionMgrConstructor. 495 newInstance(parameters); 496 return sessionManager; 497 } 498 } 499 catch (Exception except) { 500 throw new ApplicationException(except); 501 } 502 } 503 504 516 protected DatabaseManager createDatabaseManager(Config databaseMgrConfig) throws 517 ApplicationException { 518 try { 519 String databaseMgr; 520 if (databaseMgrConfig.containsKey("Class")) { 521 databaseMgr = databaseMgrConfig.getString("Class"); 522 } 523 else { 524 databaseMgr = 525 STANDARD_DATABASE_MANAGER_CLASS_NAME; 526 } 527 Class standardDbManagerClass = Class.forName(databaseMgr); 528 Class [] ArgClassArray = new Class [] { 529 Config.class 530 }; 531 Object [] ArgObject = new Object [] { 532 databaseMgrConfig 533 }; 534 Constructor standardDbManager = standardDbManagerClass. 535 getDeclaredConstructor(ArgClassArray); 536 return (DatabaseManager) (standardDbManager.newInstance(ArgObject)); 537 } 538 catch (Exception except) { 539 throw new ApplicationException(except); 540 } 541 } 542 543 557 protected Session createSession(HttpPresentationComms comms) throws 558 ApplicationException { 559 try { 560 return sessionManager.createSession(comms); 561 } 562 catch (Exception exception) { 563 throw new ApplicationException(exception); 564 } 565 } 566 567 586 protected void ensureSession(HttpPresentationComms comms) throws 587 ApplicationException { 588 try { 589 if (presentationManager.isPresentationRequest(comms.request)) { 590 comms.session = StandardAppUtil.getRequestSession(comms); 592 } 593 if (comms.session != null && 594 sessionManager.sessionExists(comms.session.getSessionKey())) { 595 603 comms.sessionData = comms.session.getSessionData(); 604 } 605 else { 606 if (presentationManager.isPresentationRequest(comms.request)) { 607 initializeNewSession(comms); 608 } 609 } 610 } 611 catch (HttpPresentationException except) { 612 throw new ApplicationException(except); 613 } 614 catch (SessionException except) { 615 throw new ApplicationException(except); 616 } 617 } 618 619 629 public void requestPostProcessor(HttpPresentationComms comms) throws 630 ApplicationException { 631 try { 632 if (comms.session != null) { 633 comms.application.getSessionManager().passivateSession(Thread. 634 currentThread(), 635 comms.session.getSessionKey()); 636 } 637 } 638 catch (SessionException e) { 639 throw new ApplicationException(e); 640 } 641 } 642 643 664 protected void initializeNewSession(HttpPresentationComms comms) throws 665 ApplicationException { 666 comms.session = createSession(comms); 667 if (sendCookieForNewSession) { 668 StandardAppUtil.bindSessionToClient(comms); 669 } 670 comms.sessionData = comms.session.getSessionData(); 671 } 672 673 679 public String encodeUrl(String url, String sessionKey) throws 680 ApplicationException { 681 return StandardAppUtil.encodeUrl(url, sessionKey); 682 } 683 684 691 public String encodeUrl(String url, String sessionKey, String appName) throws 692 ApplicationException { 693 return StandardAppUtil.encodeUrl(url, sessionKey); 694 } 695 696 717 public boolean requestPreprocessor(HttpPresentationComms comms) throws 718 Exception { 719 722 if (defaultUrl != null) { 723 String ap = comms.request.getApplicationPath(); 724 if (!ap.endsWith("/")) { 725 ap += "/"; 726 } 727 String page = comms.request.getPresentationObjectPath(); 728 if (!page.endsWith("/")) { 729 page += "/"; 730 } 731 if (page.equals(ap)) { 732 String target = comms.request.getHttpServletRequest().getContextPath(); 734 if (target.equals("/")) { 735 target = ""; 736 } 737 target = ""; 738 if (defaultUrl.startsWith("/")) { 739 target += ap + defaultUrl.substring(1); 740 } 741 else { 742 target += ap + defaultUrl; 743 } 744 String query = comms.request.getQueryString(); 746 if (query != null) { 747 target += "?" + query; 748 } 749 750 753 if (StandardAppUtil.getRequestSession(comms) == null){ 754 initializeNewSession(comms); 755 } 756 757 761 try { 762 if (sessionManager instanceof StandardSessionManager){ 763 if (((StandardSessionManager)sessionManager).getEncodeFirstUrl()){ 764 comms.request.setRequestedSessionIdFromUrl(true); 765 } 766 } 767 } catch (Throwable trowable){} 768 769 throw new ClientPageRedirectException(target); 770 } 771 } 772 ensureSession(comms); 774 return false; } 776 777 784 public SessionManager getSessionManager() { 785 return sessionManager; 786 } 787 788 795 public DatabaseManager getDatabaseManager() { 796 return databaseManager; 797 } 798 799 805 public HttpPresentationManager getHttpPresentationManager() { 806 return presentationManager; 807 } 808 809 816 public void setHttpPresentationManager(HttpPresentationManager pm) { 817 presentationManager = pm; 818 } 819 820 852 public boolean servletRequestPreprocessor(Servlet servlet, 853 ServletContext context, 854 HttpServletRequest request, 855 HttpServletResponse response) throws 856 ServletException , 857 IOException { 858 return false; 859 } 860 861 864 public XMLCFactory getXMLCFactory() { 865 return xmlcFactory; 866 } 867 868 871 public void setXMLCFactory(boolean enableDeferredParsing) { 872 if (enableDeferredParsing) { 873 xmlcFactory = new XMLCDeferredParsingFactory(new DocumentLoaderImpl(), 874 (MultiClassLoader) presentationManager.getAppClassLoader(), 875 new EnhydraXMLCLogger(logChannel)); 876 } 877 else { 878 xmlcFactory = new XMLCStdFactory(presentationManager.getAppClassLoader(), 879 new EnhydraXMLCLogger(logChannel)); 880 } 881 } 882 883 888 public void setJivanFactory(boolean reload) { 889 this.jivanFactory = new JivanFactory(reload, this.logChannel); 890 } 891 892 895 public JivanFactory getJivanFactory() { 896 return this.jivanFactory; 897 } 898 899 900 903 private MBeanServer findMBeanServer() throws com.lutris.appserver.server. 904 session.SessionException { 905 MBeanServer mBeanServer; 906 try { 907 java.util.ArrayList server = MBeanServerFactory.findMBeanServer(null); 908 if (server == null) { 909 return null; 910 } 911 else { 912 mBeanServer = (MBeanServer ) server.get(0); 913 } 914 } 915 catch (Exception e) { 916 throw new com.lutris.appserver.server.session.SessionException(e); 917 } 918 return mBeanServer; 919 } 920 921 924 public String toHtml() { 925 return "No Application Info"; 926 } 927 928 936 937 private void registerApplicationMBean(){ 938 if (appName == null) { 939 return; 940 } 941 942 try { 943 server = findMBeanServer(); 944 if (server == null) { 945 return; 946 } 947 } 948 catch (Exception e) { 949 logChannel.write(Logger.DEBUG, e.toString()); 950 } 951 952 try { 953 String applicationName = appName; 954 955 ObjectName objectName = new ObjectName ("EnhydraApplications:type=ApplicationConfig,name=" 956 + applicationName); 957 958 if (!server.isRegistered(objectName)) { 959 String [] includes = null; 960 String [] excludes = {"SessionManager", "PresentationManager", "DatabaseManager"}; 961 appConfigMBean = new ApplicationConfigMBean(this,objectName,null,includes,excludes); 962 server.registerMBean(appConfigMBean, objectName); 963 } 964 965 } 966 catch (Exception e) { 967 logChannel.write(Logger.DEBUG, e.toString()); 968 return; 969 } 970 } 971 972 private void unRegisterApplicationMBean(){ 973 if (appName == null) { 974 return; 975 } 976 977 try { 978 server = findMBeanServer(); 979 if (server == null) { 980 return; 981 } 982 } 983 catch (Exception e) { 984 logChannel.write(Logger.DEBUG, e.toString()); 985 } 986 987 try { 988 String applicationName = appName; 989 990 ObjectName objectName = new ObjectName ("EnhydraApplications:type=ApplicationConfig,name=" 991 + applicationName); 992 993 if (server.isRegistered(objectName)) { 994 server.unregisterMBean(objectName); 995 } 996 997 } 998 catch (Exception e) { 999 logChannel.write(Logger.DEBUG, e.toString()); 1000 return; 1001 } 1002 } 1003 1004 1007 private class ApplicationConfigMBean extends EafConfigMBean{ 1008 public ApplicationConfigMBean (Application application, 1009 ObjectName objectName, String prefix, 1010 String [] includes, String [] excludes){ 1011 super(application,objectName,prefix,includes,excludes); 1012 buildDynamicMBeanInfo(); 1013 } 1014 1015 1018 public void setAttribute(Attribute attribute) throws 1019 AttributeNotFoundException , 1020 InvalidAttributeValueException , MBeanException , ReflectionException { 1021 1022 super.setAttribute(attribute); 1023 1024 shutdownWithoutMBeanUnRegistration(); 1026 try { 1027 startup(config); 1028 } 1029 catch (Exception e) { 1030 logChannel.write(Logger.DEBUG, e.toString()); 1031 } 1032 } 1033 1034 1037 public Object invoke(String operationName, Object params[], 1038 String signature[]) throws MBeanException , 1039 ReflectionException { 1040 if (operationName == null) { 1042 throw new RuntimeOperationsException (new IllegalArgumentException ( 1043 "Operation name cannot be null"), 1044 "Cannot invoke a null operation in " + dClassName); 1045 } 1046 if (operationName.equals("getConfig")) { 1048 return config; 1049 } else{ 1050 return super.invoke(operationName, params, signature); 1052 } 1053 } 1054 1055 1059 protected MBeanOperationInfo [] getMBeanOperationsInfo () { 1060 MBeanParameterInfo [] params = null; 1061 MBeanOperationInfo [] dOperations = new MBeanOperationInfo [6]; 1062 dOperations[0] = new MBeanOperationInfo ("reset", 1063 "reset(): reset attributes to their initial values", 1064 params, "void", 1065 MBeanOperationInfo.ACTION); 1066 dOperations[1] = new MBeanOperationInfo ("saveAttributes", 1067 "saveAttributes(): save the attribute values into the configuration file", 1068 params, "void", 1069 MBeanOperationInfo.ACTION); 1070 dOperations[2] = new MBeanOperationInfo ("getAppInfo", 1071 "getAppInfo(): get application information", 1072 params, "String", 1073 MBeanOperationInfo.ACTION); 1074 1075 params = new MBeanParameterInfo [2]; 1076 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 1077 "use UNDERLINE (_) as attribute group separator."); 1078 params[1] = new MBeanParameterInfo ("attValue","java.lang.String","Attribute value!"); 1079 1080 dOperations[3] = new MBeanOperationInfo ("addAttribute", 1081 "addAttribute(String key, String value): add new application parameter", 1082 params, "void", 1083 MBeanOperationInfo.ACTION); 1084 1085 params = new MBeanParameterInfo [1]; 1086 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 1087 "use UNDERLINE (_) as attribute group separator."); 1088 1089 dOperations[4] = new MBeanOperationInfo ("removeAttribute", 1090 "removeAttribute(String key): remove application parameter", 1091 params, "void", 1092 MBeanOperationInfo.ACTION); 1093 1094 params = null; 1095 1096 dOperations[5] = new MBeanOperationInfo ("getConfig", 1097 "getConfig(): Gets actual application Config object.", 1098 params, "com.lutris.util.Config", 1099 MBeanOperationInfo.ACTION); 1100 1101 return dOperations; 1102 } 1103 1104 } 1105 1106 private void registerSessionManagerMBean(){ 1107 if (appName == null) { 1108 return; 1109 } 1110 1111 try { 1112 server = findMBeanServer(); 1113 if (server == null) { 1114 return; 1115 } 1116 } 1117 catch (Exception e) { 1118 logChannel.write(Logger.DEBUG, e.toString()); 1119 } 1120 1121 try { 1122 String applicationName = appName; 1123 1124 ObjectName objectName = new ObjectName ("EnhydraApplications:type=SessionManager,name=" 1125 + applicationName); 1126 1127 if (!server.isRegistered(objectName)) { 1128 String [] includes = {"SessionManager"}; 1129 String [] excludes = null; 1130 sessionManagerMBean = new SessionManagerMBean(this,objectName,"SessionManager",includes,excludes); 1131 server.registerMBean(sessionManagerMBean, objectName); 1132 } 1133 1134 } 1135 catch (Exception e) { 1136 logChannel.write(Logger.DEBUG, e.toString()); 1137 return; 1138 } 1139 } 1140 1141 private void unRegisterSessionManagerMBean(){ 1142 if (appName == null) { 1143 return; 1144 } 1145 1146 try { 1147 server = findMBeanServer(); 1148 if (server == null) { 1149 return; 1150 } 1151 } 1152 catch (Exception e) { 1153 logChannel.write(Logger.DEBUG, e.toString()); 1154 } 1155 1156 try { 1157 String applicationName = appName; 1158 1159 ObjectName objectName = new ObjectName ("EnhydraApplications:type=SessionManager,name=" 1160 + applicationName); 1161 1162 if (server.isRegistered(objectName)) { 1163 server.unregisterMBean(objectName); 1164 } 1165 1166 } 1167 catch (Exception e) { 1168 logChannel.write(Logger.DEBUG, e.toString()); 1169 return; 1170 } 1171 } 1172 1173 1176 private class SessionManagerMBean extends EafConfigMBean{ 1177 public SessionManagerMBean (Application application, 1178 ObjectName objectName, String prefix, 1179 String [] includes, String [] excludes){ 1180 super(application,objectName,prefix,includes,excludes); 1181 buildDynamicMBeanInfo(); 1182 } 1183 1184 1187 public void setAttribute(Attribute attribute) throws 1188 AttributeNotFoundException , 1189 InvalidAttributeValueException , MBeanException , ReflectionException { 1190 1191 super.setAttribute(attribute); 1192 1193 shutdownWithoutMBeanUnRegistration(); 1195 try { 1196 startup(config); 1197 } 1198 catch (Exception e) { 1199 logChannel.write(Logger.DEBUG, e.toString()); 1200 } 1201 } 1202 1203 1206 public Object invoke(String operationName, Object params[], 1207 String signature[]) throws MBeanException , 1208 ReflectionException { 1209 if (operationName.equals("sessionExists")) { 1211 boolean temp = false; 1212 try { 1213 if (params!=null && params.length==1){ 1214 temp = sessionManager.sessionExists((String )params[0]); 1215 } 1216 return new Boolean (temp); 1217 }catch (Exception e) { 1218 throw new MBeanException (e); 1219 } 1220 } else if (operationName.equals("activeSessionCount")) { 1221 int temp = 0; 1222 try { 1223 temp = sessionManager.activeSessionCount(); 1224 return new Integer (temp); 1225 }catch (Exception e){ 1226 throw new MBeanException (e); 1227 } 1228 } else if (operationName.equals("getSessionKeys")) { 1229 Enumeration temp = null; 1230 try { 1231 temp = sessionManager.getSessionKeys(); 1232 return temp; 1233 }catch (Exception e){ 1234 throw new MBeanException (e); 1235 } 1236 } else if (operationName.equals("getSession")) { 1237 Session temp = null; 1238 try { 1239 if (params!=null && params.length==1){ 1240 temp = sessionManager.getSession((String )params[0]); 1241 } 1242 return temp; 1243 }catch (Exception e){ 1244 throw new MBeanException (e); 1245 } 1246 } else if (operationName.equals("getSessionManager")) { 1247 try { 1248 return sessionManager; 1249 }catch (Exception e){ 1250 throw new MBeanException (e); 1251 } 1252 } else if (operationName.equals("getEncodeUrlState")) { 1253 try { 1254 return sessionManager.getEncodeUrlState(); 1255 }catch (Exception e){ 1256 throw new MBeanException (e); 1257 } 1258 } else if (operationName.equals("createSession")) { 1259 try { 1260 Session sesion = null; 1261 if (params!=null && params.length==1){ 1262 sesion = sessionManager.createSession((String )params[0]); 1263 } 1264 return sesion; 1265 }catch (Exception e){ 1266 throw new MBeanException (e); 1267 } 1268 } else if (operationName.equals("deleteSession")) { 1269 try { 1270 if (params!=null && params.length==1){ 1271 sessionManager.deleteSession((String )params[0]); 1272 } 1273 return null; 1274 }catch (Exception e){ 1275 throw new MBeanException (e); 1276 } 1277 } else{ 1278 return super.invoke(operationName, params, signature); 1280 } 1281 } 1282 1283 1287 protected MBeanOperationInfo [] getMBeanOperationsInfo () { 1288 1289 boolean includeAdditional = true; 1290 if (hashAttrib.containsKey("Class")){ 1291 String value = (String ) hashAttrib.get("Class"); 1292 if ("com.lutris.appserver.server.sessionContainerAdapter.ContainerAdapterSessionManager".equals(value) 1293 ||"com.lutris.appserver.server.sessionContainerAdapter.JmxContainerAdapterSessionManager".equals(value)){ 1294 includeAdditional = false; 1295 } 1296 } 1297 1298 MBeanParameterInfo [] params = null; 1299 MBeanOperationInfo [] dOperations = null; 1300 if (includeAdditional){ 1301 dOperations = new MBeanOperationInfo [13]; 1302 } else { 1303 dOperations = new MBeanOperationInfo [7]; 1304 } 1305 1306 dOperations[0] = new MBeanOperationInfo ("reset", 1307 "reset(): reset attributes to their initial values", 1308 params, "void", 1309 MBeanOperationInfo.ACTION); 1310 dOperations[1] = new MBeanOperationInfo ("saveAttributes", 1311 "saveAttributes(): save the attribute values into the configuration file", 1312 params, "void", 1313 MBeanOperationInfo.ACTION); 1314 dOperations[2] = new MBeanOperationInfo ("getAppInfo", 1315 "getAppInfo(): get application information", 1316 params, "String", 1317 MBeanOperationInfo.ACTION); 1318 1319 params = new MBeanParameterInfo [2]; 1320 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 1321 "use UNDERLINE (_) as attribute group separator."); 1322 params[1] = new MBeanParameterInfo ("attValue","java.lang.String","Attribute value!"); 1323 1324 dOperations[3] = new MBeanOperationInfo ("addAttribute", 1325 "addAttribute(String key, String value): add new application parameter", 1326 params, "void", 1327 MBeanOperationInfo.ACTION); 1328 1329 params = new MBeanParameterInfo [1]; 1330 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 1331 "use UNDERLINE (_) as attribute group separator."); 1332 1333 dOperations[4] = new MBeanOperationInfo ("removeAttribute", 1334 "removeAttribute(String key): remove application parameter", 1335 params, "void", 1336 MBeanOperationInfo.ACTION); 1337 1338 params = null; 1339 1340 dOperations[5] = new MBeanOperationInfo ("getSessionManager", 1341 "getSessionManager(): " + 1342 "Get an SessionManager object.", 1343 params, "com.lutris.appserver.server.session.SessionManager", 1344 MBeanOperationInfo.ACTION); 1345 1346 dOperations[6] = new MBeanOperationInfo ("getEncodeUrlState", 1347 "getEncodeUrlState(): " + 1348 "Get the value indicating the url encoding status.", 1349 params, "com.lutris.appserver.server.session.SessionManager", 1350 MBeanOperationInfo.ACTION); 1351 1352 if (includeAdditional){ 1353 dOperations[7] = new MBeanOperationInfo ("activeSessionCount", 1354 "activeSessionCount(): " + 1355 "Gets the number of currently active sessions.", 1356 params, "int", 1357 MBeanOperationInfo.ACTION); 1358 1359 dOperations[8] = new MBeanOperationInfo ("getSessionKeys", 1360 "getSessionKeys(): " + 1361 "Get an enumeration of all session keys. ", 1362 params, "java.util.Enumeration", 1363 MBeanOperationInfo.ACTION); 1364 1365 params = new MBeanParameterInfo [1]; 1366 params[0] = new MBeanParameterInfo ("sessionKey","java.lang.String", 1367 "The String used to reference a Session object."); 1368 1369 dOperations[9] = new MBeanOperationInfo ("sessionExists", 1370 "sessionExists(String sessionKey): " + 1371 "Returns whether the Session object " + 1372 "associated with the specified session key exists", 1373 params, "boolean", 1374 MBeanOperationInfo.ACTION); 1375 1376 dOperations[10] = new MBeanOperationInfo ("getSession", 1377 "getSession(String sessionKey): " + 1378 "Returns the Session object associated with the " + 1379 "specified session key. The session is put in the " + 1380 "ACTIVE state.", 1381 params, "com.lutris.appserver.server.session.Session", 1382 MBeanOperationInfo.ACTION); 1383 1384 dOperations[11] = new MBeanOperationInfo ("createSession", 1385 "createSession(String sessionKey): " + 1386 "Create a new Session object and an associated " + 1387 "unique random key. No <CODE>User</CODE> object is " + 1388 "initially associated with the session", 1389 params, "com.lutris.appserver.server.session.Session", 1390 MBeanOperationInfo.ACTION); 1391 1392 dOperations[12] = new MBeanOperationInfo ("deleteSession", 1393 "deleteSession(String sessionKey): " + 1394 "Removes a session from the manager.", 1395 params, "com.lutris.appserver.server.session.Session", 1396 MBeanOperationInfo.ACTION); 1397 } 1398 return dOperations; 1399 } 1400 1401 } 1402 1403 1404 private void registerPresentationManagerMBean(){ 1405 if (appName == null) { 1406 return; 1407 } 1408 1409 try { 1410 server = findMBeanServer(); 1411 if (server == null) { 1412 return; 1413 } 1414 } 1415 catch (Exception e) { 1416 logChannel.write(Logger.DEBUG, e.toString()); 1417 } 1418 1419 try { 1420 String applicationName = appName; 1421 1422 ObjectName objectName = new ObjectName ("EnhydraApplications:type=PresentationManager,name=" 1423 + applicationName); 1424 1425 if (!server.isRegistered(objectName)) { 1426 String [] includes = {"PresentationManager"}; 1427 String [] excludes = null; 1428 presentationManagerMBean = new PresentationManagerMBean(this,objectName,"PresentationManager",includes,excludes); 1429 server.registerMBean(presentationManagerMBean, objectName); 1430 } 1431 1432 } 1433 catch (Exception e) { 1434 logChannel.write(Logger.DEBUG, e.toString()); 1435 return; 1436 } 1437 } 1438 1439 private void unRegisterPresentationManagerMBean(){ 1440 if (appName == null) { 1441 return; 1442 } 1443 1444 try { 1445 server = findMBeanServer(); 1446 if (server == null) { 1447 return; 1448 } 1449 } 1450 catch (Exception e) { 1451 logChannel.write(Logger.DEBUG, e.toString()); 1452 } 1453 1454 try { 1455 String applicationName = appName; 1456 1457 ObjectName objectName = new ObjectName ("EnhydraApplications:type=PresentationManager,name=" 1458 + applicationName); 1459 1460 if (server.isRegistered(objectName)) { 1461 server.unregisterMBean(objectName); 1462 } 1463 1464 } 1465 catch (Exception e) { 1466 logChannel.write(Logger.DEBUG, e.toString()); 1467 return; 1468 } 1469 } 1470 1471 1474 private class PresentationManagerMBean extends EafConfigMBean{ 1475 1476 1479 public PresentationManagerMBean (Application application, 1480 ObjectName objectName, String prefix, 1481 String [] includes, String [] excludes){ 1482 super(application,objectName,prefix,includes,excludes); 1483 buildDynamicMBeanInfo(); 1484 } 1485 1486 1489 public void setAttribute(Attribute attribute) throws 1490 AttributeNotFoundException , 1491 InvalidAttributeValueException , MBeanException , ReflectionException { 1492 1493 super.setAttribute(attribute); 1494 1495 shutdownWithoutMBeanUnRegistration(); 1497 try { 1498 startup(config); 1499 } 1500 catch (Exception e) { 1501 logChannel.write(Logger.DEBUG, e.toString()); 1502 } 1503 } 1504 1505 1508 public Object invoke(String operationName, Object params[], 1509 String signature[]) throws MBeanException , 1510 ReflectionException { 1511 if (operationName.equals("flushCache")) { 1513 try { 1514 presentationManager.flushCache(); 1515 }catch (Exception e) { 1516 throw new MBeanException (e); 1517 } 1518 return null; 1519 } else if (operationName.equals("sizeofPOCache")) { 1520 int temp = 0; 1521 try { 1522 temp = presentationManager.sizeofPOCache(); 1523 }catch (Exception e) { 1524 throw new MBeanException (e); 1525 } 1526 return new Integer (temp); 1527 } else if (operationName.equals("sizeofResourceCache")) { 1528 int temp = 0; 1529 try { 1530 temp = presentationManager.sizeofResourceCache(); 1531 }catch (Exception e) { 1532 throw new MBeanException (e); 1533 } 1534 return new Integer (temp); 1535 } else if (operationName.equals("addMimeType")) { 1536 if (params!=null && params.length==2){ 1537 presentationManager.addMimeType((String )params[0],(String )params[1]); 1538 } 1539 return null; 1540 } else if (operationName.equals("getPresentationManager")) { 1541 try { 1542 return presentationManager; 1543 }catch (Exception e) { 1544 throw new MBeanException (e); 1545 } 1546 } else{ 1547 return super.invoke(operationName, params, signature); 1549 } 1550 } 1551 1552 1556 protected MBeanOperationInfo [] getMBeanOperationsInfo () { 1557 MBeanParameterInfo [] params = null; 1558 MBeanOperationInfo [] dOperations = new MBeanOperationInfo [10]; 1559 dOperations[0] = new MBeanOperationInfo ("reset", 1560 "reset(): reset attributes to their initial values", 1561 params, "void", 1562 MBeanOperationInfo.ACTION); 1563 dOperations[1] = new MBeanOperationInfo ("saveAttributes", 1564 "saveAttributes(): save the attribute values into the configuration file", 1565 params, "void", 1566 MBeanOperationInfo.ACTION); 1567 dOperations[2] = new MBeanOperationInfo ("getAppInfo", 1568 "getAppInfo(): get application information", 1569 params, "String", 1570 MBeanOperationInfo.ACTION); 1571 1572 params = new MBeanParameterInfo [2]; 1573 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 1574 "use UNDERLINE (_) as attribute group separator."); 1575 params[1] = new MBeanParameterInfo ("attValue","java.lang.String","Attribute value!"); 1576 1577 dOperations[3] = new MBeanOperationInfo ("addAttribute", 1578 "addAttribute(String key, String value): add new application parameter", 1579 params, "void", 1580 MBeanOperationInfo.ACTION); 1581 1582 params = new MBeanParameterInfo [1]; 1583 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 1584 "use UNDERLINE (_) as attribute group separator."); 1585 1586 dOperations[4] = new MBeanOperationInfo ("removeAttribute", 1587 "removeAttribute(String key): remove application parameter", 1588 params, "void", 1589 MBeanOperationInfo.ACTION); 1590 1591 params = null; 1592 1593 dOperations[5] = new MBeanOperationInfo ("getPresentationManager", 1594 "getPresentationManager(): Gets actual PresentationManager object reference.", 1595 params, "com.lutris.appserver.server.httpPresentation.HttpPresentationManager", 1596 MBeanOperationInfo.ACTION); 1597 1598 dOperations[6] = new MBeanOperationInfo ("flushCache", 1599 "flushCache(): Flush the presentation object and resource caches", 1600 params, "void", 1601 MBeanOperationInfo.ACTION); 1602 1603 dOperations[7] = new MBeanOperationInfo ("sizeofPOCache", 1604 "sizeofPOCache(): the number of entries in the cache or 0 is disabled", 1605 params, "int", 1606 MBeanOperationInfo.ACTION); 1607 1608 dOperations[8] = new MBeanOperationInfo ("sizeofResourceCache", 1609 "sizeofResourceCache(): number of entries in the cache or 0 is disabled", 1610 params, "int", 1611 MBeanOperationInfo.ACTION); 1612 1613 params = new MBeanParameterInfo [2]; 1614 params[0] = new MBeanParameterInfo ("mimeType","java.lang.String", 1615 "Mime Type you want to add!"); 1616 params[1] = new MBeanParameterInfo ("extension","java.lang.String", 1617 "Extension of Mime Type you want to add!"); 1618 1619 dOperations[9] = new MBeanOperationInfo ("addMimeType", 1620 "addMimeType(String mimeType, String extension): Add a new mime type to extension mapping.", 1621 params, "void", 1622 MBeanOperationInfo.ACTION); 1623 1624 return dOperations; 1625 } 1626 1627 } 1628 1629 1630 private void registerDatabaseManagerMBean(){ 1631 if (appName == null) { 1632 return; 1633 } 1634 1635 try { 1636 server = findMBeanServer(); 1637 if (server == null) { 1638 return; 1639 } 1640 } 1641 catch (Exception e) { 1642 logChannel.write(Logger.DEBUG, e.toString()); 1643 } 1644 1645 try { 1646 String applicationName = appName; 1647 1648 ObjectName objectName = new ObjectName ("EnhydraApplications:type=DatabaseManager,name=" 1649 + applicationName); 1650 1651 if (!server.isRegistered(objectName)) { 1652 String [] includes = {"DatabaseManager"}; 1653 String [] excludes = {"DatabaseManager_DB"}; 1654 databaseManagerMBean = new DatabaseManagerMBean(this,objectName,"DatabaseManager",includes,excludes); 1655 server.registerMBean(databaseManagerMBean, objectName); 1656 } 1657 1658 } 1659 catch (Exception e) { 1660 logChannel.write(Logger.DEBUG, e.toString()); 1661 return; 1662 } 1663 } 1664 1665 private void unRegisterDatabaseManagerMBean(){ 1666 if (appName == null) { 1667 return; 1668 } 1669 1670 try { 1671 server = findMBeanServer(); 1672 if (server == null) { 1673 return; 1674 } 1675 } 1676 catch (Exception e) { 1677 logChannel.write(Logger.DEBUG, e.toString()); 1678 } 1679 1680 try { 1681 String applicationName = appName; 1682 1683 ObjectName objectName = new ObjectName ("EnhydraApplications:type=DatabaseManager,name=" 1684 + applicationName); 1685 1686 if (server.isRegistered(objectName)) { 1687 server.unregisterMBean(objectName); 1688 } 1689 1690 } 1691 catch (Exception e) { 1692 logChannel.write(Logger.DEBUG, e.toString()); 1693 return; 1694 } 1695 } 1696 1697 1700 private class DatabaseManagerMBean extends EafConfigMBean{ 1701 public DatabaseManagerMBean (Application application, 1702 ObjectName objectName, String prefix, 1703 String [] includes, String [] excludes){ 1704 super(application,objectName,prefix,includes,excludes); 1705 buildDynamicMBeanInfo(); 1706 } 1707 1708 1711 public void setAttribute(Attribute attribute) throws 1712 AttributeNotFoundException , 1713 InvalidAttributeValueException , MBeanException , ReflectionException { 1714 1715 super.setAttribute(attribute); 1716 1717 shutdownWithoutMBeanUnRegistration(); 1719 try { 1720 startup(config); 1721 } 1722 catch (Exception e) { 1723 logChannel.write(Logger.DEBUG, e.toString()); 1724 } 1725 } 1726 1727 1730 public Object invoke(String operationName, Object params[], 1731 String signature[]) throws MBeanException , 1732 ReflectionException { 1733 if (operationName == null) { 1735 throw new RuntimeOperationsException (new IllegalArgumentException ( 1736 "Operation name cannot be null"), 1737 "Cannot invoke a null operation in " + dClassName); 1738 } 1739 if (operationName.equals("Toggle_EnableOrDisable_Cache")) { 1741 try { 1742 return enableDisableCaching(); 1743 }catch (Exception e) { 1744 throw new MBeanException (e); 1745 } 1746 } else if (operationName.equals("Enable_Cache")) { 1747 try { 1748 return enableCaching(); 1749 }catch (Exception e) { 1750 throw new MBeanException (e); 1751 } 1752 } else if (operationName.equals("Disable_Cache")) { 1753 try { 1754 return disableCaching(); 1755 }catch (Exception e) { 1756 throw new MBeanException (e); 1757 } 1758 } else if (operationName.equals("Refresh_Cache")) { 1759 try { 1760 return refreshCache(); 1761 }catch (Exception e) { 1762 throw new MBeanException (e); 1763 } 1764 } else if (operationName.equals("Refresh_Statistics")) { 1765 try { 1766 return refreshStatistics(); 1767 }catch (Exception e) { 1768 throw new MBeanException (e); 1769 } 1770 } else if (operationName.equals("getDatabaseManager")) { 1771 return databaseManager; 1772 } else{ 1773 return super.invoke(operationName, params, signature); 1775 } 1776 } 1777 1778 1782 protected MBeanOperationInfo [] getMBeanOperationsInfo () { 1783 MBeanParameterInfo [] params = null; 1784 MBeanOperationInfo [] dOperations = new MBeanOperationInfo [11]; 1785 dOperations[0] = new MBeanOperationInfo ("reset", 1786 "reset(): reset attributes to their initial values", 1787 params, "void", 1788 MBeanOperationInfo.ACTION); 1789 dOperations[1] = new MBeanOperationInfo ("saveAttributes", 1790 "saveAttributes(): save the attribute values into the configuration file", 1791 params, "void", 1792 MBeanOperationInfo.ACTION); 1793 dOperations[2] = new MBeanOperationInfo ("getAppInfo", 1794 "getAppInfo(): get application information", 1795 params, "String", 1796 MBeanOperationInfo.ACTION); 1797 1798 params = new MBeanParameterInfo [2]; 1799 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 1800 "use UNDERLINE (_) as attribute group separator."); 1801 params[1] = new MBeanParameterInfo ("attValue","java.lang.String","Attribute value!"); 1802 1803 dOperations[3] = new MBeanOperationInfo ("addAttribute", 1804 "addAttribute(String key, String value): add new application parameter", 1805 params, "void", 1806 MBeanOperationInfo.ACTION); 1807 1808 params = new MBeanParameterInfo [1]; 1809 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 1810 "use UNDERLINE (_) as attribute group separator."); 1811 1812 dOperations[4] = new MBeanOperationInfo ("removeAttribute", 1813 "removeAttribute(String key): remove application parameter", 1814 params, "void", 1815 MBeanOperationInfo.ACTION); 1816 1817 params = null; 1818 1819 dOperations[5] = new MBeanOperationInfo ("getDatabaseManager", 1820 "getDatabaseManager(): Gets actual application DatabaseManager object.", 1821 params, "com.lutris.appserver.server.sql.DatabaseManager", 1822 MBeanOperationInfo.ACTION); 1823 1824 dOperations[6] = new MBeanOperationInfo ("Refresh_Cache", 1825 "refreshCache(): Refresh DatabaseManager Cache.", 1826 params, "java.lang.String", 1827 MBeanOperationInfo.ACTION); 1828 1829 dOperations[7] = new MBeanOperationInfo ("Refresh_Statistics", 1830 "refreshStatistics(): Refresh DatabaseManager Statistics.", 1831 params, "java.lang.String", 1832 MBeanOperationInfo.ACTION); 1833 1834 dOperations[8] = new MBeanOperationInfo ("Enable_Cache", 1835 "enableCaching(): Enables DatabaseManager Cache Status.", 1836 params, "java.lang.String", 1837 MBeanOperationInfo.ACTION); 1838 1839 dOperations[9] = new MBeanOperationInfo ("Disable_Cache", 1840 "disableCaching(): Disables DatabaseManager Cache Status.", 1841 params, "java.lang.String", 1842 MBeanOperationInfo.ACTION); 1843 1844 dOperations[10] = new MBeanOperationInfo ("Toggle_EnableOrDisable_Cache", 1845 "enableDisableCaching(): Toggles DatabaseManager Cache Status.", 1846 params, "java.lang.String", 1847 MBeanOperationInfo.ACTION); 1848 1849 return dOperations; 1850 } 1851 1852 private String enableDisableCaching() { 1853 String retString = TableMBean.TABLE + 1854 TableMBean.CAPTION + TableMBean.BOLD + 1855 TableMBean.COLOUR + TableMBean.BLUE + 1856 "DatabaseManagar" + TableMBean.E_COLOUR + 1857 TableMBean.E_BOLD + TableMBean.E_CAPTION; 1858 1859 int length = tableMBeans.size(); 1860 Enumeration objectNames = tableMBeans.keys(); 1861 for (int i=0;i<length;i++){ 1862 String keyName = (String ) objectNames.nextElement(); 1863 retString = retString+TableMBean.ROW; 1864 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 1865 retString = retString+TableMBean.DATA+ 1866 TableMBean.BOLD + TableMBean.COLOUR + 1867 TableMBean.BLUE + keyName + 1868 TableMBean.E_COLOUR + TableMBean.E_BOLD + 1869 TableMBean.E_DATA; 1870 1871 retString = retString+TableMBean.DATA+ 1872 tableMBean.enableDisableCaching()+TableMBean.E_DATA; 1873 } 1874 1875 retString = retString+TableMBean.E_TABLE; 1876 1877 return retString; 1878 } 1879 1880 private String enableCaching() { 1881 String retString = null; 1882 int length = tableMBeans.size(); 1883 Enumeration objectNames = tableMBeans.keys(); 1884 for (int i=0;i<length;i++){ 1885 String keyName = (String ) objectNames.nextElement(); 1886 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 1887 retString = tableMBean.enableCaching(); 1888 } 1889 return retString; 1890 } 1891 1892 private String disableCaching() { 1893 String retString = null; 1894 int length = tableMBeans.size(); 1895 Enumeration objectNames = tableMBeans.keys(); 1896 for (int i=0;i<length;i++){ 1897 String keyName = (String ) objectNames.nextElement(); 1898 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 1899 retString = tableMBean.disableCaching(); 1900 } 1901 return retString; 1902 } 1903 1904 private String refreshCache() { 1905 String retString = null; 1906 int length = tableMBeans.size(); 1907 Enumeration objectNames = tableMBeans.keys(); 1908 for (int i=0;i<length;i++){ 1909 String keyName = (String ) objectNames.nextElement(); 1910 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 1911 retString = tableMBean.refreshCache(); 1912 } 1913 return retString; 1914 } 1915 1916 private String refreshStatistics() { 1917 String retString = null; 1918 int length = tableMBeans.size(); 1919 Enumeration objectNames = tableMBeans.keys(); 1920 for (int i=0;i<length;i++){ 1921 String keyName = (String ) objectNames.nextElement(); 1922 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 1923 retString = tableMBean.refreshStatistics(); 1924 } 1925 return retString; 1926 } 1927 } 1928 1929 1930 private void registerDatabaseMBean(String dbName){ 1931 if (appName == null) { 1932 return; 1933 } 1934 1935 try { 1936 server = findMBeanServer(); 1937 if (server == null) { 1938 return; 1939 } 1940 } 1941 catch (Exception e) { 1942 logChannel.write(Logger.DEBUG, e.toString()); 1943 } 1944 1945 try { 1946 String applicationName = appName; 1947 1948 ObjectName objectName = new ObjectName ("EnhydraApplications:type=Database-"+dbName+",name=" + applicationName); 1949 1950 if (!server.isRegistered(objectName)) { 1951 String [] includes = {"DatabaseManager_DB_"+dbName}; 1952 1953 String [] excludes; 1954 1955 int length = tableMBeans.size(); 1956 java.util.Vector temp = new java.util.Vector (); 1957 Enumeration keys = tableMBeans.keys(); 1958 for (int i=0;i<length;i++){ 1959 String key = (String ) keys.nextElement(); 1960 if (key.startsWith(dbName)){ 1961 temp.add(key); 1962 } 1963 } 1964 1965 if (temp.isEmpty()){ 1966 excludes = null; 1967 } else { 1968 excludes = new String [temp.size()]; 1969 for (int i=0;i<temp.size();i++){ 1970 excludes[i]="DatabaseManager_DB_"+(String )temp.elementAt(i); 1971 } 1972 } 1973 1974 databaseMBean = new DatabaseMBean(dbName,this,objectName,"DatabaseManager_DB_"+dbName,includes,excludes); 1975 server.registerMBean(databaseMBean, objectName); 1976 } 1977 1978 } 1979 catch (Exception e) { 1980 logChannel.write(Logger.DEBUG, e.toString()); 1981 return; 1982 } 1983 } 1984 1985 private void unRegisterDatabaseMBean(String dbName){ 1986 if (appName == null) { 1987 return; 1988 } 1989 1990 try { 1991 server = findMBeanServer(); 1992 if (server == null) { 1993 return; 1994 } 1995 } 1996 catch (Exception e) { 1997 logChannel.write(Logger.DEBUG, e.toString()); 1998 } 1999 2000 try { 2001 String applicationName = appName; 2002 2003 ObjectName objectName = new ObjectName ("EnhydraApplications:type=Database-"+dbName+",name=" + applicationName); 2004 2005 if (server.isRegistered(objectName)) { 2006 server.unregisterMBean(objectName); 2007 } 2008 2009 } 2010 catch (Exception e) { 2011 logChannel.write(Logger.DEBUG, e.toString()); 2012 return; 2013 } 2014 } 2015 2016 2017 2020 private class DatabaseMBean extends EafConfigMBean{ 2021 2022 protected String dbName = null; 2023 2024 public DatabaseMBean (Application application, 2025 ObjectName objectName, String prefix, 2026 String [] includes, String [] excludes){ 2027 super(application,objectName,prefix,includes,excludes); 2028 buildDynamicMBeanInfo(); 2029 } 2030 2031 public DatabaseMBean (String dbName, 2032 Application application, 2033 ObjectName objectName, String prefix, 2034 String [] includes, String [] excludes){ 2035 super(application,objectName,prefix,includes,excludes); 2036 this.dbName = dbName; 2037 buildDynamicMBeanInfo(); 2038 } 2039 2040 2043 public void setAttribute(Attribute attribute) throws 2044 AttributeNotFoundException , 2045 InvalidAttributeValueException , MBeanException , ReflectionException { 2046 2047 super.setAttribute(attribute); 2048 2049 shutdownWithoutMBeanUnRegistration(); 2051 try { 2052 startup(config); 2053 } 2054 catch (Exception e) { 2055 logChannel.write(Logger.DEBUG, e.toString()); 2056 } 2057 } 2058 2059 2062 public Object invoke(String operationName, Object params[], 2063 String signature[]) throws MBeanException , 2064 ReflectionException { 2065 if (operationName == null) { 2067 throw new RuntimeOperationsException (new IllegalArgumentException ( 2068 "Operation name cannot be null"), 2069 "Cannot invoke a null operation in " + dClassName); 2070 } 2071 if (operationName.equals("Toggle_EnableOrDisable_Cache")) { 2073 try { 2074 return enableDisableCaching(); 2075 }catch (Exception e) { 2076 throw new MBeanException (e); 2077 } 2078 } else if (operationName.equals("Enable_Cache")) { 2079 try { 2080 return enableCaching(); 2081 }catch (Exception e) { 2082 throw new MBeanException (e); 2083 } 2084 } else if (operationName.equals("Disable_Cache")) { 2085 try { 2086 return disableCaching(); 2087 }catch (Exception e) { 2088 throw new MBeanException (e); 2089 } 2090 } else if (operationName.equals("Refresh_Cache")) { 2091 try { 2092 return refreshCache(); 2093 }catch (Exception e) { 2094 throw new MBeanException (e); 2095 } 2096 } else if (operationName.equals("Refresh_Statistics")) { 2097 try { 2098 return refreshStatistics(); 2099 }catch (Exception e) { 2100 throw new MBeanException (e); 2101 } 2102 } else if (operationName.equals("getDatabase")) { 2103 try { 2104 return databaseManager.findLogicalDatabase(dbName); 2105 }catch (Exception e) { 2106 throw new MBeanException (e); 2107 } 2108 } else{ 2109 return super.invoke(operationName, params, signature); 2111 } 2112 } 2113 2114 2118 protected MBeanConstructorInfo [] getMBeanConstructorInfo () { 2119 MBeanParameterInfo [] dParameters = new MBeanParameterInfo [6]; 2120 dParameters[0] = new MBeanParameterInfo ("dbName","java.lang.String","Database Name"); 2121 dParameters[1] = new MBeanParameterInfo ("application","com.lutris.appserver.server.Application","Application Object"); 2122 dParameters[2] = new MBeanParameterInfo ("objectName","javax.management.ObjectName","MBean Name Object"); 2123 dParameters[3] = new MBeanParameterInfo ("prefix","java.lang.String","Configuration Parameter Prefix"); 2124 dParameters[4] = new MBeanParameterInfo ("includes","java.lang.reflect.Array","Array of internal parameter prefixes to include"); 2125 dParameters[5] = new MBeanParameterInfo ("excludes","java.lang.reflect.Array","Array of internal parameter prefixes to exclude"); 2126 2127 MBeanConstructorInfo [] dConstructors = new MBeanConstructorInfo [1]; 2128 dConstructors[0] = new MBeanConstructorInfo ("DatabaseMBean", 2129 "ConfigMBean Object Constructor", 2130 dParameters); 2131 2132 return dConstructors; 2133 } 2134 2135 2139 protected MBeanOperationInfo [] getMBeanOperationsInfo () { 2140 MBeanParameterInfo [] params = null; 2141 MBeanOperationInfo [] dOperations = new MBeanOperationInfo [11]; 2142 dOperations[0] = new MBeanOperationInfo ("reset", 2143 "reset(): reset attributes to their initial values", 2144 params, "void", 2145 MBeanOperationInfo.ACTION); 2146 dOperations[1] = new MBeanOperationInfo ("saveAttributes", 2147 "saveAttributes(): save the attribute values into the configuration file", 2148 params, "void", 2149 MBeanOperationInfo.ACTION); 2150 dOperations[2] = new MBeanOperationInfo ("getAppInfo", 2151 "getAppInfo(): get application information", 2152 params, "String", 2153 MBeanOperationInfo.ACTION); 2154 2155 params = new MBeanParameterInfo [2]; 2156 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 2157 "use UNDERLINE (_) as attribute group separator."); 2158 params[1] = new MBeanParameterInfo ("attValue","java.lang.String","Attribute value!"); 2159 2160 dOperations[3] = new MBeanOperationInfo ("addAttribute", 2161 "addAttribute(String key, String value): add new application parameter", 2162 params, "void", 2163 MBeanOperationInfo.ACTION); 2164 2165 params = new MBeanParameterInfo [1]; 2166 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 2167 "use UNDERLINE (_) as attribute group separator."); 2168 2169 dOperations[4] = new MBeanOperationInfo ("removeAttribute", 2170 "removeAttribute(String key): remove application parameter", 2171 params, "void", 2172 MBeanOperationInfo.ACTION); 2173 2174 params = null; 2175 2176 dOperations[5] = new MBeanOperationInfo ("getDatabase", 2177 "getDatabase(): Gets actual Database object.", 2178 params, "com.lutris.appserver.server.sql.LogicalDatabase", 2179 MBeanOperationInfo.ACTION); 2180 2181 dOperations[6] = new MBeanOperationInfo ("Refresh_Cache", 2182 "refreshCache(): Refresh Database Cache.", 2183 params, "java.lang.String", 2184 MBeanOperationInfo.ACTION); 2185 2186 dOperations[7] = new MBeanOperationInfo ("Refresh_Statistics", 2187 "refreshStatistics(): Refresh Database Statistics.", 2188 params, "java.lang.String", 2189 MBeanOperationInfo.ACTION); 2190 2191 dOperations[8] = new MBeanOperationInfo ("Enable_Cache", 2192 "enableCaching(): Enables Database Cache Status.", 2193 params, "java.lang.String", 2194 MBeanOperationInfo.ACTION); 2195 2196 dOperations[9] = new MBeanOperationInfo ("Disable_Cache", 2197 "disableCaching(): Disables Database Cache Status.", 2198 params, "java.lang.String", 2199 MBeanOperationInfo.ACTION); 2200 2201 dOperations[10] = new MBeanOperationInfo ("Toggle_EnableOrDisable_Cache", 2202 "enableDisableCaching(): Toggles Database Cache Status.", 2203 params, "java.lang.String", 2204 MBeanOperationInfo.ACTION); 2205 2206 return dOperations; 2207 } 2208 2209 2210 private String enableDisableCaching() { 2211 String retString = TableMBean.TABLE + 2212 TableMBean.CAPTION + TableMBean.BOLD + 2213 TableMBean.COLOUR + TableMBean.BLUE + 2214 "Database " + dbName + TableMBean.E_COLOUR + 2215 TableMBean.E_BOLD + TableMBean.E_CAPTION; 2216 2217 int length = tableMBeans.size(); 2218 Enumeration objectNames = tableMBeans.keys(); 2219 for (int i=0;i<length;i++){ 2220 String keyName = (String ) objectNames.nextElement(); 2221 if (keyName.startsWith(dbName+DOT)) { 2222 retString = retString+TableMBean.ROW; 2223 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 2224 retString = retString+TableMBean.DATA+ 2225 TableMBean.BOLD + TableMBean.COLOUR + 2226 TableMBean.BLUE + tableMBean.tableName + 2227 TableMBean.E_COLOUR + TableMBean.E_BOLD + 2228 TableMBean.E_DATA; 2229 2230 retString = retString+TableMBean.DATA+ 2231 tableMBean.enableDisableCaching()+TableMBean.E_DATA; 2232 } 2233 } 2234 2235 retString = retString+TableMBean.E_TABLE; 2236 2237 return retString; 2238 } 2239 2240 private String enableCaching() { 2241 String retString = null; 2242 int length = tableMBeans.size(); 2243 Enumeration objectNames = tableMBeans.keys(); 2244 for (int i=0;i<length;i++){ 2245 String keyName = (String ) objectNames.nextElement(); 2246 if (keyName.startsWith(dbName+DOT)) { 2247 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 2248 retString = tableMBean.enableCaching(); 2249 } 2250 } 2251 return retString; 2252 } 2253 2254 private String disableCaching() { 2255 String retString = null; 2256 int length = tableMBeans.size(); 2257 Enumeration objectNames = tableMBeans.keys(); 2258 for (int i=0;i<length;i++){ 2259 String keyName = (String ) objectNames.nextElement(); 2260 if (keyName.startsWith(dbName+DOT)) { 2261 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 2262 retString = tableMBean.disableCaching(); 2263 } 2264 } 2265 return retString; 2266 } 2267 2268 private String refreshCache() { 2269 String retString = null; 2270 int length = tableMBeans.size(); 2271 Enumeration objectNames = tableMBeans.keys(); 2272 for (int i=0;i<length;i++){ 2273 String keyName = (String ) objectNames.nextElement(); 2274 if (keyName.startsWith(dbName+DOT)) { 2275 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 2276 retString = tableMBean.refreshCache(); 2277 } 2278 } 2279 return retString; 2280 } 2281 2282 private String refreshStatistics() { 2283 String retString = null; 2284 int length = tableMBeans.size(); 2285 Enumeration objectNames = tableMBeans.keys(); 2286 for (int i=0;i<length;i++){ 2287 String keyName = (String ) objectNames.nextElement(); 2288 if (keyName.startsWith(dbName+DOT)) { 2289 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 2290 retString = tableMBean.refreshStatistics(); 2291 } 2292 } 2293 return retString; 2294 } 2295 2296 } 2297 2298 2299 2300 protected Hashtable tableMBeans = new Hashtable (); 2301 2302 private void registerTableMBeans() { 2303 List listDOClasses = Utils.getCachedDOClassesForApplication(config, 2304 this.getClass().getClassLoader()); 2305 ListIterator li = listDOClasses.listIterator(); 2306 try { 2308 while (li.hasNext()) { 2309 DOTable tableDBClassName = (DOTable) li.next(); 2310 registerTableMBean(tableDBClassName); 2311 2312 } 2313 } catch (Exception e) { 2314 logChannel.write(Logger.DEBUG, e.toString()); 2315 } 2316 } 2317 2318 private void registerTableMBean(DOTable tableDBClassName){ 2319 if (appName == null) { 2320 return; 2321 } 2322 2323 try { 2324 server = findMBeanServer(); 2325 if (server == null) { 2326 return; 2327 } 2328 } 2329 catch (Exception e) { 2330 logChannel.write(Logger.DEBUG, e.toString()); 2331 } 2332 2333 try { 2334 String applicationName = appName; 2335 2336 String dbName = tableDBClassName.getDBName(); 2337 2338 String tableName = tableDBClassName.getTableName(); 2339 2340 ObjectName objectName = new ObjectName ("EnhydraApplications:type=Database.Table-"+dbName+"."+tableName+",name=" + applicationName); 2341 2342 if (!server.isRegistered(objectName)) { 2343 tableMBean = new TableMBean(tableDBClassName,this,objectName); 2344 tableMBeans.put(dbName+"_"+tableName,tableMBean); 2345 server.registerMBean(tableMBean, objectName); 2346 } 2347 2348 } 2349 catch (Exception e) { 2350 logChannel.write(Logger.DEBUG, e.toString()); 2351 return; 2352 } 2353 } 2354 2355 private void unRegisterTableMBeans(){ 2356 if (appName == null) { 2357 return; 2358 } 2359 2360 try { 2361 server = findMBeanServer(); 2362 if (server == null) { 2363 return; 2364 } 2365 } catch (Exception e) { 2366 logChannel.write(Logger.DEBUG, e.toString()); 2367 } 2368 2369 try { 2370 String applicationName = appName; 2371 int length = tableMBeans.size(); 2372 Enumeration objectNames = tableMBeans.keys(); 2373 for (int i=0;i<length;i++){ 2374 String keyName = (String ) objectNames.nextElement(); 2375 TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName); 2376 ObjectName objectName = new ObjectName ("EnhydraApplications:type=Database.Table-"+tableMBean.getDbName()+"."+tableMBean.getTableName()+",name=" + applicationName); 2377 2378 if (server.isRegistered(objectName)) { 2379 server.unregisterMBean(objectName); 2380 } 2381 } 2382 tableMBeans.clear(); 2383 } 2384 catch (Exception e) { 2385 logChannel.write(Logger.DEBUG, e.toString()); 2386 return; 2387 } 2388 } 2389 2390 private static class TableMBConst { 2391 static Class cacheConstantClass; 2392 static int DATA_CACHE; 2393 static int SIMPLE_QUERY_CACHE; 2394 static int COMPLEX_QUERY_CACHE; 2395 static int QUERY_CACHING; 2396 2397 static Class [] NOCLASS_ARR = {}; 2398 2399 static final String [] CACHE_STAT_TYPE = { 2400 "Data_Struct_", "Simple_Query_", "Complex_Query_"}; 2401 2402 static final String cacheParameters[] = { 2403 "reserveFactor","CachePercentage", 2404 "initialCondition", "maxCacheSize", 2405 "maxSimpleCacheSize", "maxComplexCacheSize", 2406 "InitialDSCacheSize", "InitialCacheFetchSize" 2407 }; 2408 static String cacheDefaults[] = { 2409 "0", "-1.0", "*", "0", "0", "0", "-1", "0" 2410 }; 2411 2412 static{ 2413 try { 2414 cacheConstantClass = Class.forName( 2415 "org.enhydra.dods.cache.CacheConstants"); 2416 DATA_CACHE = (cacheConstantClass.getField( 2417 "DATA_CACHE")).getInt(null); 2418 SIMPLE_QUERY_CACHE = (cacheConstantClass.getField( 2419 "SIMPLE_QUERY_CACHE")).getInt(null); 2420 COMPLEX_QUERY_CACHE = (cacheConstantClass.getField( 2421 "COMPLEX_QUERY_CACHE")).getInt(null); 2422 QUERY_CACHING = (cacheConstantClass.getField( 2423 "QUERY_CACHING")).getInt(null); 2424 } catch (Exception e) { 2425 e.printStackTrace(); 2426 } 2427 } 2428 } 2429 2430 2433 private class TableMBean extends EafConfigMBean{ 2434 2435 protected DOTable doTable = null; 2436 protected String tableName = null; 2437 protected String dbName = null; 2438 protected Class tableClass = null; 2439 protected Object cfgAdmin = null; 2440 protected int levelOfCaching; 2441 2442 static final String CLASS_DODS = "org.enhydra.dods.DODS"; 2443 static final String REGISTER = "register"; 2444 static final String CLASS_DBMANAGER = 2445 "com.lutris.appserver.server.sql.DatabaseManager"; 2446 static final String GET_CONFIGURATION_ADMINISTRATION = 2447 "getConfigurationAdministration"; 2448 static final String READ_CACHE_CONFIGURATION = 2449 "readCacheConfiguration"; 2450 static final String CLASS_CONFIGURATION_ADMINISTRATION = 2451 "org.enhydra.dods.cache.ConfigurationAdministration"; 2452 2453 static final String CLASS_STATISTICS = 2454 "org.enhydra.dods.statistics.Statistics"; 2455 static final String CLASS_CACHE_STATISTICS = 2456 "org.enhydra.dods.statistics.CacheStatistics"; 2457 static final String GET_STATISTICS_TYPE = "getStatisticsType"; 2458 2459 static final String CACHE_DOT = "cache_"; 2460 static final String PRC = " %"; 2461 static final String CLEAR = "clear"; 2462 2463 static final String GET_LEVEL_OF_CACHING = "getLevelOfCaching"; 2464 static final String IS_DISABLED = "isDisabled"; 2465 static final String GET_TYPE = "getCacheType"; 2466 2467 static final String GET_RESERVE_FACTOR = "getReserveFactor"; 2468 static final String GET_CACHE_PERCENTAGE = "getCachePercentage"; 2469 static final String SET_CACHE_PERCENTAGE = "setCachePercentage"; 2470 static final String GET_INITIAL_FETCH_SIZE = "getInitialCacheFetchSize"; 2471 static final String SET_INITIAL_FETCH_SIZE = "setInitialCacheFetchSize"; 2472 static final String GET_INITIAL_DS_SIZE = "getInitialDSCacheSize"; 2473 static final String SET_INITIAL_DS_SIZE = "setInitialDSCacheSize"; 2474 static final String GET_INITIAL_QUERY_CACHE = "getInitialQueryCache"; 2475 static final String GET_CACHE_ADMINISTRATION = "getCacheAdministration"; 2476 static final String SET_RESERVE_FACTOR = "setReserveFactor"; 2477 static final String SET_INITIAL_QUERY_CACHE = "setInitialQueryCache"; 2478 static final String GET_MAX_CACHE_SIZE = "getMaxCacheSize"; 2479 static final String CLASS_CACHE_ADMINISTRATION = 2480 "org.enhydra.dods.cache.CacheAdministration"; 2481 static final String CLASS_UPDATE_CONFIGURATION_ADMINISTRATION = 2482 "org.enhydra.dods.cache.UpdateConfigurationAdministration"; 2483 static final String SET_MAX_CACHE_SIZE = "setMaxCacheSize"; 2484 2485 2486 static final String EMPTY = ""; 2487 static final String TABLE = "<TABLE border=3>"; 2488 static final String E_TABLE = "</TABLE>"; 2489 static final String COLOUR = "<SPAN STYLE='color:"; 2490 static final String E_COLOUR = "</SPAN>"; 2491 static final String BLUE = "blue'>"; 2492 static final String RED = "red'>"; 2493 static final String GREEN = "green'>"; 2494 static final String BOLD = "<B>"; 2495 static final String E_BOLD = "</B>"; 2496 static final String CAPTION = "<CAPTION>"; 2497 static final String E_CAPTION = "</CAPTION>"; 2498 static final String ROW = "<TR>"; 2499 static final String E_ROW = "</TR>"; 2500 static final String DATA = "<TD>"; 2501 static final String E_DATA = "</TD>"; 2502 2503 static final String CACHE_NOT_ACTIVE = "Cache is not configured"; 2504 static final String CACHE_STAT_FOR = "Cache Statistics for "; 2505 2506 static final String CACHE_ACCESS_NUM = "CacheAccessNum"; 2507 static final String CACHE_HITS_NUM = "CacheHitsNum"; 2508 static final String USED_PERCENTS = "UsedPercents"; 2509 static final String CACHE_HITS_PERCENTS = "CacheHitsPercents"; 2510 2511 static final String ENABLE = "enableCaching"; 2512 static final String ENABLED = "Caching has been enabled"; 2513 static final String DISABLE = "disableCaching"; 2514 static final String DISABLED = "Caching has been disabled"; 2515 2516 static final String REFRESH = "refreshCache"; 2517 static final String REFRESHED = "Caching has been refreshed"; 2518 static final String STATISTICREFRESH = "refreshStatistics"; 2519 static final String STATISTICREFRESHED = "Statistics have been refreshed"; 2520 2521 static final String GET_CACHE_STATISTICS = "getCacheStatistics"; 2522 static final String CLEAR_STATISTICS = "clearStatistics"; 2523 static final String GET_CACHE_ACCESS_NUM = "getCacheAccessNum"; 2524 static final String GET_CACHE_HITS_NUM = "getCacheHitsNum"; 2525 static final String GET_USED_PERCENTS = "getUsedPercents"; 2526 static final String GET_CACHE_HITS_PERCENTS = "getCacheHitsPercents"; 2527 2528 static final String TABLE_STAT_FOR = "Table Statistics for "; 2529 2530 static final String STATISTCS_TYPE = "StatisticsType"; 2531 static final String INSERT_NUM = "InsertNum"; 2532 static final String UPDATE_NUM = "UpdateNum"; 2533 static final String DELETE_NUM = "DeleteNum"; 2534 static final String DML_NUM = "DMLNum"; 2535 static final String LAZY_LOADING_NUM = "LazyLoadingNum"; 2536 static final String START_TIME = "StartTime"; 2537 static final String STOP_TIME = "StopTime"; 2538 static final String QUERY_NUM = "QueryNum"; 2539 static final String QUERY_BY_OID_NUM = "QueryByOIdNum"; 2540 static final String QUERY_AVERAGE_TIME = "QueryAverageTime"; 2541 static final String QUERY_BY_OID_AVERAGE_TIME = "QueryByOIdAverageTime"; 2542 2543 static final String GET_INSERT_NUM = "getInsertNum"; 2544 static final String GET_UPDATE_NUM = "getUpdateNum"; 2545 static final String GET_DELETE_NUM = "getDeleteNum"; 2546 static final String GET_DML_NUM = "getDMLNum"; 2547 static final String GET_LAZY_LOADING_NUM = "getLazyLoadingNum"; 2548 static final String GET_START_TIME = "getStartTime"; 2549 static final String GET_STOP_TIME = "getStopTime"; 2550 static final String GET_QUERY_NUM = "getQueryNum"; 2551 static final String GET_QUERY_BY_OID_NUM = "getQueryByOIdNum"; 2552 static final String GET_QUERY_AVERAGE_TIME = "getQueryAverageTime"; 2553 static final String GET_QUERY_BY_OID_AVERAGETIME = 2554 "getQueryByOIdAverageTime"; 2555 2556 static final String GET_DODS_CACHE_TABLE_NAME = "getCacheDodsTableName"; 2557 2558 public TableMBean (Application application, 2559 ObjectName objectName, String prefix, 2560 String [] includes, String [] excludes){ 2561 super(application,objectName,prefix,includes,excludes); 2562 buildDynamicMBeanInfo(); 2563 } 2564 2565 public TableMBean (DOTable tableDBClassName, Application application, 2566 ObjectName objectName){ 2567 2568 try { 2569 Method mth; 2570 mth = Class.forName(CLASS_DODS).getMethod(REGISTER, 2571 new Class [] {Class.forName(CLASS_DBMANAGER)}); 2572 mth.invoke(null, new Object [] { (Object ) databaseManager}); 2573 2574 doTable = tableDBClassName; 2575 tableName = doTable.getTableName(); 2576 dbName = doTable.getDBName(); 2577 tableClass = doTable.getCls(); 2578 2579 mth = tableClass.getMethod(GET_DODS_CACHE_TABLE_NAME, 2580 new Class [] {}); 2581 tableName = (mth.invoke(null, new Object [] {})).toString(); 2582 2583 mth = tableClass.getMethod(GET_CONFIGURATION_ADMINISTRATION, 2584 new Class [] {}); 2585 cfgAdmin = mth.invoke(null, new Object [] {}); 2586 2587 } catch (Exception e) { 2588 e.printStackTrace(); 2589 } 2590 2591 String [] includes = {"DatabaseManager_DB_"+dbName+"_"+tableName}; 2592 String [] excludes = null; 2593 2594 String prefix = "DatabaseManager_DB_"+dbName+"_"+tableName; 2595 2596 super.init(application,objectName,prefix,includes,excludes); 2597 2598 levelOfCaching = getLevelOfCaching(); 2599 hashAttrib.put(CACHE_DOT+"cachingStatus",getCachingStatus()); 2601 hashAttrib.put(CACHE_DOT+"cachingType",getCacheType()); 2602 hashAttrib.put(CACHE_DOT+"levelOfCaching",new Integer (levelOfCaching)); 2603 2604 if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[0])){ 2605 hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[0],getReserveFactor()); 2606 initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[0],getReserveFactor()); 2607 } 2608 if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[1])){ 2609 hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[1],getCachePercentage()); 2610 initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[1],getCachePercentage()); 2611 } 2612 if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[2])){ 2613 hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[2],getInitialCondition()); 2614 initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[2],getInitialCondition()); 2615 } 2616 if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[3])){ 2617 hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[3],getMaxCacheSize()); 2618 initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[3],getMaxCacheSize()); 2619 } 2620 if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[4])){ 2621 hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[4],getMaxSimpleCacheSize()); 2622 initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[4],getMaxSimpleCacheSize()); 2623 } 2624 if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[5])){ 2625 hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[5],getMaxComplexCacheSize()); 2626 initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[5],getMaxComplexCacheSize()); 2627 } 2628 if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[6])){ 2629 hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[6],getInitialDSCacheSize()); 2630 initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[6],getInitialDSCacheSize()); 2631 } 2632 if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[7])){ 2633 hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[7],getInitialCacheFetchSize()); 2634 initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[7],getInitialCacheFetchSize()); 2635 } 2636 2637 buildDynamicMBeanInfo(); 2638 } 2639 2640 2643 public Object getAttribute(String attribute_name) throws 2644 AttributeNotFoundException , 2645 MBeanException , ReflectionException { 2646 if (attribute_name == null) { 2648 throw new RuntimeOperationsException (new IllegalArgumentException ( 2649 "Attribute name cannot be null"), 2650 "Cannot invoke a getter of " + dClassName + 2651 " with null attribute name"); 2652 } 2653 2654 if ((CACHE_DOT+"levelOfCaching").equals(attribute_name)){ 2655 try{ 2656 hashAttrib.put(attribute_name,new Integer (getLevelOfCaching()).toString()); 2657 }catch (Exception e) { 2658 throw new MBeanException (e); 2659 } 2660 } else if ((CACHE_DOT+"cachingType").equals(attribute_name)){ 2661 try{ 2662 hashAttrib.put(attribute_name,getCacheType()); 2663 }catch (Exception e) { 2664 throw new MBeanException (e); 2665 } 2666 } else if ((CACHE_DOT+"cachingStatus").equals(attribute_name)){ 2667 try{ 2668 hashAttrib.put(attribute_name,getCachingStatus()); 2669 }catch (Exception e) { 2670 throw new MBeanException (e); 2671 } 2672 } else if ((CACHE_DOT+TableMBConst.cacheParameters[0]).equals(attribute_name)){ 2673 try{ 2674 hashAttrib.put(attribute_name,getReserveFactor()); 2675 }catch (Exception e) { 2676 throw new MBeanException (e); 2677 } 2678 } else if ((CACHE_DOT+TableMBConst.cacheParameters[1]).equals(attribute_name)){ 2679 try{ 2680 hashAttrib.put(attribute_name,getCachePercentage()); 2681 }catch (Exception e) { 2682 throw new MBeanException (e); 2683 } 2684 } else if ((CACHE_DOT+TableMBConst.cacheParameters[2]).equals(attribute_name)){ 2685 try{ 2686 hashAttrib.put(attribute_name,getInitialCondition()); 2687 }catch (Exception e) { 2688 throw new MBeanException (e); 2689 } 2690 } else if ((CACHE_DOT+TableMBConst.cacheParameters[3]).equals(attribute_name)){ 2691 try{ 2692 hashAttrib.put(attribute_name,getMaxCacheSize()); 2693 }catch (Exception e) { 2694 throw new MBeanException (e); 2695 } 2696 } else if ((CACHE_DOT+TableMBConst.cacheParameters[4]).equals(attribute_name)){ 2697 try{ 2698 hashAttrib.put(attribute_name,getMaxSimpleCacheSize()); 2699 }catch (Exception e) { 2700 throw new MBeanException (e); 2701 } 2702 } else if ((CACHE_DOT+TableMBConst.cacheParameters[5]).equals(attribute_name)){ 2703 try{ 2704 hashAttrib.put(attribute_name,getMaxComplexCacheSize()); 2705 }catch (Exception e) { 2706 throw new MBeanException (e); 2707 } 2708 } else if ((CACHE_DOT+TableMBConst.cacheParameters[6]).equals(attribute_name)){ 2709 try{ 2710 hashAttrib.put(attribute_name,getInitialDSCacheSize()); 2711 }catch (Exception e) { 2712 throw new MBeanException (e); 2713 } 2714 } else if ((CACHE_DOT+TableMBConst.cacheParameters[7]).equals(attribute_name)){ 2715 try{ 2716 hashAttrib.put(attribute_name,getInitialCacheFetchSize()); 2717 }catch (Exception e) { 2718 throw new MBeanException (e); 2719 } 2720 } 2721 2722 try { 2724 return hashAttrib.get(attribute_name); 2725 } 2726 catch (Exception e) { 2727 throw (new AttributeNotFoundException ("Cannot find " + 2729 attribute_name + " attribute in " + dClassName)); 2730 } 2731 } 2732 2733 2736 public void setAttribute(Attribute attribute) throws 2737 AttributeNotFoundException , 2738 InvalidAttributeValueException , MBeanException , ReflectionException { 2739 2740 if (attribute == null) { 2742 throw new RuntimeOperationsException (new IllegalArgumentException ( 2743 "Attribute cannot be null"), 2744 "Cannot invoke a setter of " + dClassName + 2745 " with null attribute"); 2746 } 2747 2748 String name = attribute.getName(); 2749 String value = (String ) attribute.getValue(); 2750 2751 boolean cacheAttribute = false; 2752 2753 if ((CACHE_DOT+TableMBConst.cacheParameters[0]).equals(name)){ 2754 try{ 2755 setReserveFactor(value); 2756 cacheAttribute = true; 2757 }catch (Exception e) { 2758 throw new MBeanException (e); 2759 } 2760 } else if ((CACHE_DOT+TableMBConst.cacheParameters[1]).equals(name)){ 2761 try{ 2762 setCachePercentage(value); 2763 cacheAttribute = true; 2764 }catch (Exception e) { 2765 throw new MBeanException (e); 2766 } 2767 } else if ((CACHE_DOT+TableMBConst.cacheParameters[2]).equals(name)){ 2768 try{ 2769 setInitialCondition(value); 2770 cacheAttribute = true; 2771 }catch (Exception e) { 2772 throw new MBeanException (e); 2773 } 2774 } else if ((CACHE_DOT+TableMBConst.cacheParameters[3]).equals(name)){ 2775 try{ 2776 setMaxCacheSize(value); 2777 cacheAttribute = true; 2778 }catch (Exception e) { 2779 throw new MBeanException (e); 2780 } 2781 } else if ((CACHE_DOT+TableMBConst.cacheParameters[4]).equals(name)){ 2782 try{ 2783 setMaxSimpleCacheSize(value); 2784 cacheAttribute = true; 2785 }catch (Exception e) { 2786 throw new MBeanException (e); 2787 } 2788 } else if ((CACHE_DOT+TableMBConst.cacheParameters[5]).equals(name)){ 2789 try{ 2790 setMaxComplexCacheSize(value); 2791 cacheAttribute = true; 2792 }catch (Exception e) { 2793 throw new MBeanException (e); 2794 } 2795 } else if ((CACHE_DOT+TableMBConst.cacheParameters[6]).equals(name)){ 2796 try{ 2797 setInitialDSCacheSize(value); 2798 cacheAttribute = true; 2799 }catch (Exception e) { 2800 throw new MBeanException (e); 2801 } 2802 } else if ((CACHE_DOT+TableMBConst.cacheParameters[7]).equals(name)){ 2803 try{ 2804 setInitialCacheFetchSize(value); 2805 cacheAttribute = true; 2806 }catch (Exception e) { 2807 throw new MBeanException (e); 2808 } 2809 } 2810 2811 super.setAttribute(attribute); 2813 2814 if (!cacheAttribute){ 2815 shutdownWithoutMBeanUnRegistration(); 2817 try { 2818 startup(config); 2819 } 2820 catch (Exception e) { 2821 logChannel.write(Logger.DEBUG, e.toString()); 2822 } 2823 } 2824 } 2825 2826 2831 2832 2836 protected MBeanConstructorInfo [] getMBeanConstructorInfo () { 2837 MBeanParameterInfo [] dParameters = new MBeanParameterInfo [3]; 2838 dParameters[0] = new MBeanParameterInfo ("doTable","org.enhydra.util.DOTable","DOTable Object"); 2839 dParameters[1] = new MBeanParameterInfo ("application","com.lutris.appserver.server.Application","Application Object"); 2840 dParameters[2] = new MBeanParameterInfo ("objectName","javax.management.ObjectName","MBean Name Object"); 2841 2842 MBeanConstructorInfo [] dConstructors = new MBeanConstructorInfo [1]; 2843 dConstructors[0] = new MBeanConstructorInfo ("TableMBean", 2844 "ConfigMBean Object Constructor", 2845 dParameters); 2846 2847 return dConstructors; 2848 } 2849 2850 2851 2855 protected MBeanAttributeInfo [] getMBeanAttributesInfo () { 2856 int length = hashAttrib.size(); 2857 MBeanAttributeInfo [] dAttributes = new MBeanAttributeInfo [length]; 2858 Enumeration keys = hashAttrib.keys(); 2859 for (int i = 0; i < length; i++) { 2860 String attName = (String ) keys.nextElement(); 2861 String attDesc = new String (attName + " configuration parameter!"); 2862 2863 if ((CACHE_DOT+"cachingStatus").equals(attName)||(CACHE_DOT+"cachingType").equals(attName) 2864 ||(CACHE_DOT+"levelOfCaching").equals(attName)){ 2865 dAttributes[i] = new MBeanAttributeInfo (attName, "java.lang.String", 2866 attDesc, true, false, false); 2867 }else { 2868 dAttributes[i] = new MBeanAttributeInfo (attName, "java.lang.String", 2869 attDesc, true, true, false); 2870 } 2871 } 2872 return dAttributes; 2873 } 2874 2875 2876 2879 public Object invoke(String operationName, Object params[], 2880 String signature[]) throws MBeanException , 2881 ReflectionException { 2882 if (operationName == null) { 2884 throw new RuntimeOperationsException (new IllegalArgumentException ( 2885 "Operation name cannot be null"), 2886 "Cannot invoke a null operation in " + dClassName); 2887 } 2888 if (operationName.equals("Toggle_EnableOrDisable_Cache")) { 2890 try { 2891 return enableDisableCaching(); 2892 }catch (Exception e) { 2893 throw new MBeanException (e); 2894 } 2895 } else if (operationName.equals("Get_Table_Data_Struct_Statistics")) { 2896 try { 2897 return getDoCacheStatistics(0); 2898 }catch (Exception e) { 2899 throw new MBeanException (e); 2900 } 2901 } else if (operationName.equals("Get_Table_Simple_Query_Statistics")) { 2902 try { 2903 return getDoCacheStatistics(1); 2904 }catch (Exception e) { 2905 throw new MBeanException (e); 2906 } 2907 } else if (operationName.equals("Get_Table_Complex_Query_Statistics")) { 2908 try { 2909 return getDoCacheStatistics(2); 2910 }catch (Exception e) { 2911 throw new MBeanException (e); 2912 } 2913 } else if (operationName.equals("Get_Table_Statistics")) { 2914 try { 2915 return getAllDoCacheStatistics(); 2916 }catch (Exception e) { 2917 throw new MBeanException (e); 2918 } 2919 } else if (operationName.equals("Clear_Table_Data_Struct_Statistics")) { 2920 try { 2921 clearDoCacheStatistics(0); 2922 return null; 2923 }catch (Exception e) { 2924 throw new MBeanException (e); 2925 } 2926 } else if (operationName.equals("Clear_Table_Simple_Query_Statistics")) { 2927 try { 2928 clearDoCacheStatistics(1); 2929 return null; 2930 }catch (Exception e) { 2931 throw new MBeanException (e); 2932 } 2933 } else if (operationName.equals("Clear_Table_Complex_Query_Statistics")) { 2934 try { 2935 clearDoCacheStatistics(2); 2936 return null; 2937 }catch (Exception e) { 2938 throw new MBeanException (e); 2939 } 2940 } else if (operationName.equals("Clear_Table_Statistics")) { 2941 try { 2942 clearAllDoStatistics(); 2943 return null; 2944 }catch (Exception e) { 2945 throw new MBeanException (e); 2946 } 2947 } else if (operationName.equals("Enable_Cache")) { 2948 try { 2949 return enableCaching(); 2950 }catch (Exception e) { 2951 throw new MBeanException (e); 2952 } 2953 } else if (operationName.equals("Disable_Cache")) { 2954 try { 2955 return disableCaching(); 2956 }catch (Exception e) { 2957 throw new MBeanException (e); 2958 } 2959 } else if (operationName.equals("Refresh_Cache")) { 2960 try { 2961 return refreshCache(); 2962 }catch (Exception e) { 2963 throw new MBeanException (e); 2964 } 2965 } else if (operationName.equals("Refresh_Statistics")) { 2966 try { 2967 return refreshStatistics(); 2968 }catch (Exception e) { 2969 throw new MBeanException (e); 2970 } 2971 } else{ 2972 return super.invoke(operationName, params, signature); 2974 } 2975 } 2976 2977 2981 protected MBeanOperationInfo [] getMBeanOperationsInfo () { 2982 MBeanParameterInfo [] params = null; 2983 MBeanOperationInfo [] dOperations = new MBeanOperationInfo [18]; 2984 dOperations[0] = new MBeanOperationInfo ("reset", 2985 "reset(): reset attributes to their initial values", 2986 params, "void", 2987 MBeanOperationInfo.ACTION); 2988 dOperations[1] = new MBeanOperationInfo ("saveAttributes", 2989 "saveAttributes(): save the attribute values into the configuration file", 2990 params, "void", 2991 MBeanOperationInfo.ACTION); 2992 dOperations[2] = new MBeanOperationInfo ("getAppInfo", 2993 "getAppInfo(): get application information", 2994 params, "String", 2995 MBeanOperationInfo.ACTION); 2996 2997 params = new MBeanParameterInfo [2]; 2998 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 2999 "use UNDERLINE (_) as attribute group separator."); 3000 params[1] = new MBeanParameterInfo ("attValue","java.lang.String","Attribute value!"); 3001 3002 dOperations[3] = new MBeanOperationInfo ("addAttribute", 3003 "addAttribute(String key, String value): add new application parameter", 3004 params, "void", 3005 MBeanOperationInfo.ACTION); 3006 3007 params = new MBeanParameterInfo [1]; 3008 params[0] = new MBeanParameterInfo ("attKey","java.lang.String","Attribute name! Please, " + 3009 "use UNDERLINE (_) as attribute group separator."); 3010 3011 dOperations[4] = new MBeanOperationInfo ("removeAttribute", 3012 "removeAttribute(String key): remove application parameter", 3013 params, "void", 3014 MBeanOperationInfo.ACTION); 3015 3016 params = null; 3017 3018 dOperations[5] = new MBeanOperationInfo ("Refresh_Cache", 3019 "refreshCache(): Refresh Table Cache.", 3020 params, "java.lang.String", 3021 MBeanOperationInfo.ACTION); 3022 3023 dOperations[6] = new MBeanOperationInfo ("Refresh_Statistics", 3024 "refreshStatistics(): Refresh Table Statistics.", 3025 params, "java.lang.String", 3026 MBeanOperationInfo.ACTION); 3027 3028 dOperations[7] = new MBeanOperationInfo ("Get_Table_Statistics", 3029 "getAllDoCacheStatistics(): Get Table Statistics.", 3030 params, "java.lang.String", 3031 MBeanOperationInfo.ACTION); 3032 3033 dOperations[8] = new MBeanOperationInfo ("Get_Table_Data_Struct_Statistics", 3034 "getDoCacheStatistics(0): Get Table Data Struct Statistics.", 3035 params, "java.lang.String", 3036 MBeanOperationInfo.ACTION); 3037 3038 dOperations[9] = new MBeanOperationInfo ("Get_Table_Simple_Query_Statistics", 3039 "getDoCacheStatistics(1): Get Table Simple Query Statistics.", 3040 params, "java.lang.String", 3041 MBeanOperationInfo.ACTION); 3042 3043 dOperations[10] = new MBeanOperationInfo ("Get_Table_Complex_Query_Statistics", 3044 "getDoCacheStatistics(2): Get Table Complex Query Statistics.", 3045 params, "java.lang.String", 3046 MBeanOperationInfo.ACTION); 3047 3048 dOperations[11] = new MBeanOperationInfo ("Clear_Table_Data_Struct_Statistics", 3049 "clearDoCacheStatistics(0): Clear Table Data Struct Statistics.", 3050 params, "void", 3051 MBeanOperationInfo.ACTION); 3052 3053 dOperations[12] = new MBeanOperationInfo ("Clear_Table_Simple_Query_Statistics", 3054 "clearDoCacheStatistics(1): Clear Table Simple Query Statistics.", 3055 params, "void", 3056 MBeanOperationInfo.ACTION); 3057 3058 dOperations[13] = new MBeanOperationInfo ("Clear_Table_Complex_Query_Statistics", 3059 "clearDoCacheStatistics(2): Clear Table Complex Query Statistics.", 3060 params, "void", 3061 MBeanOperationInfo.ACTION); 3062 3063 dOperations[14] = new MBeanOperationInfo ("Clear_Table_Statistics", 3064 "clearAllDoStatistics(): Clear Table Statistics.", 3065 params, "void", 3066 MBeanOperationInfo.ACTION); 3067 3068 dOperations[15] = new MBeanOperationInfo ("Enable_Cache", 3069 "enableCaching(): Enables Table Cache Status.", 3070 params, "java.lang.String", 3071 MBeanOperationInfo.ACTION); 3072 3073 dOperations[16] = new MBeanOperationInfo ("Disable_Cache", 3074 "disableCaching(): Disables Table Cache Status.", 3075 params, "java.lang.String", 3076 MBeanOperationInfo.ACTION); 3077 3078 dOperations[17] = new MBeanOperationInfo ("Toggle_EnableOrDisable_Cache", 3079 "enableDisableCaching(): Toggles Table Cache Status.", 3080 params, "java.lang.String", 3081 MBeanOperationInfo.ACTION); 3082 3083 return dOperations; 3084 } 3085 3086 3089 public void reset() throws AttributeNotFoundException { 3090 super.reset(); 3091 try { 3092 setReserveFactor((String )hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[0])); 3093 setCachePercentage((String )hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[1])); 3094 setInitialCondition((String )hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[2])); 3095 setMaxCacheSize((String )hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[3])); 3096 setMaxSimpleCacheSize((String )hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[4])); 3097 setMaxComplexCacheSize((String )hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[5])); 3098 setInitialDSCacheSize((String )hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[6])); 3099 setInitialCacheFetchSize((String )hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[7])); 3100 } catch (Exception ex){ 3101 ex.printStackTrace(); 3102 } 3103 } 3104 3105 3110 3111 private int getLevelOfCaching() { 3112 int levelOfCaching = 0; 3113 try { 3114 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3115 getMethod(GET_LEVEL_OF_CACHING, new Class [] {}); 3116 levelOfCaching = ( (Integer ) mth.invoke(cfgAdmin, new Object [] {})). 3117 intValue(); 3118 } catch (Exception e) { 3119 e.printStackTrace(); 3120 } 3121 return levelOfCaching; 3122 } 3123 3124 private String getCachingStatus() { 3125 if (isCachingDisabled()){ 3126 return "DISABLED"; 3127 }else { 3128 return "ENABLED"; 3129 } 3130 } 3131 3132 private boolean isCachingDisabled() { 3133 boolean ret = true; 3134 try { 3135 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3136 getMethod(IS_DISABLED, new Class [] {}); 3137 ret = ( (Boolean ) mth.invoke(cfgAdmin, new Object [] {})).booleanValue(); 3138 } catch (Exception e) { 3139 e.printStackTrace(); 3140 } 3141 return ret; 3142 } 3143 3144 private String getCacheType() { 3145 String ret = null; 3146 try { 3147 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3148 getMethod(GET_TYPE, new Class [] {}); 3149 ret = ( (String ) mth.invoke(cfgAdmin, new Object [] {})); 3150 } catch (Exception e) { 3151 e.printStackTrace(); 3152 } 3153 return ret; 3154 } 3155 3156 private String getCachePercentage() { 3157 double cachePercentage = 0; 3158 try { 3159 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3160 getMethod(GET_CACHE_PERCENTAGE, new Class [] {}); 3161 cachePercentage = ( (Double ) mth.invoke(cfgAdmin, new Object [] {})). 3162 doubleValue(); 3163 } catch (Exception e) { 3164 logChannel.write(Logger.DEBUG, e.toString()); 3165 } 3166 return String.valueOf(cachePercentage); 3167 } 3168 3169 private String setCachePercentage(String value) throws Exception { 3170 String oldValue = getCachePercentage(); 3171 if (!value.equals(oldValue)) { 3172 Method mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION). 3173 getMethod(SET_CACHE_PERCENTAGE, 3174 new Class [] {Class.forName( 3175 CLASS_CONFIGURATION_ADMINISTRATION), Double.TYPE}); 3176 mth.invoke(null, new Object [] {cfgAdmin, new Double (value)}); 3177 } 3178 return oldValue; 3179 } 3180 3181 private String getInitialCacheFetchSize() { 3182 int fetchSize = 0; 3183 try { 3184 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3185 getMethod(GET_INITIAL_FETCH_SIZE, new Class [] {}); 3186 fetchSize = ( (Integer ) mth.invoke(cfgAdmin, new Object [] {})). 3187 intValue(); 3188 } catch (Exception e) { 3189 logChannel.write(Logger.DEBUG, e.toString()); 3190 } 3191 return String.valueOf(fetchSize); 3192 } 3193 3194 private String setInitialCacheFetchSize(String value) throws Exception { 3195 String oldValue = getInitialCacheFetchSize(); 3196 if (!value.equals(oldValue)) { 3197 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3198 getMethod(SET_INITIAL_FETCH_SIZE, 3199 new Class [] {Integer.TYPE}); 3200 mth.invoke(cfgAdmin, new Object [] {new Integer (value)}); 3201 } 3202 return oldValue; 3203 } 3204 3205 private String getInitialDSCacheSize() { 3206 int dsSize = 0; 3207 try { 3208 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3209 getMethod(GET_INITIAL_DS_SIZE, new Class [] {}); 3210 dsSize = ( (Integer ) mth.invoke(cfgAdmin, new Object [] {})). 3211 intValue(); 3212 } catch (Exception e) { 3213 logChannel.write(Logger.DEBUG, e.toString()); 3214 } 3215 return String.valueOf(dsSize); 3216 } 3217 3218 private String setInitialDSCacheSize(String value) throws Exception { 3219 String oldValue = getInitialDSCacheSize(); 3220 if (!value.equals(oldValue)) { 3221 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3222 getMethod(SET_INITIAL_DS_SIZE, 3223 new Class [] {Integer.TYPE}); 3224 mth.invoke(cfgAdmin, new Object [] {new Integer (value)}); 3225 } 3226 return oldValue; 3227 } 3228 3229 private String getReserveFactor() { 3230 double reserveFactor = 0; 3231 try { 3232 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3233 getMethod(GET_RESERVE_FACTOR, new Class [] {}); 3234 reserveFactor = ( (Double ) mth.invoke(cfgAdmin, new Object [] {})). 3235 doubleValue(); 3236 } catch (Exception e) { 3237 logChannel.write(Logger.DEBUG, e.toString()); 3238 } 3239 return String.valueOf(reserveFactor); 3240 } 3241 3242 private String setReserveFactor(String value) throws Exception { 3243 String oldValue = getReserveFactor(); 3244 if (!value.equals(oldValue)) { 3245 Method mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION). 3246 getMethod(SET_RESERVE_FACTOR, 3247 new Class [] {Class.forName( 3248 CLASS_CONFIGURATION_ADMINISTRATION), Double.TYPE}); 3249 mth.invoke(null, new Object [] {cfgAdmin, new Double (value)}); 3250 } 3251 return oldValue; 3252 } 3253 3254 private String getInitialCondition() { 3255 String initialCondition = null; 3256 try { 3257 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3258 getMethod(GET_INITIAL_QUERY_CACHE, new Class [] {}); 3259 initialCondition = (String ) mth.invoke(cfgAdmin, new Object [] {}); 3260 if (initialCondition == null) { 3261 initialCondition = TableMBConst.cacheDefaults[2]; 3262 } 3263 } catch (Exception e) { 3264 logChannel.write(Logger.DEBUG, e.toString()); 3265 } 3266 return initialCondition; 3267 } 3268 3269 private String setInitialCondition(String value) throws Exception { 3270 String oldValue = getInitialCondition(); 3271 if (!value.equals(oldValue)) { 3272 Method mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION). 3273 getMethod(SET_INITIAL_QUERY_CACHE, 3274 new Class [] {Class.forName( 3275 CLASS_CONFIGURATION_ADMINISTRATION), 3276 Class.forName("java.lang.String")}); 3277 mth.invoke(null, new Object [] {cfgAdmin, value}); 3278 } 3279 return oldValue; 3280 } 3281 3282 private Object getCacheAdministration(int i) { 3283 Object ret = null; 3284 try { 3285 Method mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION). 3286 getMethod(GET_CACHE_ADMINISTRATION, 3287 new Class [] {Integer.TYPE}); 3288 ret = mth.invoke(cfgAdmin, new Object [] {new Integer (i)}); 3289 } catch (Exception e) { 3290 logChannel.write(Logger.DEBUG, e.toString()); 3291 } 3292 return ret; 3293 } 3294 3295 private String getMaxCacheSize() { 3296 String ret = null; 3297 try { 3298 Object cacheAdmin = getCacheAdministration(TableMBConst.DATA_CACHE); 3299 Method mth = Class.forName(CLASS_CACHE_ADMINISTRATION). 3300 getMethod(GET_MAX_CACHE_SIZE, new Class [] {}); 3301 int maxCacheSize = ( (Integer ) mth.invoke(cacheAdmin, new Object [] {})). 3302 intValue(); 3303 ret = String.valueOf(maxCacheSize); 3304 } catch (Exception e) { 3305 logChannel.write(Logger.DEBUG, e.toString()); 3306 } 3307 return ret; 3308 } 3309 3310 private String setMaxCacheSize(String value) throws Exception { 3311 String oldValue = getMaxCacheSize(); 3312 if (!value.equals(oldValue)) { 3313 Object cacheAdmin = getCacheAdministration(TableMBConst.DATA_CACHE); 3314 Method mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION). 3315 getMethod(SET_MAX_CACHE_SIZE, 3316 new Class [] {Class.forName(CLASS_CACHE_ADMINISTRATION), 3317 Integer.TYPE}); 3318 mth.invoke(null, new Object [] {cacheAdmin, new Integer (value)}); 3319 } 3320 return oldValue; 3321 } 3322 3323 private String getMaxSimpleCacheSize() { 3324 String ret = null; 3325 try { 3326 Object cacheAdmin = getCacheAdministration(TableMBConst.SIMPLE_QUERY_CACHE); 3327 Method mth = Class.forName(CLASS_CACHE_ADMINISTRATION). 3328 getMethod(GET_MAX_CACHE_SIZE, new Class [] {}); 3329 int maxCacheSize = ( (Integer ) mth.invoke(cacheAdmin, new Object [] {})). 3330 intValue(); 3331 ret = String.valueOf(maxCacheSize); 3332 } catch (Exception e) { 3333 logChannel.write(Logger.DEBUG, e.toString()); 3334 } 3335 return ret; 3336 } 3337 3338 private String setMaxSimpleCacheSize(String value) throws Exception { 3339 String oldValue = getMaxSimpleCacheSize(); 3340 if (!value.equals(oldValue)) { 3341 Object cacheAdmin = getCacheAdministration(TableMBConst.SIMPLE_QUERY_CACHE); 3342 Method mth = Class.forName( 3343 CLASS_UPDATE_CONFIGURATION_ADMINISTRATION). 3344 getMethod(SET_MAX_CACHE_SIZE, 3345 new Class [] {Class.forName( 3346 CLASS_CACHE_ADMINISTRATION), 3347 Integer.TYPE}); 3348 mth.invoke(null, new Object [] {cacheAdmin, new Integer (value)}); 3349 } 3350 return oldValue; 3351 } 3352 3353 private String getMaxComplexCacheSize() { 3354 String ret = null; 3355 try { 3356 Object cacheAdmin = getCacheAdministration(TableMBConst.COMPLEX_QUERY_CACHE); 3357 Method mth = Class.forName(CLASS_CACHE_ADMINISTRATION). 3358 getMethod(GET_MAX_CACHE_SIZE, new Class [] {}); 3359 int maxCacheSize = ( (Integer ) mth.invoke(cacheAdmin, new Object [] {})). 3360 intValue(); 3361 ret = String.valueOf(maxCacheSize); 3362 } catch (Exception e) { 3363 logChannel.write(Logger.DEBUG, e.toString()); 3364 } 3365 return ret; 3366 } 3367 3368 private String setMaxComplexCacheSize(String value) throws Exception { 3369 String oldValue = getMaxComplexCacheSize(); 3370 if (!value.equals(oldValue)) { 3371 Object cacheAdmin = getCacheAdministration(TableMBConst.COMPLEX_QUERY_CACHE); 3372 Method mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION). 3373 getMethod(SET_MAX_CACHE_SIZE, 3374 new Class [] {Class.forName(CLASS_CACHE_ADMINISTRATION), 3375 Integer.TYPE}); 3376 mth.invoke(null, new Object [] {cacheAdmin, new Integer (value)}); 3377 } 3378 return oldValue; 3379 } 3380 3381 private String enableDisableCaching() { 3382 String retString = null; 3383 try { 3384 Method mth; 3385 if (isCachingDisabled()) { 3386 mth = tableClass.getMethod(ENABLE, 3387 TableMBConst.NOCLASS_ARR); 3388 retString = BOLD + COLOUR + GREEN + 3389 ENABLED + 3390 E_COLOUR + E_BOLD; 3391 } 3392 else { 3393 mth = tableClass.getMethod(DISABLE, 3394 TableMBConst.NOCLASS_ARR); 3395 retString = BOLD + COLOUR + RED + 3396 DISABLED + 3397 E_COLOUR + E_BOLD; 3398 } 3399 3400 mth.invoke(null, new Object [] {}); 3401 3402 } catch (Exception e) { 3403 logChannel.write(Logger.DEBUG, e.toString()); 3404 } 3405 return retString; 3406 } 3407 3408 private String enableCaching() { 3409 String retString = null; 3410 try { 3411 Method mth; 3412 mth = tableClass.getMethod(ENABLE, 3413 TableMBConst.NOCLASS_ARR); 3414 retString = BOLD + COLOUR + GREEN + 3415 ENABLED + 3416 E_COLOUR + E_BOLD; 3417 mth.invoke(null, new Object [] {}); 3418 3419 } catch (Exception e) { 3420 logChannel.write(Logger.DEBUG, e.toString()); 3421 } 3422 return retString; 3423 } 3424 3425 3426 private String disableCaching() { 3427 String retString = null; 3428 try { 3429 Method mth; 3430 mth = tableClass.getMethod(DISABLE, 3431 TableMBConst.NOCLASS_ARR); 3432 retString = BOLD + COLOUR + RED + 3433 DISABLED + 3434 E_COLOUR + E_BOLD; 3435 3436 mth.invoke(null, new Object [] {}); 3437 } catch (Exception e) { 3438 logChannel.write(Logger.DEBUG, e.toString()); 3439 } 3440 return retString; 3441 } 3442 3443 private String refreshCache() { 3444 String retString = null; 3445 try { 3446 Method mth; 3447 mth = tableClass.getMethod(REFRESH, 3448 TableMBConst.NOCLASS_ARR); 3449 retString = BOLD + COLOUR + BLUE + 3450 REFRESHED + 3451 E_COLOUR + E_BOLD; 3452 3453 mth.invoke(null, new Object [] {}); 3454 } catch (Exception e) { 3455 logChannel.write(Logger.DEBUG, e.toString()); 3456 } 3457 return retString; 3458 } 3459 3460 private String refreshStatistics() { 3461 String retString = null; 3462 try { 3463 Method mth; 3464 mth = tableClass.getMethod(STATISTICREFRESH, 3465 TableMBConst.NOCLASS_ARR); 3466 retString = BOLD + COLOUR + BLUE + 3467 STATISTICREFRESHED + 3468 E_COLOUR + E_BOLD; 3469 3470 mth.invoke(null, new Object [] {}); 3471 } catch (Exception e) { 3472 logChannel.write(Logger.DEBUG, e.toString()); 3473 } 3474 return retString; 3475 } 3476 3477 private String cachingDisabled() { 3478 String retString = null; 3479 if (isCachingDisabled()) { 3480 retString = BOLD + COLOUR + RED + 3481 DISABLED + 3482 E_COLOUR + E_BOLD; 3483 } 3484 return retString; 3485 } 3486 3487 private String cachingActive(int type) { 3488 String retString = null; 3489 if(type == 0) { 3490 int value = (new Integer (getMaxCacheSize())).intValue(); 3491 if (value<1) { 3492 retString = BOLD + COLOUR + RED + 3493 CACHE_NOT_ACTIVE + 3494 E_COLOUR + E_BOLD; 3495 } 3496 return retString; 3497 } 3498 else if(type == 1) { 3499 int value = (new Integer (getMaxSimpleCacheSize())).intValue(); 3500 if (value<1) { 3501 retString = BOLD + COLOUR + RED + 3502 CACHE_NOT_ACTIVE + 3503 E_COLOUR + E_BOLD; 3504 } 3505 return retString; 3506 } 3507 else if(type == 2) { 3508 int value = (new Integer (getMaxComplexCacheSize())).intValue(); 3509 if (value < 1) { 3510 retString = BOLD + COLOUR + RED + 3511 CACHE_NOT_ACTIVE + 3512 E_COLOUR + E_BOLD; 3513 } 3514 return retString; 3515 } 3516 return retString; 3517 } 3518 3519 private String getDoCacheStatistics(int type) { 3520 String retString = cachingActive(type); 3521 if (retString != null) { 3522 return retString; 3523 } 3524 try { 3525 Method mth = tableClass.getMethod("get_statistics", 3526 TableMBConst.NOCLASS_ARR); 3527 Object tableStat = mth.invoke(null, new Object [] {}); 3528 3529 mth = Class.forName(CLASS_STATISTICS).getMethod( 3530 GET_CACHE_STATISTICS, 3531 new Class [] {Integer.TYPE}); 3532 Object stat = mth.invoke(tableStat, new Object [] {new Integer (type)}); 3533 retString = TABLE + CAPTION + BOLD + 3534 COLOUR + BLUE + TableMBConst.CACHE_STAT_TYPE[type] + 3535 CACHE_STAT_FOR + tableClass.getName() + 3536 E_COLOUR + E_BOLD + E_CAPTION; 3537 3538 mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod( 3539 GET_CACHE_ACCESS_NUM, 3540 TableMBConst.NOCLASS_ARR); 3541 3542 retString += ROW + DATA; 3543 retString += CACHE_ACCESS_NUM + E_DATA; 3544 retString += DATA; 3545 retString += mth.invoke(stat, new Object [] {}) + 3546 E_DATA + E_ROW; 3547 mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod( 3548 GET_CACHE_HITS_NUM, 3549 TableMBConst.NOCLASS_ARR); 3550 3551 retString += ROW + DATA; 3552 retString += CACHE_HITS_NUM + E_DATA; 3553 retString += DATA; 3554 retString += mth.invoke(stat, new Object [] {}) + 3555 E_DATA + E_ROW; 3556 3557 mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod( 3558 GET_USED_PERCENTS, 3559 TableMBConst.NOCLASS_ARR); 3560 3561 retString += ROW + DATA; 3562 retString += USED_PERCENTS + E_DATA; 3563 retString += DATA; 3564 retString += mth.invoke(stat, new Object [] {}) + 3565 PRC + 3566 E_DATA + E_ROW; 3567 3568 mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod( 3569 GET_CACHE_HITS_PERCENTS, 3570 TableMBConst.NOCLASS_ARR); 3571 3572 retString += ROW + DATA; 3573 retString += CACHE_HITS_PERCENTS + E_DATA; 3574 retString += DATA; 3575 retString += mth.invoke(stat, new Object [] {}) + 3576 PRC + 3577 E_DATA + E_ROW; 3578 retString += E_TABLE; 3579 return retString; 3580 3581 } 3582 catch (Exception e) { 3583 e.printStackTrace(); 3584 return "ERROR: " + e.getLocalizedMessage(); 3585 } 3586 } 3587 3588 private String getAllDoCacheStatistics() { 3589 String retString = null; 3590 retString = TABLE + ROW + DATA; 3591 int nParam; 3592 if (levelOfCaching == TableMBConst.QUERY_CACHING) { 3593 nParam = 3; 3594 } 3595 else { 3596 nParam = 1; 3597 } 3598 for (int i = 0; i < nParam; i++) { 3599 retString += DATA; 3600 retString += getDoCacheStatistics(i); 3601 retString += E_DATA; 3602 } 3603 retString += E_ROW + E_TABLE; 3604 return retString; 3605 } 3606 3607 private String getDOStatistics() { 3608 try { 3609 Method mth = tableClass.getMethod("get_statistics", 3610 new Class [] {}); 3611 3612 Object stat = mth.invoke(null, new Object [] {}); 3613 Class statClass = Class.forName(CLASS_STATISTICS); 3614 3615 String retString = TABLE + CAPTION + BOLD + 3616 COLOUR + BLUE + TABLE_STAT_FOR + 3617 tableClass.getName() + E_COLOUR + E_BOLD + 3618 E_CAPTION; 3619 3620 mth = statClass.getMethod(GET_STATISTICS_TYPE, 3621 new Class [] {}); 3622 3623 retString = retString + ROW + DATA; 3624 retString += STATISTCS_TYPE + E_DATA; 3625 retString += DATA; 3626 retString += mth.invoke(stat, new Object [] {}) + 3627 E_DATA + E_ROW; 3628 3629 mth = statClass.getMethod(GET_INSERT_NUM, 3630 new Class [] {}); 3631 3632 retString += ROW + DATA; 3633 retString += INSERT_NUM + E_DATA; 3634 retString += DATA; 3635 retString += mth.invoke(stat, new Object [] {}) + 3636 E_DATA + E_ROW; 3637 3638 mth = statClass.getMethod(GET_UPDATE_NUM, 3639 new Class [] {}); 3640 3641 retString += ROW + DATA; 3642 retString += UPDATE_NUM + E_DATA; 3643 retString += DATA; 3644 retString += mth.invoke(stat, new Object [] {}) + 3645 E_DATA + E_ROW; 3646 3647 mth = statClass.getMethod(GET_DELETE_NUM, 3648 new Class [] {}); 3649 3650 retString += ROW + DATA; 3651 retString += DELETE_NUM + E_DATA; 3652 retString += DATA; 3653 retString += mth.invoke(stat, new Object [] {}) + 3654 E_DATA + E_ROW; 3655 3656 mth = statClass.getMethod(GET_DML_NUM, 3657 new Class [] {}); 3658 3659 retString += ROW + DATA; 3660 retString += DML_NUM + E_DATA; 3661 retString += DATA; 3662 retString += mth.invoke(stat, new Object [] {}) + 3663 E_DATA + E_ROW; 3664 3665 mth = statClass.getMethod(GET_LAZY_LOADING_NUM, 3666 new Class [] {}); 3667 3668 retString += ROW + DATA; 3669 retString += LAZY_LOADING_NUM + E_DATA; 3670 retString += DATA; 3671 retString += mth.invoke(stat, new Object [] {}) + 3672 E_DATA + E_ROW; 3673 3674 mth = statClass.getMethod(GET_START_TIME, 3675 new Class [] {}); 3676 3677 retString += ROW + DATA; 3678 retString += START_TIME + E_DATA; 3679 retString += DATA; 3680 retString += mth.invoke(stat, new Object [] {}) + 3681 E_DATA + E_ROW; 3682 3683 mth = statClass.getMethod(GET_STOP_TIME, 3684 new Class [] {}); 3685 3686 retString += ROW + DATA; 3687 retString += STOP_TIME + E_DATA; 3688 retString += DATA; 3689 retString += mth.invoke(stat, new Object [] {}) + 3690 E_DATA + E_ROW; 3691 3692 mth = statClass.getMethod(GET_QUERY_NUM, 3693 new Class [] {}); 3694 3695 retString += ROW + DATA; 3696 retString += QUERY_NUM + E_DATA; 3697 retString += DATA; 3698 retString += mth.invoke(stat, new Object [] {}) + 3699 E_DATA + E_ROW; 3700 3701 mth = statClass.getMethod(GET_QUERY_BY_OID_NUM, 3702 new Class [] {}); 3703 3704 retString += ROW + DATA; 3705 retString += QUERY_BY_OID_NUM + E_DATA; 3706 retString += DATA; 3707 retString += mth.invoke(stat, new Object [] {}) + 3708 E_DATA + E_ROW; 3709 3710 mth = statClass.getMethod(GET_QUERY_AVERAGE_TIME, 3711 new Class [] {}); 3712 3713 retString += ROW + DATA; 3714 retString += QUERY_AVERAGE_TIME + E_DATA; 3715 retString += DATA; 3716 retString += mth.invoke(stat, new Object [] {}) + 3717 E_DATA + E_ROW; 3718 3719 mth = statClass.getMethod(GET_QUERY_BY_OID_AVERAGETIME, 3720 new Class [] {}); 3721 3722 retString += ROW + DATA; 3723 retString += QUERY_BY_OID_AVERAGE_TIME + 3724 E_DATA; 3725 retString += DATA; 3726 retString += mth.invoke(stat, new Object [] {}) + 3727 E_DATA + E_ROW; 3728 retString = retString + E_TABLE; 3729 3730 return retString; 3731 } 3732 catch (Exception e) { 3733 return "ERROR: " + e.getLocalizedMessage(); 3734 } 3735 } 3736 3737 private void clearDoCacheStatistics(int type) { 3738 try { 3739 Method mth = tableClass.getMethod("get_statistics", 3740 TableMBConst.NOCLASS_ARR); 3741 3742 Object tableStat = mth.invoke(null, new Object [] {}); 3743 mth = Class.forName(CLASS_STATISTICS).getMethod( 3744 GET_CACHE_STATISTICS, 3745 new Class [] {Integer.TYPE}); 3746 Object stat = mth.invoke(tableStat, new Object [] {new Integer (type)}); 3747 mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod( 3748 CLEAR_STATISTICS, 3749 TableMBConst.NOCLASS_ARR); 3750 mth.invoke(stat, new Object [] {}); 3751 } 3752 catch (Exception e) { 3753 logChannel.write(Logger.DEBUG, e.toString()); 3754 } 3755 } 3756 3757 private void clearAllDoStatistics() { 3758 try { 3759 Method mth = tableClass.getMethod("get_statistics", 3760 TableMBConst.NOCLASS_ARR); 3761 3762 Object tableStat = mth.invoke(null, new Object [] {}); 3763 mth = Class.forName(CLASS_STATISTICS).getMethod(CLEAR, 3764 TableMBConst.NOCLASS_ARR); 3765 mth.invoke(tableStat, new Object [] {}); 3766 3767 } 3768 catch (Exception e) { 3769 logChannel.write(Logger.DEBUG, e.toString()); 3770 } 3771 } 3772 3773 public String getTableName(){ 3774 return tableName; 3775 } 3776 3777 public String getDbName(){ 3778 return dbName; 3779 } 3780 } 3781 3782 private void registerContextMBean(){ 3783 if (appName == null) { 3784 return; 3785 } 3786 3787 try { 3788 server = findMBeanServer(); 3789 if (server == null) { 3790 return; 3791 } 3792 } 3793 catch (Exception e) { 3794 logChannel.write(Logger.DEBUG, e.toString()); 3795 } 3796 3797 try { 3798 String applicationName = appName; 3799 ObjectName objectName = new ObjectName ("EnhydraApplications:type=Context,name=" + applicationName); 3800 if (!server.isRegistered(objectName)) { 3801 3802 contextMBean = new ContextMBean(this); 3803 if (contextMBean!=null){ 3804 server.registerMBean(contextMBean, objectName); 3805 } 3806 } 3807 } 3808 catch (Exception e) { 3809 e.printStackTrace(); 3810 logChannel.write(Logger.DEBUG, e.toString()); 3811 return; 3812 } 3813 } 3814 3815 private void unRegisterContextMBean(){ 3816 if (appName == null) { 3817 return; 3818 } 3819 3820 try { 3821 server = findMBeanServer(); 3822 if (server == null) { 3823 return; 3824 } 3825 } catch (Exception e) { 3826 logChannel.write(Logger.DEBUG, e.toString()); 3827 } 3828 3829 try { 3830 String applicationName = appName; 3831 ObjectName objectName = new ObjectName ("EnhydraApplications:type=Context,name=" + applicationName); 3832 if (server.isRegistered(objectName)) { 3833 server.unregisterMBean(objectName); 3834 } 3835 contextMBean = null; 3836 } catch (Exception e) { 3837 logChannel.write(Logger.DEBUG, e.toString()); 3838 return; 3839 } 3840 } 3841 3842 public class ContextMBean implements DynamicMBean { 3843 3844 private String appName = null; 3845 private String appContext = null; 3846 private String appRealContext = null; 3847 3848 protected String dClassName = this.getClass().getName(); 3849 protected MBeanInfo dMBeanInfo = null; 3850 3851 public ContextMBean (Application application) { 3852 appName = application.getName(); 3853 try{ 3854 appRealContext = application.getHttpPresentationManager().getServletContext().getRealPath("/"); 3855 appContext = application.getHttpPresentationManager().getServletContext().getServletContextName(); 3856 if (appContext == null){ 3857 if (appRealContext.endsWith(java.io.File.separator)) { 3858 appContext = appRealContext.substring(0,appRealContext.length()-1); 3859 }else{ 3860 appContext = appRealContext; 3861 } 3862 int temp = appContext.lastIndexOf(java.io.File.separator); 3863 if (temp!=-1) 3864 appContext = appContext.substring(temp+1); 3865 } 3866 3867 } catch (Exception except){ 3868 except.printStackTrace(); 3869 } 3870 3871 buildDynamicMBeanInfo(); 3872 } 3873 3874 public String getAppContext(){ 3875 return appContext; 3876 } 3877 3878 public String getAppRealContext(){ 3879 return appRealContext; 3880 } 3881 3882 public String getAppName(){ 3883 return appName; 3884 } 3885 3886 public void buildDynamicMBeanInfo(){ 3887 dMBeanInfo = new MBeanInfo (dClassName, getDescription(), 3889 getMBeanAttributesInfo(), getMBeanConstructorInfo(), 3890 getMBeanOperationsInfo(), getMBeanNotificationInfo()); 3891 } 3892 3893 3898 3899 3903 protected MBeanAttributeInfo [] getMBeanAttributesInfo () { 3904 MBeanAttributeInfo [] dAttributes = new MBeanAttributeInfo [0]; 3905 return dAttributes; 3906 } 3907 3908 3912 protected MBeanOperationInfo [] getMBeanOperationsInfo () { 3913 MBeanParameterInfo [] params = null; 3914 MBeanOperationInfo [] dOperations = new MBeanOperationInfo [3]; 3915 dOperations[0] = new MBeanOperationInfo ("getAppName", 3916 "getAppName(): returns ApplicationName", 3917 params, "java.lang.String", 3918 MBeanOperationInfo.ACTION); 3919 dOperations[1] = new MBeanOperationInfo ("getAppContext", 3920 "getAppContext(): returns value of appliation context", 3921 params, "java.lang.String", 3922 MBeanOperationInfo.ACTION); 3923 dOperations[2] = new MBeanOperationInfo ("getAppRealContext", 3924 "getAppRealContext(): returns value of appliation real context", 3925 params, "java.lang.String", 3926 MBeanOperationInfo.ACTION); 3927 3928 return dOperations; 3929 } 3930 3931 3935 protected MBeanNotificationInfo [] getMBeanNotificationInfo () { 3936 MBeanNotificationInfo [] dNotifications = new MBeanNotificationInfo [0]; 3937 return dNotifications; 3938 } 3939 3940 3944 protected MBeanConstructorInfo [] getMBeanConstructorInfo () { 3945 MBeanParameterInfo [] dParameters = new MBeanParameterInfo [1]; 3946 dParameters[0] = new MBeanParameterInfo ("application","com.lutris.appserver.server.Application","Application Object"); 3947 3948 MBeanConstructorInfo [] dConstructors = new MBeanConstructorInfo [1]; 3949 dConstructors[0] = new MBeanConstructorInfo ("ContextMBean", 3950 "Context MBean Object Constructor", 3951 dParameters); 3952 3953 return dConstructors; 3954 } 3955 3956 3960 protected String getDescription (){ 3961 String dDescription = "Dynamic MBean offers application base context data"; 3962 return dDescription; 3963 } 3964 3965 3970 3971 3974 public Object getAttribute(String attribute_name) throws 3975 AttributeNotFoundException , 3976 MBeanException , ReflectionException { 3977 return null; 3979 } 3980 3981 3984 public void setAttribute(Attribute attribute) throws 3985 AttributeNotFoundException , 3986 InvalidAttributeValueException , MBeanException , ReflectionException { 3987 } 3989 3990 3994 public AttributeList setAttributes(AttributeList attributes) { 3995 return null; 3998 } 3999 4000 4003 public AttributeList getAttributes(String [] attributeNames) { 4004 4005 return null; 4008 } 4009 4010 4014 public MBeanInfo getMBeanInfo() { 4015 return dMBeanInfo; 4018 } 4019 4020 4021 4026 4027 4030 public Object invoke(String operationName, Object params[], 4031 String signature[]) throws MBeanException , 4032 ReflectionException { 4033 if (operationName == null) { 4035 throw new RuntimeOperationsException (new IllegalArgumentException ( 4036 "Operation name cannot be null"), 4037 "Cannot invoke a null operation in " + dClassName); 4038 } 4039 if (operationName.equals("getAppName")) { 4041 return getAppName(); 4042 } else if (operationName.equals("getAppContext")) { 4043 return getAppContext(); 4044 } else if (operationName.equals("getAppRealContext")) { 4045 return getAppRealContext(); 4046 } else { 4047 throw new ReflectionException (new NoSuchMethodException (operationName), 4049 "Cannot find the operation " + 4050 operationName + " in " + dClassName); 4051 } 4052 } 4053 4054 } 4055} | Popular Tags |