@Override public void runLocally(InfoRequest infoRequest) throws WebException { if (infoRequest instanceof SetupRequest) { throw new NoServersException("Set-up requests can not be run locally."); } logger.getDebugLogger().logOn(DebugChannels.INFO_REQUESTS, "Local: " + infoRequest.getClass().getSimpleName()); infoRequest.runLocally(); } }
private void setDebugMode() { CombineDebugLogger debugLogger = (CombineDebugLogger) logger.getDebugLogger(); String debugMode = config.get(PluginSettings.DEBUG); List<DebugLogger> loggers = new ArrayList<>(); if (Verify.containsOne(debugMode, "true", "both", "all", "console")) { loggers.add(new ConsoleDebugLogger(logger)); } if (Verify.containsOne(debugMode, "true", "both", "all", "file")) { loggers.add(new FolderTimeStampFileDebugLogger(files.getLogsFolder(), () -> errorHandler)); } if (Verify.containsOne(debugMode, "true", "both", "all", "memory")) { loggers.add(debugLogger.getDebugLogger(MemoryDebugLogger.class).orElse(new MemoryDebugLogger())); } debugLogger.setDebugLoggers(loggers.toArray(new DebugLogger[0])); }
/** * Send an InfoRequest to another server or run locally if necessary. * <p> * No calls from non-async thread found on 09.02.2018 * * @param infoRequest InfoRequest to send or run. * @throws WebException If fails. */ public void sendRequest(InfoRequest infoRequest) throws WebException { try { if (!connectionSystem.isServerAvailable()) { logger.getDebugLogger().logOn(DebugChannels.INFO_REQUESTS, "Main server unavailable, running locally."); runLocally(infoRequest); return; } connectionSystem.sendInfoRequest(infoRequest); } catch (WebException original) { try { logger.getDebugLogger().logOn(DebugChannels.INFO_REQUESTS, "Exception during request: " + original.toString() + ", running locally."); runLocally(infoRequest); } catch (NoServersException e2) { throw original; } } }
@Override public void enable() throws EnableException { try { copyDefaults(); config.reorder(Arrays.asList( "Server", "Network", "Plugin", "Database", "Webserver", "Data_gathering", "Time", "Display_options", "Formatting", "World_aliases", "Export", "Plugins" )); config.save(); if (logger.getDebugLogger() instanceof CombineDebugLogger) { setDebugMode(); } } catch (IOException e) { throw new EnableException("Failed to save default config.", e); } theme.enable(); }
exchange.close(); if (inDevMode) { logger.getDebugLogger().logOn( DebugChannels.WEB_REQUESTS, timings.end(requestString).map(Benchmark::toString).orElse("-") + " Code: " + responseCode