Wiring with Spring (PU Configuration)
By now, the implementation of the domain model, DAO, and services is done, but you might have noticed that the picture is not yet complete. The configuration of a space, and types of events that the services should handle are some of the things that are not defined anywhere within the code. Instead, we define all of these in the configuration file (pu.xml) of each processing unit. Each pu.xml appears below on a different tab.
Feeder Processing Unit
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:os-core="http://www.openspaces.org/schema/core" xmlns:os-events="http://www.openspaces.org/schema/events" xmlns:os-remoting="http://www.openspaces.org/schema/remoting" xmlns:os-sla="http://www.openspaces.org/schema/sla" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.openspaces.org/schema/core http://www.openspaces.org/schema/core/openspaces-core.xsd http://www.openspaces.org/schema/events http://www.openspaces.org/schema/events/openspaces-events.xsd http://www.openspaces.org/schema/remoting http://www.openspaces.org/schema/remoting/openspaces-remoting.xsd http://www.openspaces.org/schema/sla http://www.openspaces.org/schema/sla/openspaces-sla.xsd"> <!-- Spring property configurer which allows us to use system properties (such as user.name). Here we define a common numberOfAccounts property to be injected to the AccountDataLoader and to the OrderEventFeeder beans --> <bean id="propertiesConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="properties"> <props> <prop key="numberOfAccounts">100</prop> </props> </property> </bean> <!-- This component is the RequiredAnnotationBeanPostProcessor class. This is a special BeanPostProcessor implementation that is @Required-aware and actually provides the 'blow up if this required property has not been set' logic. It is very easy to configure; simply drop the following bean definition into your Spring XML configuration. --> <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/> <!-- Enables the usage of @GigaSpaceContext annotation based injection. --> <os-core:giga-space-context/> <!-- A bean representing AccountDataDAO using GigaSpaces (an IAccountDataDAO implementation) --> <bean id="accountDataDAO" class="org.openspaces.example.oms.common.AccountDataDAO"/> <!-- A bean representing a space (an IJSpace implementation). Note, we perform a lookup on the space since we are working against a remote space. --> <os-core:space id="space" url="jini://*/*/spaceOMS"/> <!-- OpenSpaces simplified space API built on top of IJSpace/JavaSpace. --> <os-core:giga-space id="gigaSpace" space="space"/> <!-- The AccountData loader bean, writing new 750 unique AccountData objects to the space. --> <bean id="accountDataLoader" class="org.openspaces.example.oms.feeder.AccountDataLoader"> <property name="numberOfAccounts" value="${numberOfAccounts}" /> <property name="accountDataDAO" ref="accountDataDAO" /> </bean> <!-- The Data feeder bean, writing new OrderEvents objects to the space in a constant interval. the depends-on attribute ensures the feeder will start only after the feeder bean is done --> <bean id="orderEventFeeder" class="org.openspaces.example.oms.feeder.OrderEventFeeder" depends-on="accountDataLoader"> <property name="numberOfAccounts" value="${numberOfAccounts}" /> </bean> </beans> Choose another tab (back to top) Runtime Processing Unit <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:os-core="http://www.openspaces.org/schema/core" xmlns:os-events="http://www.openspaces.org/schema/events" xmlns:os-remoting="http://www.openspaces.org/schema/remoting" xmlns:os-sla="http://www.openspaces.org/schema/sla" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.openspaces.org/schema/core http://www.openspaces.org/schema/core/openspaces-core.xsd http://www.openspaces.org/schema/events http://www.openspaces.org/schema/events/openspaces-events.xsd http://www.openspaces.org/schema/remoting http://www.openspaces.org/schema/remoting/openspaces-remoting.xsd http://www.openspaces.org/schema/sla http://www.openspaces.org/schema/sla/openspaces-sla.xsd"> <!-- Spring property configurer which allows us to use system properties (such as user.name). --> <bean id="propertiesConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> <!-- This component is the RequiredAnnotationBeanPostProcessor class. This is a special BeanPostProcessor implementation that is @Required-aware and actually provides the 'blow up if this required property has not been set' logic. It is very easy to configure; simply drop the following bean definition into your Spring XML configuration. --> <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/> <!-- Enables the usage of @GigaSpaceContext annotation based injection. --> <os-core:giga-space-context/> <!-- Loads a Spring application context (based on a separate Spring xml configuration file - here mode.xml) only the if processing unit / space is in primary mode and unload it when the processing unit / space is in backup mode. --> <os-core:context-loader id="spaceMode" location="classpath:/META-INF/spring/mode/mode.xml"/> <!-- A bean representing AccountDataDAO using GigaSpaces (an IAccountDataDAO implementation) --> <bean id="accountDataDAO" class="org.openspaces.example.oms.common.AccountDataDAO"/> <!-- A bean representing a space (an IJSpace implementation). Note, we do not specify here the cluster topology of the space. It is declared outside of the processing unit or within the SLA bean. --> <os-core:space id="space" url="/./spaceOMS"/> <!-- OpenSpaces simplified space API built on top of IJSpace/JavaSpace. --> <os-core:giga-space id="gigaSpace" space="space" tx-manager="transactionManager"/> <!-- Defines a local Jini transaction manager. --> <os-core:local-tx-manager id="transactionManager" space="space"/> <!-- The orderEvent validator bean --> <bean id="orderEventValidator" class="org.openspaces.example.oms.runtime.OrderEventValidator"> <property name="accountDataDAO" ref="accountDataDAO" /> </bean> <!-- A polling event container that performs (by default) polling take operations against the space using the provided template (in our case, the new orderEvents objects). Once a match is found, the orderEvent processor bean event listener is triggered using the annotation adapter. --> <os-events:polling-container id="orderEventValidatorPollingEventContainer" giga-space="gigaSpace"> <os-events:tx-support tx-manager="transactionManager"/> <os-core:template> <bean class="org.openspaces.example.oms.common.OrderEvent"> <property name="status" value="New"/> </bean> </os-core:template> <os-events:listener> <os-events:annotation-adapter> <os-events:delegate ref="orderEventValidator"/> </os-events:annotation-adapter> </os-events:listener> </os-events:polling-container> <!-- The orderEvent processor bean --> <bean id="orderEventProcessor" class="org.openspaces.example.oms.runtime.OrderEventProcessor"> <property name="accountDataDAO" ref="accountDataDAO" /> </bean> <!-- A polling event container that performs (by default) polling take operations with txn support against the space using the provided template (in our case, the pending orderEvent objects). Once a match is found, the data processor bean event listener is triggered using the annotation adapter. --> <os-events:polling-container id="orderEventProcessorPollingEventContainer" giga-space="gigaSpace"> <os-events:tx-support tx-manager="transactionManager"/> <os-core:template> <bean class="org.openspaces.example.oms.common.OrderEvent"> <property name="status" value="Pending"/> </bean> </os-core:template> <os-events:listener> <os-events:annotation-adapter> <os-events:delegate ref="orderEventProcessor"/> </os-events:annotation-adapter> </os-events:listener> </os-events:polling-container> </beans> Choose another tab (back to top) Statistics Processing Unit <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:os-core="http://www.openspaces.org/schema/core" xmlns:os-events="http://www.openspaces.org/schema/events" xmlns:os-remoting="http://www.openspaces.org/schema/remoting" xmlns:os-sla="http://www.openspaces.org/schema/sla" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.openspaces.org/schema/core http://www.openspaces.org/schema/core/openspaces-core.xsd http://www.openspaces.org/schema/events http://www.openspaces.org/schema/events/openspaces-events.xsd http://www.openspaces.org/schema/remoting http://www.openspaces.org/schema/remoting/openspaces-remoting.xsd http://www.openspaces.org/schema/sla http://www.openspaces.org/schema/sla/openspaces-sla.xsd"> <!-- Simply use SLA to add 3 monitors that uses the outputOrderEvent bean to count the globaly processed and rejected due to matching account not found orderEvents objects and count the number of new orderEvents written. --> <os-sla:sla> <os-sla:monitors> <os-sla:bean-property-monitor name="Written OrderEvent" bean-ref="outputOrderEvent" property-name="orderEventWrittenCounter" /> <os-sla:bean-property-monitor name="Processed OrderEvent" bean-ref="outputOrderEvent" property-name="orderEventProcessedCounter" /> <os-sla:bean-property-monitor name="AccountNotFound OrderEvent" bean-ref="outputOrderEvent" property-name="orderEventAccountNotFoundCounter" /> </os-sla:monitors> </os-sla:sla> <!-- Spring property configurer which allows us to use system properties (such as user.name). --> <bean id="propertiesConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> <!-- Enables the usage of @GigaSpaceContext annotation based injection. --> <os-core:giga-space-context/> <!-- A bean representing a space (an IJSpace implementation). Note, we perform a lookup on the space since we are working against a remote space. --> <os-core:space id="space" url="jini://*/*/spaceOMS"/> <!-- OpenSpaces simplified space API built on top of IJSpace/JavaSpace. --> <os-core:giga-space id="gigaSpace" space="space"/> <!-- This bean outputs the userName and balance attributes of the AccountData object --> <bean id="outputAccountData" class="org.openspaces.example.oms.stats.OutputAccountData"/> <!-- The notification container, registers for notification on every AccountData write or update and invokes the outputAccountData listner on a copy of the object that triggered the event --> <os-events:notify-container id="accountDataNotifyContainer" giga-space="gigaSpace" com-type="UNICAST"> <!-- The notification will occur upon write or update --> <os-events:notify write="true" update="true"/> <os-core:template> <bean class="org.openspaces.example.oms.common.AccountData"> <!-- using template without properties to get all accountData objects --> </bean> </os-core:template> <os-events:listener> <os-events:annotation-adapter> <!-- The adapter activates the outputAccountData.<method annotated as @SpaceDataEvent> on the accontData object --> <os-events:delegate ref="outputAccountData"/> </os-events:annotation-adapter> </os-events:listener> </os-events:notify-container> <!-- This bean outputs the attributes of the orderEvent object --> <bean id="outputOrderEvent" class="org.openspaces.example.oms.stats.OutputOrderEventCounter"/> <!-- The notification container, registers for notification on every orderEvent write (notify on write is default), invokes the outputOrderEvent listner on a copy of the object that triggered the event --> <os-events:notify-container id="orderEventNotifyContainer" giga-space="gigaSpace"> <os-core:template> <bean class="org.openspaces.example.oms.common.OrderEvent"> </bean> </os-core:template> <os-events:listener> <os-events:annotation-adapter> <os-events:delegate ref="outputOrderEvent"/> </os-events:annotation-adapter> </os-events:listener> </os-events:notify-container> </beans> Choose another tab (back to top)
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |