public static void main(String[] args) { ShutdownHook target = new AbstractShutdownHook() { @Override public void release() { map.clear(); System.out.println("map size : " + map.size()); } @Override public void doExecute() { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); String vmName = bean.getName(); long pid = Long.valueOf(vmName.split("@")[0]); System.out.println("pid : " + pid); int count = 0; while (true) { Date systemDate = new Date(); map.put(Integer.valueOf(count++), systemDate); System.out.println("map size : " + map.size()); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }; target.execute(); }
/** * The main method responsible for starting the coadunation base. * * @param args the command line arguments */ public static void main() { try { String logFile = System.getProperty("Log.File"); if (logFile.endsWith("properties")) { System.out.println("Initing the log file from properties."); PropertyConfigurator.configure(logFile); } else if (logFile.endsWith("xml")) { System.out.println("Initing the log file from xml."); DOMConfigurator.configure(logFile); } else { System.out.println("Using the basic configuration."); BasicConfigurator.configure(); } System.out.println("Start"); Runner runner = new Runner(); ShutdownHook shutdownHook = new ShutdownHook(); Runtime.getRuntime().addShutdownHook(shutdownHook); System.out.println("Core initialization complete"); System.out.println("Waiting for deployment to complete"); shutdownHook.monitor(); runner.shutdown(); shutdownHook.notifyOfCompletion(); log.info("Shut down complete"); } catch (Exception ex) { System.out.println("Failed to run the Coadunation base [" + ex.getMessage() + "]"); ex.printStackTrace(System.out); System.exit(-1); } }
/** Invoke {@link ShutdownHook}s. */ protected void destroy() { for (ShutdownHook h : shutdownHooks) { try { h.shutdown(); } catch (Exception ex) { logger.warn("", ex); } } }
/** Invoke {@link ShutdownHook}s. */ protected void destroy() { for (ShutdownHook h : shutdownHooks) { try { h.shutdown(); } catch (Exception ex) { logger.warn("", ex); } } properties.clear(); shutdownHooks.clear(); startUpHook.clear(); atmosphereHandlerConfig.clear(); }
public HostControllerBootstrap( final HostControllerEnvironment environment, final String authCode) { this.environment = environment; this.authCode = authCode; this.shutdownHook = new ShutdownHook(); this.serviceContainer = shutdownHook.register(); }
void setNiFiCommandControlPort(final int port, final String secretKey) { this.ccPort = port; this.secretKey = secretKey; if (shutdownHook != null) { shutdownHook.setSecretKey(secretKey); } final File statusFile = getStatusFile(defaultLogger); final Properties nifiProps = new Properties(); if (nifiPid != -1) { nifiProps.setProperty("pid", String.valueOf(nifiPid)); } nifiProps.setProperty("port", String.valueOf(ccPort)); nifiProps.setProperty("secret.key", secretKey); try { saveProperties(nifiProps, defaultLogger); } catch (final IOException ioe) { defaultLogger.warn( "Apache NiFi has started but failed to persist NiFi Port information to {} due to {}", new Object[] {statusFile.getAbsolutePath(), ioe}); } defaultLogger.info( "Apache NiFi now running and listening for Bootstrap requests on port {}", port); }
/** * Start the host controller services. * * @throws Exception */ public void bootstrap() throws Exception { final HostRunningModeControl runningModeControl = environment.getRunningModeControl(); final ControlledProcessState processState = new ControlledProcessState(true); shutdownHook.setControlledProcessState(processState); ServiceTarget target = serviceContainer.subTarget(); ControlledProcessStateService controlledProcessStateService = ControlledProcessStateService.addService(target, processState).getValue(); RunningStateJmx.registerMBean( controlledProcessStateService, null, runningModeControl, Type.from(environment.getProcessType().name())); final HostControllerService hcs = new HostControllerService(environment, runningModeControl, authCode, processState); target.addService(HostControllerService.HC_SERVICE_NAME, hcs).install(); }
public void handle(HttpRequest request, HttpResponse response) { String msg = ("Shutting down server."); System.out.println(msg); response.setBody(msg); ShutdownHook.shutdown(); }