How to start your own DAC agent

You can start DAC agent and also its environment (broker, workers) in three different ways:

  • using prepared Ant targets
  • using java command
  • from java source code

Let say that we want to launch agent AgentPowerOfTwo which is part of the DAC samples (more information how to write your own DAC agent you can find here: Your own DAC agent). Below you will find instructions how to do it using all those methods.

Starting DAC environment using prepared Ant targets

In the base directory of the "power of two" sample (<DAC_distribution>\samples\power_of_two ), you will find the Ant build.xml file containing needed targets.

To start broker, worker and to send agent use

  • ant run-broker-cajo (from one command line window)
  • ant run-worker (from a second command line window)
  • ant send-agent (from a third command line window)

If you like you can optionally start log server

  • ant run-logserver (from a fourth command line window)

In this method all properties for broker, worker and agent are taken form the beans.xml file. Below you will find example content of such file.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

        <!-- activate if you want to use JMS as a transport 
        <bean id="activeMQBroker" class="" lazy-init="true">
                <constructor-arg value="tcp://localhost:61616"/>
        </bean> -->

        <bean id="cajoBroker" class="" lazy-init="true">
                <constructor-arg value="//localhost:1198/broker" />
        <bean id="workerSingleThreaded" class="org.dacframe.worker.WorkerSingleThreaded" lazy-init="true">
                <property name="cacheService">
                        <bean class="org.dacframe.cs.CacheServiceHM"/>
                <property name="agentBroker">
                        <ref bean="cajoBroker"/>
        <bean id="agentPowerOfTwo" class="org.dacframe.example.poweroftwo.AgentPowerOfTwo" lazy-init="true">
          <constructor-arg value="10" />
        <bean id="launcher" class="org.dacframe.Launcher" lazy-init="true">
          <property name="broker">
             <ref bean="cajoBroker"/>
          <property name="agent">
           <ref bean="agentPowerOfTwo"/>


Starting DAC environment using java command

In the base directory of the "power of two" sample (<DAC_distribution>\samples\power_of_two ), you can use following command to start broker, worker and to send agent:

For Windows:


  • java -Dorg.dacframe.workerType=brokerCajo -cp .;%DAC_HOME%\bin;%DAC_HOME%\lib\*;%DAC_HOME%\samples\power_of_two\bin localhost

run worker

  • java -Dorg.dacframe.workerType=workerab -cp .;%DAC_HOME%\bin;%DAC_HOME%\lib\*;%DAC_HOME%\samples\power_of_two\bin org.dacframe.worker.WorkerSingleThreaded

send agent

  • java -cp .;%DAC_HOME%\bin;%DAC_HOME%\lib\*;%DAC_HOME%\samples\power_of_two\bin org.dacframe.Launcher



  • java -Dorg.dacframe.workerType=brokerCajo -cp .:$DAC_HOME/bin:$DAC_HOME/lib/*:$DAC_HOME/samples/power_of_two/bin localhost

run worker

  • java -Dorg.dacframe.workerType=workerab -cp .:$DAC_HOME/bin:$DAC_HOME/lib/*:$DAC_HOME/samples/power_of_two/bin org.dacframe.worker.WorkerSingleThreaded

send agent

  • java -cp .:$DAC_HOME/bin:$DAC_HOME/lib/*:$DAC_HOME/samples/power_of_two/bin org.dacframe.Launcher

Where DAC_HOME is previously set environment variable:



For Windows:


In this method all properties for broker, worker and agent are taken also from the beans.xml file.

Starting DAC environment from java source code

First of all we have to start broker:

 private CajoBroker ab;
  private CajoBrokerServer cajoServer;

  private Thread cajoServerThread = new Thread() {
    public void run() {
        try {
            cajoServer = new CajoBrokerServer("localhost");
        } catch (UnknownHostException e) {
        } catch (RemoteException e) {

  public void setUp() throws Exception {
    ab = new CajoBroker("//localhost:1198/broker");

When broker is started, we can send agent (one session will be created):

  Agent addressee = new AgentStub();
  //assertEquals(0, ab.getBrokerInfo().getNumberOfActiveSessions());
  ab.sendAgent(new AgentPowerOfTwo(addressee, 10));
  //assertEquals(1, ab.getBrokerInfo().getNumberOfActiveSessions());

We should also create worker:

WorkerSingleThreaded worker = new WorkerSingleThreaded();
  worker.setCacheService(new CacheServiceHM());
  Thread workerThread = new Thread(worker);


That is all - your agent started and working!

After some time we can collect the results:


List<Object> resultList = ab.receiveAgentResults(addressee.getIdentString());

Example provided here you can also find in samples directory of the DAC distribution (class: org.dacframe.example.poweroftwo.CajoPowerOfTwoTest).

Default environment initialization

It is not necessary to manually start broker and workers. DAC support the default environment initialization (Since version 0.8).

When the connection to the cajoBroker or jmsBroker located on the local machine fail, the new processes are started automatically:

  • cajoBroker/jmsBroker with exactly the same parameters at the one we was trying to connect to
  • worker connected to the new broker instance

Please look at the log fragment from the DAC session without any previous environment preparation:

  • cajoBroker
CajoBroker  - Unable to connect to broker - schedule lazy initialization
CajoBroker  - Scheduled broker initialization:
CajoBroker  -    host: localhost
CajoBroker  -    port: 1198
CajoBroker  -    name: broker
CajoBrokerServer  - Starting server.. (hostName=localhost, port=1198, name=broker)
CajoBrokerServer  - ..Done
CajoBrokerServer  - Listening at: //localhost:1198/broker
WorkerSingleThreaded  - Single threaded worker 15cbe3a6-acb1-4518-add7-b544c6fa2f2f started
WorkerSingleThreaded  - Worker 15cbe3a6-acb1-4518-add7-b544c6fa2f2f is receiving agent...
AgentBrokerStub  - New session: 84eede3f-1d45-4612-ac12-115561f0b52e
  (started: Mon Sep 28 10:19:05 CEST 2009, pending results: 0, waiting agents: 0)
WorkerSingleThreaded  - Worker 15cbe3a6-acb1-4518-add7-b544c6fa2f2f is executing agent:
  <org.dacframe.agent.AgentStub 84eede3f-1d45-4612-ac12-115561f0b52e>
WorkerSingleThreaded  - Stub agent 0 is doing execute()

  • jmsBroker
Unable to connect to JMS broker - schedule lazy initialization
JMS broker ready at: tcp://localhost:61616
Single threaded worker 3136154e-ad6d-4e95-a449-dea2a48fed32 started

You can use the newly created broker in the same way as any other brokers started manually. In particular you can:

  • send new agents
  • connect new workers