1 24 25 package org.continuent.sequoia.controller.core.shutdown; 26 27 import java.io.File ; 28 29 import org.continuent.sequoia.common.exceptions.ShutdownException; 30 import org.continuent.sequoia.common.i18n.Translate; 31 import org.continuent.sequoia.common.util.Constants; 32 import org.continuent.sequoia.controller.core.Controller; 33 import org.continuent.sequoia.controller.core.ControllerConstants; 34 import org.continuent.sequoia.controller.core.ControllerServerThread; 35 import org.continuent.sequoia.controller.core.ReportManager; 36 import org.continuent.sequoia.controller.jmx.MBeanServerManager; 37 import org.continuent.sequoia.controller.jmx.RmiConnector; 38 39 45 public class ControllerShutdownThread extends ShutdownThread 46 { 47 protected Controller controller; 48 49 54 public ControllerShutdownThread(Controller controller) 55 { 56 super(Constants.SHUTDOWN_SAFE); 57 this.controller = controller; 58 } 59 60 63 public void shutdown() throws ShutdownException 64 { 65 logger.info("Starting controller shutdown"); 66 generateReportIfNeeded(); 67 shutdownJmxAgent(); 68 shutdownServerConnectionThread(0); 69 logger.info("Controller shutdown completed"); 70 } 71 72 75 protected void shutdownJmxAgent() 76 { 77 logger.info("Shutting down Jmx Agent"); 78 try 79 { 80 RmiConnector rmiConnector = controller.getRmiConnector(); 81 if (rmiConnector != null) 82 rmiConnector.stop(); 83 MBeanServerManager.stopMBeanServer(); 84 } 85 catch (Exception jme) 86 { 87 logger.error(Translate.get("controller.shutdown.jmx.error", jme 88 .getMessage()), jme); 89 } 91 } 92 93 101 protected void shutdownServerConnectionThread(int joinTimeoutInMillis) 102 throws ShutdownException 103 { 104 if (logger.isDebugEnabled()) 105 logger.debug("Shutting down ControllerServerThread"); 106 try 107 { 108 ControllerServerThread thread = controller.getConnectionThread(); 110 if (thread != null && !thread.isShuttingDown()) 111 { 112 thread.shutdown(); 113 logger.info("Waiting for controller thread termination."); 114 thread.join(joinTimeoutInMillis); 115 } 116 } 117 catch (Exception e) 118 { 119 throw new ShutdownException(e); 120 } 121 } 122 123 126 protected void generateReportIfNeeded() 127 { 128 ReportManager report = controller.getReport(); 129 if (report != null && report.isGenerateOnShutdown()) 130 { 131 report.generate(true); 132 logger.info(Translate.get("fatal.report.generated", report 133 .getReportLocation() 134 + File.separator + ControllerConstants.REPORT_FILE)); 135 } 136 } 137 138 } | Popular Tags |