An Agent Group for Collaborative Database Access

An application which utilizes CollaboratorAgents must implement one or more collaboration policies by subclassing AgentGroupImpl and writing application-specific analyzeResults methods.

Consider, an application of the DBCollaboratorAgent shown earlier. Each region maintains its own database, in a potentially different format from the others (e.g., ODBC vs. a proprietary system). An application could launch multiple agents to query the databases -- one per database. Each agent could determine the total sales volume in a specific region. Then the agents could share the results of their queries via collaboration to determine the region with the highest sales.

Figure 2 depicts the DBAccessAgentGroup, which performs the collaboration and analysis on the results of the agents' queries.


 1: /*  DBAccessAgentGroup.java

 2:  *  Copyright © 1997-1998 Horizon Systems Laboratory,

 3:  *  Mitsubishi Electric Information Technology Center America.

 4:  *  All rights reserved.

 5:  *

 6:  *  CONFIDENTIAL AND PROPRIETARY PROPERTY OF MITSUBISHI ELECTRIC ITA.

 7:  *

 8:  *  DESCRIPTION

 9:  *  Launcher for DBAccessAgent.

10:  *

11:  */

12: 

13: import java.rmi.RemoteException;

14: import java.util.*;

15: 

16: import COM.meitca.concordia.collaborate.*;

17: 

18: public class DBAccessAgentGroup extends AgentGroupImpl {

19:

20:     public DBAccessAgentGroup()

21:         throws RemoteException {

22:     }

23: 

24:     protected Object analyzeResults(Enumeration results) {

25:         try {

26:             QueryResult     highest = null;

27:             QueryResult[]	others = new QueryResult[getGroupSize()-1];

28:             int		        i = 0;

29: 

30:             for (; results.hasMoreElements(); ) {

31:                 AgentResult result = (AgentResult)results.nextElement();

32:                 QueryResult query = (QueryResult)result.getResult();

33:

34:                 if (query != null) {

35:                     if (highest == null) {

36:                         highest = query;

37:                     } else if (query.sales > highest.sales) {

38:                         others[i++] = highest;

39:                         highest = query;

40:                     } else {

41:                         others[i++] = query;

42:                     }

43:                 }

44:             }

45:

46:             CollaborationResult result = new CollaborationResult();

47:             result.highest = highest;

48:             result.others = others;

49:             return result;

50: 

51:         } catch (RemoteException e) {

52:             // catch bogus remote exception from getGroupSize

53:         }

54: 

55:         return null;

56:     }

57: }


Figure 2 - The Database Access Agent Group

The analyzeResults method above utilizes the results of all of the agents' queries to compute the region with the highest sales (lines 24-56). The analysis returns a CollaborationResult object (lines 46-49). The CollaborationResult class is shown in Figure 3. It contains the highest sales result and an array of the other sales results. The sales results are represented by QueryResult objects (also shown in Figure 3), which contain the name of a region and its sales volume.


 1: import java.io.Serializable;

 2: 

 3: class CollaborationResult implements Serializable {

 4:     QueryResult highest;

 5:     QueryResult[] others;

 6: }

 7: 

 8: 

 9: class QueryResult implements Serializable {

10:     String region;

11:     float sales;

12: }


Figure 3 - CollaborationResult and QueryResult Objects