/** * Loads plugins from directory {@literal webRoot/plugins/}. */ public void load() { Stopwatchs.start("Load Plugins"); classLoaders.clear(); final ServletContext servletContext = AbstractServletListener.getServletContext(); final Set<String> pluginDirPaths = servletContext.getResourcePaths("/plugins"); final List<AbstractPlugin> plugins = new ArrayList<>(); if (null != pluginDirPaths) { for (final String pluginDirPath : pluginDirPaths) { try { LOGGER.log(Level.INFO, "Loading plugin under directory[{0}]", pluginDirPath); final AbstractPlugin plugin = load(pluginDirPath, pluginCache); if (plugin != null) { plugins.add(plugin); } } catch (final Exception e) { LOGGER.log(Level.WARN, "Load plugin under directory[" + pluginDirPath + "] failed", e); } } } eventManager.fireEventSynchronously(new Event<>(PLUGIN_LOADED_EVENT, plugins)); Stopwatchs.end(); }
/** * Gets stopwatch from the specified parent stopwatch with the specified task title. * * @param parent the specified parent * @param taskTitle the specified task title * @return stopwatch, returns {@code null} if not found */ private static Stopwatch get(final Stopwatch parent, final String taskTitle) { if (taskTitle.equals(parent.getTaskTitle())) { return parent; } for (final Stopwatch leaf : parent.getLeaves()) { final Stopwatch ret = get(leaf, taskTitle); if (null != ret) { return ret; } } return null; }
/** * Ends the timing of the recent task started by {@link #start(java.lang.String)}. */ public static void end() { final Stopwatch root = STOPWATCH.get(); if (null == root) { return; // Donoting.... } final Stopwatch recent = getRecentRunning(root); if (null == recent) { return; } recent.setEndTime(System.currentTimeMillis()); // Ends timing }
/** * Loads plugins from directory {@literal webRoot/plugins/}. */ public void load() { Stopwatchs.start("Load Plugins"); classLoaders.clear(); final ServletContext servletContext = AbstractServletListener.getServletContext(); final Set<String> pluginDirPaths = servletContext.getResourcePaths("/plugins"); final List<AbstractPlugin> plugins = new ArrayList<>(); if (null != pluginDirPaths) { for (final String pluginDirPath : pluginDirPaths) { try { LOGGER.log(Level.INFO, "Loading plugin under directory[{0}]", pluginDirPath); final AbstractPlugin plugin = load(pluginDirPath, pluginCache); if (plugin != null) { plugins.add(plugin); } } catch (final Exception e) { LOGGER.log(Level.WARN, "Load plugin under directory[" + pluginDirPath + "] failed", e); } } } eventManager.fireEventSynchronously(new Event<>(PLUGIN_LOADED_EVENT, plugins)); Stopwatchs.end(); }
/** * Starts a task timing with the specified task title. * * @param taskTitle the specified task title */ public static void start(final String taskTitle) { Stopwatch root = STOPWATCH.get(); if (null == root) { root = new Stopwatch(taskTitle); // Creates the root stopwatch STOPWATCH.set(root); return; } final Stopwatch recent = getRecentRunning(STOPWATCH.get()); if (null == recent) { return; } recent.addLeaf(new Stopwatch(taskTitle)); // Adds sub-stopwatch }
final Stopwatch stopwatch = get(root, taskTitle);
/** * Gets the recent running stopwatch with the specified parent stopwatch. * * @param parent the specified parent stopwatch * @return the recent stopwatch, returns {@code null} if not found */ private static Stopwatch getRecentRunning(final Stopwatch parent) { if (null == parent) { return null; } final List<Stopwatch> leaves = parent.getLeaves(); if (leaves.isEmpty()) { if (parent.isRunning()) { return parent; } else { return null; } } for (int i = leaves.size() - 1; i > -1; i--) { final Stopwatch leaf = leaves.get(i); if (leaf.isRunning()) { return getRecentRunning(leaf); } else { continue; } } return parent; }
/** * Gets stopwatch from the specified parent stopwatch with the specified task title. * * @param parent the specified parent * @param taskTitle the specified task title * @return stopwatch, returns {@code null} if not found */ private static Stopwatch get(final Stopwatch parent, final String taskTitle) { if (taskTitle.equals(parent.getTaskTitle())) { return parent; } for (final Stopwatch leaf : parent.getLeaves()) { final Stopwatch ret = get(leaf, taskTitle); if (null != ret) { return ret; } } return null; }
/** * Ends the timing of the recent task started by {@link #start(java.lang.String)}. */ public static void end() { final Stopwatch root = STOPWATCH.get(); if (null == root) { return; // Donoting.... } final Stopwatch recent = getRecentRunning(root); if (null == recent) { return; } recent.setEndTime(System.currentTimeMillis()); // Ends timing }
final Stopwatch stopwatch = get(root, taskTitle);
/** * Starts a task timing with the specified task title. * * @param taskTitle the specified task title */ public static void start(final String taskTitle) { Stopwatch root = STOPWATCH.get(); if (null == root) { root = new Stopwatch(taskTitle); // Creates the root stopwatch STOPWATCH.set(root); return; } final Stopwatch recent = getRecentRunning(STOPWATCH.get()); if (null == recent) { return; } recent.addLeaf(new Stopwatch(taskTitle)); // Adds sub-stopwatch }
/** * Gets the recent running stopwatch with the specified parent stopwatch. * * @param parent the specified parent stopwatch * @return the recent stopwatch, returns {@code null} if not found */ private static Stopwatch getRecentRunning(final Stopwatch parent) { if (null == parent) { return null; } final List<Stopwatch> leaves = parent.getLeaves(); if (leaves.isEmpty()) { if (parent.isRunning()) { return parent; } else { return null; } } for (int i = leaves.size() - 1; i > -1; i--) { final Stopwatch leaf = leaves.get(i); if (leaf.isRunning()) { return getRecentRunning(leaf); } else { continue; } } return parent; }