/** * Unregisters a listener for the IPluginEvent callback event. * * @param listener Listener to be unregistered. */ public void unregisterListener(IPluginEventListener listener) { if (pluginEventListeners2 != null && pluginEventListeners2.contains(listener)) { pluginEventListeners2.remove(listener); listener.onPluginEvent(new PluginEvent(this, PluginAction.UNSUBSCRIBE)); } }
/** * Subscribe/unsubscribe container. */ @Override public void onPluginEvent(PluginEvent event) { ElementPlugin plugin = event.getPlugin(); switch (event.getAction()) { case SUBSCRIBE: init(); plugins.add(plugin); plugin.setDisabled(isDisabled()); break; case UNSUBSCRIBE: plugins.remove(plugin); plugin.setDisabled(false); break; } }
private void onAction(PluginEvent event) { PluginException exception = null; PluginAction action = event.getAction(); boolean debug = log.isDebugEnabled();
/** * Listen for plugin lifecycle events. * * @see org.carewebframework.shell.plugins.IPluginEventListener#onPluginEvent(org.carewebframework.shell.plugins.PluginEvent) */ @Override public void onPluginEvent(PluginEvent event) { switch (event.getAction()) { case SUBSCRIBE: // Upon initial subscription, begin listening for specified generic events. plugin = event.getPlugin(); doSubscribe(true); break; case LOAD: // Stop listening once loaded. plugin.unregisterListener(this); break; case UNSUBSCRIBE: // Stop listening for generic events once unsubscribed from plugin events. doSubscribe(false); break; } }
/** * Registers a listener for the IPluginEventListener callback event. If the listener has already * been registered, the request is ignored. * * @param listener Listener to be registered. */ public void registerListener(IPluginEventListener listener) { if (pluginEventListeners2 == null) { pluginEventListeners2 = new ArrayList<>(); } if (!pluginEventListeners2.contains(listener)) { pluginEventListeners2.add(listener); listener.onPluginEvent(new PluginEvent(this, PluginAction.SUBSCRIBE)); } }
/** * Notify all plugin callbacks of the specified action. * * @param action Action to perform. * @param data Event-dependent data (may be null). * @param async If true, callbacks are done asynchronously. */ private void executeAction(PluginAction action, boolean async, Object data) { if (hasListeners() || action == PluginAction.LOAD) { PluginEvent event = new PluginEvent(this, action, data); if (async) { EventUtil.post(event); } else { onAction(event); } } }