|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 5
First, import defaultSplitterContext.xml
:
<import resource="classpath:defaultSplitterContext.xml"/>
Second, declare thedelayedServiceImplementationbean, which contains the implementation we are trying to parallelize:
<bean id="delayedServiceImpl" class="net.sourceforge.offsprings.examples.DelayedServiceImpl"/>
Third, declare the AOP Proxy beandelayedService, which acts as a foundation for the point cut interceptor. In summary, thedelayedServiceproxy intercepts all calls to theDelayedServiceinterface and redirects them through the splitter (beansplitterAdviceDelayedService) while using the actual implementation indelayedServiceImplementation:
"target" is the delayedServiceImplementation bean.
"interceptorNames" is the splitterAdvisorDelayedService bean.
<bean id="delayedService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>net.sourceforge.offsprings.examples.DelayedService</value>
</property>
<property name="interceptorNames">
<list>
<value>splitterAdvisorDelayedService</value>
</list>
</property>
<property name="target">
<ref bean="delayedServiceImpl"/>
</property>
</bean>
Fourth, declare thesplitterAdvisorDelayedServicebean which effects the point cut to the splitter:
Intercept all methods with names matching the "pattern" ".*"
Apply the "advice" given by the splitterAdviceDelayedService bean
<bean id="splitterAdvisorDelayedService" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="pattern">
<value>.*</value>
</property>
<property name="advice">
<ref bean="splitterAdviceDelayedService"/>
</property>
</bean>
Fifth, declare the beansplitterAdviceDelayedService, which extends the default advicedefaultSplitterAdvice. This bean provides the core functionality of the whole application; it's a splitter.
We can reconfigure splitter parameters as necessary:
parallelism is the number of separate threads which will be in parallel
batchsize is the number of items that will be processed in each batch
Some optional properties are only relevant for XMLInputStreamresults:
docPath is an XML xpath expression to the document element (e.g. delayed_service/docs/doc) within the XML. If omitted the elements in each batches root elements are merged.
metaPath is an xpath expression to the element containing meta information for each batch. If omitted, it is assumed there is no meta
information.
metaXSLTTemplate provides the name of an XSL template that will be used to merge the content in the location designated by metaPath.
<bean id="splitterAdviceDelayedService" parent="defaultSplitterAdvice">
<property name="parallelism" value="10"/>
<property name="batchsize" value="10"/>
<property name = "properties">
<map>
<entry key="docPath" value="delayed_service/docs/doc" />
<entry key="metaPath" value="delayed_service/meta_info" />
<entry key="metaXSLTTemplate" value="meta.xsl" />
</map>
</property>
</bean>
SplitterAdvice class (let's call it splitter) is the foundation of the whole application. It orchestrates the splitting of the process in the parallel threads and assembling
the result of each thread execution. Splitter is an AOP advice; therefore, it implements the Spring MethodInterceptor interface.
As a result, all calls are redirected to the method invoke(MethodInvocation invocation). The MethodInvocation method must know which argument represents the collection of document identifiers to split them into the chunks. The Parameter
idsArgumentPosition can be set in application context to specify which argument contains the identifiers.