/** * Registers a new administration command. New commands may not be registered after the service * has been started. * * @param command command to register */ public void registerAdminCommand(AbstractAdminCommand command) { if (command == null) { return; } if (adminService.isRunning()) { throw new IllegalStateException("Admin service is already running"); } for (AbstractAdminCommand adminCommand : adminCommands) { if (adminCommand.getCommandPath().equals(command.getCommandPath())) { throw new IllegalArgumentException( "Another admin command is already registered under the path " + command.getCommandPath()); } } adminCommands.add(command); }
/** Creates and starts the shutdown service. */ public synchronized void start() { if (adminService.isRunning()) { throw new IllegalStateException("Admin service is already running"); } Context commandContext = new Context(adminService, "/", false, false); adminCommands.add(buildShutdownCommand()); ServletHolder servletHolder; for (AbstractAdminCommand command : adminCommands) { servletHolder = new ServletHolder(command); commandContext.addServlet(servletHolder, command.getCommandPath()); } if (adminPassword != null) { FilterHolder passwordFiler = new FilterHolder(new PasswordProtectFilter(adminPassword)); commandContext.addFilter(passwordFiler, "/*", Handler.REQUEST); } JettyRunThread shutdownServiceRunThread = new JettyRunThread(adminService); shutdownServiceRunThread.start(); }