Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can have your plugin service publish an event when it completes then listen for that event in your main application. I have used this pattern a few times and it has been a very convenient way to decouple various pieces of of my application. To do this, create an <a href="http://static.springsource.org/spring/docs/1.2.9/api/org/springframework/context/ApplicationEvent.html" rel="nofollow">event</a> class.</p> <pre><code>class PluginEvent extends ApplicationEvent { public PluginEvent(source) { super(source) } } </code></pre> <p>Then, have your plugin service implement <code>ApplicationContextAware</code>. That gives your plugin a way to publish your events</p> <pre><code>class PluginService implements ApplicationContextAware { def applicationContext def serviceMethod() { //do stuff publishPluginEvent() } private void publishPluginEvent() { def event = new PluginEvent(this) applicationContext.publishEvent(event) } } </code></pre> <p>Then in your main application, create a listener service that will respond when the event is published:</p> <pre><code>class ApplicationService implements ApplicationListener&lt;PluginEvent&gt; { void onApplicationEvent(PluginEvent event) { //whatever you want to do in your app when // the plugin service fires. } } </code></pre> <p>This listener doesn't need to be a Grails Service, you can just use a POJO/POGO, but you'll need to configure it as a spring bean inside <code>resources.groovy</code>.</p> <p>I have been using this approach recently and it has worked well for me. It's definitely a nice tool to have in your Grails toolbox. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload