# Linked Data Aware Agent Development Framework for Mobile Devices
## 4 Case Study and Discussion
### Using the LDAF-M Framework
#### 4.2.3 Defining Goals  
MetaGoal class plays the key role in defining an agent's goals. As you can see from the code fragment given in Listing 4, the MetaGoal class has a two-parameter constructor. The first parameter is the name of the goal, and the second parameter specifies the type of the goal. Some of the goals of an agent can be adopted either from the very beginning when the agent is activated or just before the agent terminates. These goals can be added to the goalbase of the agent using the methods addInitialGoalName and addFinishingGoalName as shown in Listing 4.  
1. MetaGoal metagoal = new MetaGoal(\"finishing\", MetaGoal.PERFORMANCE);
2. getGoalbase().addMetaGoals(metagoal);
3. metagoal = new MetaGoal(\"initialization\", MetaGoal.PERFORMANCE);
4. getGoalbase().addMetaGoals(metagoal);
5. getGoalbase().addInitialGoalName(\"initialization\");
6. getGoalbase().addFinishingGoalNames(\"finishing\");  
**Listing 4**. Adding goals to the goalbase of the agent.  
As mentioned in Section 2.3, the life cycle of a goal can be controlled by the developer. The necessary conditions that are required for the transitions between the phases of the goal life cycle are defined in a class extended from the TriggeredCondition class. Such a class defined within the context of the developed auction application is shown in Listing 5. The AuctioneerAgentSuspendCondition class defines the conditions for an auctioneer agent to make a transition to suspended state and these conditions are written in the body of the method triggeredCondition().  
1. public class AuctioneerAgentSuspendCondition extends TriggeredCondition{
2. public Boolean triggeredCondition(){
3.......
4. }
5. }  
The metaGoal class provides the methods for relating the defined conditions with the goal at hand. For example, setSuspendConditionClassName relates a suspend condition definition to a goal. On the other hand, the conditions that define when an agent has to drop a goal, is related with the goal via the method setDropConditionClassName. Examples for defining conditions for a goal that is related with starting an auction are shown in Listing 6.  
1. metagoal = new MetaGoal(\"auction_process\", MetaGoal.PERFORMANCE);
2. metagoal.setSuspendConditionClassName
3. (\"tr.edu.ege.bilmuh.application.sample.servside.AuctioneerAgentSuspendCondition\");
4. metagoal.setDropConditionClassName
5. (\"tr.edu.ege.bilmuh.application.sample.servside.AuctioneerAgentDropCondition\");
6. getGoalbase().addMetaGoals(metagoal);  
**Listing 6**. Defining conditions for a goal.  
Another property in LDAF-M, which is a result of its BDI architecture, is that a goal can block some or all of the other goals during deliberation. For example, some of the goals of the agent can be transferred to the option phase from the active phase, based on the blocking list of another goal that is being adopted by the agent. These blocked goals can never pass to the active state unless the blocking goal continues its execution. This information is provided through the addInhibitGoalName method located in the MetaGoal class. In addition, the number of maximum goals the agent can handle while executing a specific goal is defined using the setCardinality method as shown in Listing 7. In Listing 7, one can see that searching for an auction while sending an auction generation request is inhibited.  
1. MetaGoal metagool = new MetaGoal(\"send_request_generate_auction\",
2. MetaGoal.PERFORMOGAL);
3. metagool.addInhibitGoalName(\"search_auction\");
4. metagool.setCardinality(5);
5. getGoalbase().addMetaGoals(metagool);  
**Listing 7**. Setting properties for a goal.