General
Transactions
Both available brokers:
- jmsBroker
- cajoBroker
support transactions (cajoBroker since version 0.8).
The idea is to increase the reliability of the DAC framework. You can (and should) use transactions, but you are not forced to do that.
Using DAC without transactions
You can still use DAC without starting transaction. If you do this, results of the following methods:
- sendAgent
- putResult
- receiveAgentResults
are immediately visible to other agents. The big advantage of this use case is performance - there is no cost of the transaction handling. However, if something goes wrong (for example the worker's machine goes down), your session might get broken.
Using DAC with transaction
One advantage of DAC is that you do not have to do anything in order to use transactions. All the work is done by the default worker implementation (WorkerSingleThreaded).
However, if you want to communicate with broker using your own code, you still can (and should) use transactions. Moreover, everything is very simple. You can use the following code snippet as a template:
// ab is a valid AgentBroker instance try { ab.startTransaction(); // your code ab.commit(); } catch (Exception e) { // handle exception try { ab.rollback(); } catch (DACException e1) { // shouldn't happen, but you should still at least do some logging } }
Transaction design
Transactions in DAC framework are organised as follows:
- Transaction is started using startTransaction() method.
- Transaction can be ended in one of three ways:
- using commit() method
- using rollback() method
- with automatic rollback() invocation when there was no previous commit() invocation
- All received agents are not visible to other agents during transaction.
- when the transaction fails, received agents return to the broker's queue
- All sent agents are not visible to other agents during transaction.
- when the transaction is successful, sent agents become visible to other agents
- when the transaction fails, sent agents disappeared
- All received results are not visible to other agents during transaction.
- when the transaction fails, received results return to the broker's queue
- All sent results are not visible to other agents during transaction.
- when the transaction is successful, sent results become visible to other agents
- when the transaction fails, sent results disappeared
Configuring Transactions
You can configure transactions' lifetime by using "org.dacframe.transaction.lifetime" jvm property. The default value is 300000 milliseconds.
Cache service
Ticket #27
Logging service
One of the services managed by workers and injected into agents is Logger. It is an object from log4j library, used to log messages to a message server. Default configuration assumes that the server is working on localhost. In case the server is not working (port 12388) all the logging commands will be silently ignored. When the server is up, it collects messages from all agents to a logserver.log file.
Starting of the message server:
$ ant run-logserver
To enable cooperation between agents and message server that is working on another host/port, you have to change configuration in etc/log4j.properties file.
Management
It is possible to monitor some aspects of current broker using JMX. The easiest way to do so is by JConsole, a part of Java Development Kit (JDK) (It can be started using "jconsole" command). In JConsole you have to connect to the running broker.
In the console in MBeans section you can view all information about actual state. Currently available are:
- numberOfActiveSessions - gives the number of active sessions
- numberOfAllSessions - gives the number of all sessions
- numberOfAllAgents - gives the number of agents
- numberOfAllUniqueAgents - gives the number of unique agents
- numberOfWaitingAgents - gives the number of agents waiting for task or the number of agents from given session
- numberOfPendingResults - gives the number of waiting results or the number of waiting results from given session
- listPendingResults - gives a list of waiting results from given session
- listWaitingAgents - gives a list of waiting agents from given session
- listActiveSessions - gives a list of active session



