Summary: Service reloading allows you to reload business logic without bringing down the Processing Unit.
OverviewThe service reloading feature allows you to reload business logic (Spring beans) without shutting down the application or undeploying a Processing Unit. In order to do this, any reloadable business logic needs to be defined in a special Spring XML file. The Spring XML file is then referenced very similar to the Space Mode Context Loader from inside the pu.xml.
An example that demonstrates this is provided in the Solutions and Best Practices Refreshable Business Logic Example page. Configuring Reloadable Business LogicLets assume we have business logic that we would like to reload at some point in time after our Processing Unit has been deployed. Here is an example of such business logic: public class RefreshableBean implements InitializingBean, DisposableBean { @GigaSpaceContext(name = "gigaSpace") private GigaSpace gigaSpace; public void afterPropertiesSet() throws Exception { System.out.println("BEAN LOADED, SPACE [" + gigaSpace + "]"); } public void destroy() throws Exception { System.out.println("BEAN DESTROYED, SPACE [" + gigaSpace + "]"); } } We then need to define it in a specific Spring XML file (lets assume it is named refreshable-beans.xml): <beans ... > <os-core:giga-space-context /> <bean id="refreshableBean" class="org.openspaces.example.data.processor.RefreshableBean"/> </beans>
To enable service reloading, in our processing unit pu.xml file, we reference the refreshable-beans.xml file in the following manner: <beans ...> ... <os-core:refreshable-context-loader id="refreshableExample" location="classpath:/META-INF/spring/refreshable-beans.xml"/> </beans>
Above configuration will let you refresh the code defined in the refreshable context. Actual execution of this reloading of context can be done using OpenSpaces sync remoting, which allows you to broadcast the reload operation to all active cluster members. Here is how this is configured: <beans ...> <os-core:space id="space" url="/./space"> <os-core:filter-provider ref="remotingServiceExporter"/> </os-core:space> <os-remoting:service-exporter id="remotingServiceExporter"> <os-remoting:service ref="refreshableExample"/> </os-remoting:service-exporter> </beans> Reloading Business LogicWhen there is a change in business logic for any beans defined in the refreshable context and these changes are ready to be applied to the cluster, copy the new classes into the GigaSpaces deploy folder of GSM machine(s) and work folder of each cluster node (default location, <GigaSpacesRoot>/work/processing-units/<puInstance>) and execute the reload command as below: java -cp [list of jar files, including JSpace, openspaces and spring] RefreshContextLoaderExecutor jini://*/*/space
As a result of the above command, all the beans defined in the refreshable context are destroyed and fresh copies of these beans are re-created using the new class definitions in the work folder. Your new version of business logic is now ready without brining down the cluster. Other Considerations
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |