Java Doc for PlaceOrderPlugin.java in  » Science » Cougaar12_4 » org » cougaar » pizza » plugin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.pizza.plugin 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.cougaar.core.plugin.ComponentPlugin
   org.cougaar.pizza.plugin.PlaceOrderPlugin

All known Subclasses:   org.cougaar.pizza.plugin.SDPlaceOrderPlugin,
PlaceOrderPlugin
public class PlaceOrderPlugin extends ComponentPlugin (Code)
This plugin orders the pizza for a pizza party. It subscribes to a PizzaPreferences object published by the InvitePlugin when it knows how much of what kind of pizza to order.

On receiving the PizzaPreferences, it creates and publishes a Task with the Verb "Order" and a Direct Object of type Pizza (Asset). Next, it expands the Order Task into a workflow of two subtasks, one subtask per type of pizza with a quantity Preference for the number of servings needed. To place the order, it allocates the subtasks to its pizza provider, Joes Local Pizza Shack. This customer/provider relationship is defined in the XML configuration files and is established when the agents start up. See PizzaNode1.xml and PizzaNode2.xml for details.

In this example, the plugin cannot successfully complete the pizza order because Joe's Local Pizza Shack doesn't make veggie pizzas. The final result is a failed Expansion on the parent order Task due to the failed Allocation of the veggie pizza subtask.



Field Summary
final protected static  UnaryPredicateALLOCATION_PRED
     This predicate matches Allocations on "Order" tasks.
final protected static  UnaryPredicateEXPANSION_PRED
     This predicate matches Expansions on "Order" tasks.
final protected static  UnaryPredicatePIZZA_PREF_PRED
     This predicate matches PizzaPreferences objects.
final protected static  UnaryPredicateSELF_PRED
     This predicate matches the Entity object of the agent.
protected  IncrementalSubscriptionallocationSub
    
protected  DomainServicedomainService
    
protected  IncrementalSubscriptionexpansionSub
    
protected  LoggingServicelogger
    
protected  IncrementalSubscriptionpizzaPrefSub
    
protected  PlanningFactoryplanningFactory
    
protected  IncrementalSubscriptionselfSub
    


Method Summary
protected  voidallocateSubtasks(Collection subtasks, Entity provider)
     Creates and publishes Allocations for each subtask in the collection.
protected  TaskcreateOrderTask()
     Returns a Task for ordering pizza.
protected  CollectioncreatePizzaSubtasks(PizzaPreferences pizzaPrefs, Task parentTask)
     Returns a Collection of subtasks for ordering meat and veggie pizzas.
protected  voidexecute()
     When there are changes to the plugins's subscriptions, we: 1) When the PizzaPreferences arrives, create the root Order Task, and expand it by the types of pizza.
protected  ExpansiongetChangedExpansion()
     Returns the Expansion that was changed (the one and only typically).
protected  PizzaPreferencesgetPizzaPreferences()
     Returns any added PizzaPreferences object from the PizzaPreferences Subscription.
protected  EntitygetProvider()
     Returns a pizza provider for this agent.
protected  EntitygetSelfEntity()
     Returns the Entity representing the agent.
public  voidload()
     Loads services used by the plugin.
protected  voidlogExpansionResults(Expansion exp)
     Log (at SHOUT) the results of the given Expansion, showing what was ordered, how much, from whom, and with what success.
protected  voidmakeExpansion(Task parentTask, Collection subtasks)
     Creates and adds an Expansion on a Task and publishes it to the blackboard.
protected  PizzaAssetmakePizzaAsset(String assetType)
     Creates an instance of a PizzaAsset of the specified asset type.
protected  PreferencemakeQuantityPreference(int value)
     Returns a quantity Preference, representing the number of servings of pizza to order.

Creates a Preference with a Strictly-at ScoringFunction and a quantity AspectType from the specified value.

protected  NewTaskmakeTask(Verb verb, Asset directObject)
     Returns a NewTask.
protected  StringprintAllocationResults(PlanElement pe)
    
protected  StringprintExpansionResults(Expansion exp)
    
public  voidsetDomainService(DomainService aDomainService)
     Services that are absolutely required by the plugin can be loaded via introspection by the binding utility instead of explicitly getting each service from the ServiceBroker in load().
protected  voidsetupSubscriptions()
     Initialize the subcriptions the plugin is interested in: self Entity, the PizzaPreferences, and existing Allocations or Expansions or Order Tasks.
protected  voidupdateOrderAllocationResults()
     Updates the estimated AllocationResults with reported AllocationResults.

Field Detail
ALLOCATION_PRED
final protected static UnaryPredicate ALLOCATION_PRED(Code)
This predicate matches Allocations on "Order" tasks.



EXPANSION_PRED
final protected static UnaryPredicate EXPANSION_PRED(Code)
This predicate matches Expansions on "Order" tasks.



PIZZA_PREF_PRED
final protected static UnaryPredicate PIZZA_PREF_PRED(Code)
This predicate matches PizzaPreferences objects.



SELF_PRED
final protected static UnaryPredicate SELF_PRED(Code)
This predicate matches the Entity object of the agent.



allocationSub
protected IncrementalSubscription allocationSub(Code)



domainService
protected DomainService domainService(Code)



expansionSub
protected IncrementalSubscription expansionSub(Code)



logger
protected LoggingService logger(Code)



pizzaPrefSub
protected IncrementalSubscription pizzaPrefSub(Code)



planningFactory
protected PlanningFactory planningFactory(Code)



selfSub
protected IncrementalSubscription selfSub(Code)





Method Detail
allocateSubtasks
protected void allocateSubtasks(Collection subtasks, Entity provider)(Code)
Creates and publishes Allocations for each subtask in the collection. The Allocation includes: the provider assigned to compelete the task, an estimated AllocationResult, and the Role of PizzaProvider. The estimated AllocationResult includes: an estimated confidence rating of 0.25 and success is true. Valid range for the confidence rating is between 0 and 1. The assumption is, as the subtasks are completed, the allocation results will become closer to 1. The Allocations are then published to the blackboard.
Parameters:
  subtasks - a collection of subtasks to be allocated
Parameters:
  provider - the provider to which the subtasks are allocated



createOrderTask
protected Task createOrderTask()(Code)
Returns a Task for ordering pizza. Creates a Task with Verb "Order", makes a Pizza asset and sets it as the direct object of the task. Next, it publishes the task to the blackboard. a task for ordering pizza



createPizzaSubtasks
protected Collection createPizzaSubtasks(PizzaPreferences pizzaPrefs, Task parentTask)(Code)
Returns a Collection of subtasks for ordering meat and veggie pizzas. Creates a meat pizza subtask and a veggie pizza subtask. The number of individuals requesting meat and veggie pizzas are obtained from the PizzaPreferences object. A quantity Preference is created to represent the number of servings needed and is added to the appropriate subtask. The parentTask is set as the parent of the subtasks.
Parameters:
  pizzaPrefs - contains the number of people requesting meat or veggie pizzas
Parameters:
  parentTask - the parent of the subtasks a Collection of pizza subtasks



execute
protected void execute()(Code)
When there are changes to the plugins's subscriptions, we: 1) When the PizzaPreferences arrives, create the root Order Task, and expand it by the types of pizza. Then allocate these to the available provider. 2) Propagate up any changed Allocation Results 3) See if the root Expansion changed. If so, we may be done.



getChangedExpansion
protected Expansion getChangedExpansion()(Code)
Returns the Expansion that was changed (the one and only typically).

Checks the changed collection on the Subscription. If the collection is not empty, it returns the first element. If empty it returns null. the Expansion that was changed if any




getPizzaPreferences
protected PizzaPreferences getPizzaPreferences()(Code)
Returns any added PizzaPreferences object from the PizzaPreferences Subscription. Checks the added collection on the subscription and returns the first element in the collection. Will return null if the added collection is empty.

Note that since we only check the Added list, this method will only return an object once in our application. This keeps the plugin from publishing the Order Tasks each time the plugin runs. first PizzaPrefereneces object from the subscription




getProvider
protected Entity getProvider()(Code)
Returns a pizza provider for this agent. Get all relationships that match the Role of PizzaProvider from the RelationshipSchedule. Return the provider Entity from the first Relationship found. If there are no pizza provider relationships, null will be returned. a pizza provider Entity



getSelfEntity
protected Entity getSelfEntity()(Code)
Returns the Entity representing the agent. Checks the self entity subscription and returns the first element. In this example, there should be only one self entity. Will return null if the subscription is empty. the Entity representing the agent.



load
public void load()(Code)
Loads services used by the plugin.



logExpansionResults
protected void logExpansionResults(Expansion exp)(Code)
Log (at SHOUT) the results of the given Expansion, showing what was ordered, how much, from whom, and with what success.
Parameters:
  exp - The Expansion of the root Order task, whose details we print



makeExpansion
protected void makeExpansion(Task parentTask, Collection subtasks)(Code)
Creates and adds an Expansion on a Task and publishes it to the blackboard. An Expansion is created containing a Workflow of the specified subtasks. This Expansion is set to the parent task. The subtasks are published to the blackboard first, then the Expansion is published.
Parameters:
  parentTask - the parent task to be expanded
Parameters:
  subtasks - the collection of subtasks to be added to the Workflow of Expansion



makePizzaAsset
protected PizzaAsset makePizzaAsset(String assetType)(Code)
Creates an instance of a PizzaAsset of the specified asset type. Adds an ItemIdentification property group to the pizzaAsset instance marking the pizza type.
Parameters:
  assetType - the name of the type of asset (veg/meat) a PizzaAsset



makeQuantityPreference
protected Preference makeQuantityPreference(int value)(Code)
Returns a quantity Preference, representing the number of servings of pizza to order.

Creates a Preference with a Strictly-at ScoringFunction and a quantity AspectType from the specified value. In other words, says I want this many, and you get 0 credit for any more or less.
Parameters:
  value - the number required a Preference requesting that number of items exactly




makeTask
protected NewTask makeTask(Verb verb, Asset directObject)(Code)
Returns a NewTask. Creates a task with the specified verb and sets the Asset as the direct object.
Parameters:
  verb - the verb of the newtask
Parameters:
  directObject - asset that this Task is acting on a NewTask



printAllocationResults
protected String printAllocationResults(PlanElement pe)(Code)



printExpansionResults
protected String printExpansionResults(Expansion exp)(Code)



setDomainService
public void setDomainService(DomainService aDomainService)(Code)
Services that are absolutely required by the plugin can be loaded via introspection by the binding utility instead of explicitly getting each service from the ServiceBroker in load(). The setter methods are called after the component is constructed but before the state methods such as initialize, load, setupSubscriptions, etc. If the service is not available at that time, the component will be unloaded.



setupSubscriptions
protected void setupSubscriptions()(Code)
Initialize the subcriptions the plugin is interested in: self Entity, the PizzaPreferences, and existing Allocations or Expansions or Order Tasks.



updateOrderAllocationResults
protected void updateOrderAllocationResults()(Code)
Updates the estimated AllocationResults with reported AllocationResults.

Remember that the infrastructure sets the ReportedResult for you (in this case, by copying it from the provider agent when the provider settles the Task), but you must copy that up typically.

Checks the changed collection on the Allocation subscription. If the collection is not empty, it retrieves the Allocation PlanElement from the subscription. If the reported AllocationResults have changed, the results are udpated and a publish change is called on the PlanElement. The reported AllocationResults are changed by the provider assigned to the task.




Methods inherited from org.cougaar.core.plugin.ComponentPlugin
abstract protected void execute()(Code)(Java Doc)
protected ConfigFinder getConfigFinder()(Code)(Java Doc)
abstract protected void setupSubscriptions()(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.