| 360 | === Reacting to configuration changes === |
| 361 | |
| 362 | The `opengrid-config.xml` is normally read in fully when the Open Grid Scheduler service extension is started. Changes to the configuration file are not applied until the service is re-started. For some extensions it may be critical to be able to detect when this happens. Luckily, everything that is needed is already built into the BASE core API. Extensions that need to know when the Open Grid Scheduler service is stoppped or started simply need to register an event handler with the manager in BASE. The event handler should listen to `SERVICE_STOPPED` or `SERVICE_STARTED` events for the `net.sf.basedb.opengrid.service` extension. |
| 363 | |
| 364 | {{{ |
| 365 | // We need a filter that listens for SERVICE_STARTED event related to the Open Grid Scheduler service |
| 366 | EventFilter serviceStarted = new ExtensionEventFilter( |
| 367 | "net.sf.basedb.opengrid.service", Services.SERVICE_STARTED); |
| 368 | |
| 369 | // We need to implement an event handler which, for example, reloads our own configuration file |
| 370 | EventHandler handler = new MyEventHandler(); |
| 371 | |
| 372 | // Register the event handler with BASE |
| 373 | // The classloader parameter is important for not leaking memory |
| 374 | // in case this extension is updated or uninstalled |
| 375 | Registry registry = Application.getExtensionsManager().getRegistry(); |
| 376 | registry.registerEventHandler(handler, serviceStarted , this.getClass().getClassLoader()); |
| 377 | }}} |
| 378 | |