1 24 25 package org.objectweb.cjdbc.controller.core.shutdown; 26 27 import java.io.File ; 28 import java.util.ArrayList ; 29 30 import org.objectweb.cjdbc.common.exceptions.ShutdownException; 31 import org.objectweb.cjdbc.common.i18n.Translate; 32 import org.objectweb.cjdbc.controller.core.Controller; 33 import org.objectweb.cjdbc.controller.core.ControllerConstants; 34 import org.objectweb.cjdbc.controller.core.ControllerServerThread; 35 import org.objectweb.cjdbc.controller.core.ReportManager; 36 import org.objectweb.cjdbc.controller.jmx.MBeanServerManager; 37 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase; 38 39 46 public abstract class ControllerShutdownThread extends ShutdownThread 47 { 48 protected Controller controller; 49 50 57 public ControllerShutdownThread(Controller controller, int level) 58 { 59 super(level); 60 this.controller = controller; 61 } 62 63 66 protected void shutdownJmxAgent() 67 { 68 logger.info("Shutting down Jmx Agent"); 69 try 70 { 71 if (controller.getJmxEnable()) 72 MBeanServerManager.setJmxEnabled(false); 73 } 74 catch (Exception jme) 75 { 76 logger.error(Translate.get("controller.shutdown.jmx.error", jme 77 .getMessage()), jme); 78 } 80 } 81 82 85 protected void shutdownDatabases() 86 { 87 logger.info("Shutting down databases"); 88 try 89 { 90 ArrayList listvb = controller.getVirtualDatabases(); 92 int nbvb = listvb.size(); 93 for (int i = 0; i < nbvb; i++) 94 { 95 logger.info("Shutting down database:" 96 + ((VirtualDatabase) listvb.get(i)).getVirtualDatabaseName() 97 + " with level:" + this.shutdownLevel); 98 ((VirtualDatabase) listvb.get(i)).shutdown(this.shutdownLevel); 99 logger.info("Database:" 100 + ((VirtualDatabase) listvb.get(i)).getVirtualDatabaseName() 101 + " is shutdown"); 102 } 103 } 104 catch (Exception e) 105 { 106 logger.error(Translate.get("controller.shutdown.database.error", e)); 107 } 108 } 109 110 118 protected void shutdownServerConnectionThread(int joinTimeoutInMillis) 119 throws ShutdownException 120 { 121 if (logger.isDebugEnabled()) 122 logger.debug("Shutting down ControllerServerThread"); 123 try 124 { 125 ControllerServerThread thread = controller.getConnectionThread(); 127 if (thread != null && !thread.isShuttingDown()) 128 { 129 thread.shutdown(); 130 logger.info("Waiting for controller thread termination."); 131 thread.join(joinTimeoutInMillis); 132 } 133 } 134 catch (Exception e) 135 { 136 throw new ShutdownException(e); 137 } 138 } 139 140 143 protected void generateReportIfNeeded() 144 { 145 ReportManager report = controller.getReport(); 146 if (report != null && report.isGenerateOnShutdown()) 147 { 148 report.startReport(); 149 report.generate(); 150 logger.info(Translate.get("fatal.report.generated", report 151 .getReportLocation() 152 + File.separator + ControllerConstants.REPORT_FILE)); 153 } 154 } 155 156 } | Popular Tags |