# Linked Data Aware Agent Development Framework for Mobile Devices
## 4 Case Study and Discussion
### Using the LDAF-M Framework
#### 4.2.4 Defining Plans  
The MetaPlan class is the main class that supports the definition of plans which play an active role in transforming the goals into a series of actions. As illustrated in the code fragment given in Listing 8, MetaPlan class has a constructor with two parameters. The first parameter is the name of the plan being defined, and the second parameter is the name of the class containing the body of the plan. The class containing the body of a plan is an extension of the PlanContent class. In addition, it is also important to define the relationships between plans and goals, and the MetaPlan class includes a method using which such relationships can be defined. In Listing 8, the goal called \"auction_process\" is associated with the auction processing of the auctioneer agent which is responsible for managing the auction. Finally, the plan defined is added to the plan base of the agent.  
1. MetaPlan metaplan = new MetaPlan(\"auction_process_plan\",
2. \"tr.edu.ege.bilmuh.application.sample.servside.Auctioneer.AuctionProcessPlan\");
3. metaplan.addProbablyGoalName(\"auction_process\");
4. getPlanbase().addMetaPlan(metaplan);  
**Listing 8**. Defining plans.  
In LDAF-M, execution of a plan not only starts with the adoption of a goal which associated with that plan, but also starts based on the occurrence of an event within the agent platform. For example, when an agent receives an agent communication language message from another agent, an event is created. Then, the plan associated with that event begins to execute provided that the relationship between that plan and the message generated the event have already been defined. This relationship is defined using the method addMessageEventTrigger which is located in the Planbase class. The use of that method is shown in Listing 9. The first parameter of the method is the reference name of the message trigger, and the second parameter is the name of the plan.  
1. getPlanbase().addMessageEventTrigger(\"subscribe_auction_msg\", \"subscribe_auction\");
2. getPlanbase().addMessageEventTrigger(\"get_auction_name_msg\", \"get_auction_name\");  
**Listing 9**. Adding event trigger to a plan.  
The PlanContent class has also an important role in the execution of the plans, since the detailed operation of a plan is defined within that class. A plan content example is given in Listing 10.  
The actions to be done within the scope of the plan are defined in the method called \"body\". Execution of a plan can end with success or failure. The actions to be done in case of success, just before the plan is terminated, are defined in the method called \"passed\", while the actions to be done in case of a failure are defined in the method called \"failed\". On the other hand, some plans cannot be completed due to some reasons. When this is the case, the actions that should be done are defined in the method called \"aborted\".  
\begin{tabular}{l l}
01 & public class EvaluateActionOfferPlan extends PlanContent { \\
02 & public void body() {..... } \\
03 & public void passed() {..... } \\
04 & public void failed() {..... } \\
05 & public void aborted() {....... } \\
06 \} \\ \end{tabular}  
**Listing 10**. Plan content.  
From the agent developer's perspective, the plan content plays an important role, since a developer is able to define the following tasks and access the main components of an agent within a plan body:  
\(\bullet\)Interacting with the Agent Management System (AMS) to create an agent, to kill an agent, or to query the AMS about an agent.  
\(\bullet\)Accessing belief base, goal base, and plan base of the agent that is executing the plan body.  
\(\bullet\)Registering the services of an agent with the Directory Facilitator (DF), searching the DF for discovering the agents giving a specific service.  
\(\bullet\)Sending agent communication language messages to other agents.