Setting up properties for broker, worker and agent - beans.xml configuration file
You are able to set properties for broker, worker and agent simply by
creating appropriate bean with properties or constructor arguments .
Below you will find some examples.
Let's start from defining broker. Currently DAC is supporting two kinds of brokers: Cajo broker and JMS broker using ActiveMQ as provider.
To define CajoBroker working localhost on port eg. 1198 simply use:
<bean id="cajoBroker" class="org.dacframe.broker.CajoBroker" lazy-init="true"> <constructor-arg value="//localhost:1198/broker" /> </bean>
To define JMS broker using ActiveMQ as provider, which will be working localhost on port eg. 61616 simply use:
<bean id="activeMQBroker" class="org.dacframe.broker.ActiveMQBroker" lazy-init="true"> <constructor-arg value="tcp://localhost:61616"/> </bean>
To define Single Threaded Worker simply use:
<bean id="workerSingleThreaded" class="org.dacframe.worker.WorkerSingleThreaded" lazy-init="true"> <property name="cacheService"> <bean class="org.dacframe.cs.CacheServiceHM"/> </property> <property name="agentBroker"> <ref bean="cajoBroker"/> </property> </bean>
Where:
- cacheService is an injected implementation of the CacheService
- agentBroker is an injected implementation of the AgentBroker (here we use reference to the broker defined above)
To define agent which should be passed for calculation use:
<bean id="agentPowerOfTwo" class="org.dacframe.example.poweroftwo.AgentPowerOfTwo" lazy-init="true"> <constructor-arg value="10" /> </bean>
Where:
- class parameter contains class name of your agent
Launcher which is responsible for starting work can be defined as follows:
<bean id="launcher" class="org.dacframe.Launcher" lazy-init="true">
<property name="broker">
<ref bean="cajoBroker"/>
</property>
<property name="agent">
<ref bean="agentPowerOfTwo"/>
</property>
</bean>
As you see in launcher configuration you use references to broker and agent definitions.
Complete example of the beans.xml file you can find below.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="cajoBroker" class="org.dacframe.broker.CajoBroker" lazy-init="true"> <constructor-arg value="//localhost:1198/broker" /> </bean> <bean id="workerSingleThreaded" class="org.dacframe.worker.WorkerSingleThreaded" lazy-init="true"> <property name="cacheService"> <bean class="org.dacframe.cs.CacheServiceHM"/> </property> <property name="agentBroker"> <ref bean="cajoBroker"/> </property> </bean> <bean id="agentPowerOfTwo" class="org.dacframe.example.poweroftwo.AgentPowerOfTwo" lazy-init="true"> <constructor-arg value="10" /> </bean> <bean id="launcher" class="org.dacframe.Launcher" lazy-init="true"> <property name="broker"> <ref bean="cajoBroker"/> </property> <property name="agent"> <ref bean="agentPowerOfTwo"/> </property> </bean> </beans>



