Source Code Cross Referenced for TestCompletionPlugin.java in  » Science » Cougaar12_4 » org » cougaar » planning » plugin » completion » 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.planning.plugin.completion 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2001-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.planning.plugin.completion;
028:
029:        import java.util.Collection;
030:        import java.util.Enumeration;
031:        import java.util.Iterator;
032:        import java.util.Vector;
033:
034:        import org.cougaar.core.agent.service.alarm.Alarm;
035:        import org.cougaar.core.service.LoggingService;
036:        import org.cougaar.planning.ldm.PlanningFactory;
037:        import org.cougaar.planning.ldm.measure.CountRate;
038:        import org.cougaar.planning.ldm.measure.FlowRate;
039:        import org.cougaar.planning.ldm.measure.Rate;
040:        import org.cougaar.planning.ldm.plan.AspectRate;
041:        import org.cougaar.planning.ldm.plan.AspectType;
042:        import org.cougaar.planning.ldm.plan.AspectValue;
043:        import org.cougaar.planning.ldm.plan.NewTask;
044:        import org.cougaar.planning.ldm.plan.Preference;
045:        import org.cougaar.planning.ldm.plan.PrepositionalPhrase;
046:        import org.cougaar.planning.ldm.plan.ScoringFunction;
047:        import org.cougaar.planning.ldm.plan.Task;
048:        import org.cougaar.planning.ldm.plan.Verb;
049:        import org.cougaar.planning.ldm.predicate.TaskPredicate;
050:        import org.cougaar.planning.plugin.legacy.SimplePlugin;
051:        import org.cougaar.planning.plugin.util.PluginHelper;
052:
053:        /**
054:         * A plugin for testing completion detection. Injects a slug of new
055:         * Supply tasks every day (of execution) based on the ProjectSupply
056:         * tasks in the logplan. Each ProjectSupply leads to one Supply task
057:         * for which the quantity is one day's projected demand. The intention
058:         * is to stimulate the inventory manager to run and set off a wave of
059:         * activity through the society that the completion plugins detect to
060:         * inhibit the speeded up advancement of time until the cessation of
061:         * activity is detected.
062:         **/
063:        public class TestCompletionPlugin extends SimplePlugin {
064:            private static final long ONE_DAY = 86400000L;
065:            private static final long TIME_OFFSET = ONE_DAY / 2;
066:            private static final Verb SUPPLY = Verb.get("Supply");
067:            private static final Verb PROJECTSUPPLY = Verb.get("ProjectSupply");
068:            private static final String MAINTAINING = "Maintaining";
069:            private static final String FOR = "For";
070:            private static final int DEMANDRATE = AspectType.N_CORE_ASPECTS + 0;
071:
072:            private long demoNow;
073:            private long nextWakeTime;
074:            private Alarm timer;
075:            private LoggingService logger;
076:            private PlanningFactory ldmf;
077:
078:            public void setLoggingService(LoggingService ls) {
079:                logger = ls;
080:            }
081:
082:            public void setupSubscriptions() {
083:                ldmf = (PlanningFactory) getFactory("planning");
084:                demoNow = currentTimeMillis();
085:                nextWakeTime = TIME_OFFSET + (((demoNow) / ONE_DAY) + 1)
086:                        * ONE_DAY;
087:                timer = wakeAt(nextWakeTime);
088:            }
089:
090:            public void execute() {
091:                if (timer.hasExpired()) {
092:                    demoNow = currentTimeMillis();
093:                    do {
094:                        generateSupplyTasks();
095:                        nextWakeTime += ONE_DAY;
096:                    } while (nextWakeTime < demoNow);
097:                    timer = wakeAt(nextWakeTime);
098:                }
099:            }
100:
101:            private String parseMaintainedItemType(String mi) {
102:                int pos1 = mi.indexOf(": <") + 3;
103:                int pos2 = mi.indexOf(">", pos1);
104:                return mi.substring(pos1, pos2);
105:            }
106:
107:            private void generateSupplyTasks() {
108:                final String selfIdentification = getMessageAddress()
109:                        .toString();
110:                TaskPredicate projectionTaskPredicate = new TaskPredicate() {
111:                    public boolean execute(Task task) {
112:                        if (task.getVerb().equals(PROJECTSUPPLY)) {
113:                            PrepositionalPhrase maintaining = task
114:                                    .getPrepositionalPhrase(MAINTAINING);
115:                            if (maintaining != null) {
116:                                String maintainedItem = maintaining
117:                                        .getIndirectObject().toString();
118:                                String maintainedItemType = parseMaintainedItemType(maintainedItem);
119:                                if (maintainedItemType.equals("Inventory"))
120:                                    return false;
121:                                PrepositionalPhrase pp = task
122:                                        .getPrepositionalPhrase(FOR);
123:                                String orgName = (String) pp
124:                                        .getIndirectObject();
125:                                if (selfIdentification.equals(orgName)) {
126:                                    return true;
127:                                }
128:                            }
129:                        }
130:                        return false;
131:                    }
132:                };
133:                Collection projections = query(projectionTaskPredicate);
134:                if (projections.size() == 0)
135:                    return;
136:                if (logger.isDebugEnabled()) {
137:                    logger.debug(selfIdentification + ": " + projections.size()
138:                            + " projections");
139:                }
140:                for (Iterator i = projections.iterator(); i.hasNext();) {
141:                    Task projectionTask = (Task) i.next();
142:                    NewTask supplyTask = ldmf.newTask();
143:                    supplyTask.setVerb(SUPPLY);
144:                    supplyTask
145:                            .setDirectObject(projectionTask.getDirectObject());
146:                    // Copy all but the demand rate pp
147:                    Enumeration fe = projectionTask.getPrepositionalPhrases();
148:                    //          new FilteredEnumeration(, demandRateFilter);
149:                    supplyTask.setPrepositionalPhrases(fe);
150:                    supplyTask.setPlan(projectionTask.getPlan());
151:                    supplyTask.setContext(projectionTask.getContext());
152:                    Vector prefs = new Vector(3);
153:                    Preference pref;
154:                    ScoringFunction sf;
155:                    AspectValue av;
156:                    av = AspectValue.newAspectValue(AspectType.START_TIME,
157:                            demoNow);
158:                    sf = new ScoringFunction.StepScoringFunction(av, 0.00, 0.99);
159:                    pref = ldmf.newPreference(AspectType.START_TIME, sf, 1.0);
160:                    prefs.addElement(pref);
161:                    av = AspectValue.newAspectValue(AspectType.END_TIME,
162:                            demoNow);
163:                    sf = new ScoringFunction.StepScoringFunction(av, 0.00, 0.99);
164:                    pref = ldmf.newPreference(AspectType.END_TIME, sf, 1.0);
165:                    prefs.addElement(pref);
166:                    double rateValue = 0.0;
167:                    Rate rate = ((AspectRate) PluginHelper.getPreferenceBest(
168:                            projectionTask, DEMANDRATE)).getRateValue();
169:                    if (rate instanceof  CountRate) {
170:                        rateValue = ((CountRate) rate)
171:                                .getValue(CountRate.EACHES_PER_DAY);
172:                    } else if (rate instanceof  FlowRate) {
173:                        rateValue = ((FlowRate) rate)
174:                                .getValue(FlowRate.GALLONS_PER_DAY);
175:                    } else {
176:                        continue;
177:                    }
178:                    if (rateValue <= 0.0)
179:                        continue;
180:                    double theQuantity = rateValue * ONE_DAY;
181:                    av = AspectValue.newAspectValue(AspectType.QUANTITY,
182:                            theQuantity);
183:                    sf = new ScoringFunction.StrictValueScoringFunction(av);
184:                    pref = ldmf.newPreference(AspectType.QUANTITY, sf, 1.0);
185:                    prefs.addElement(pref);
186:                    supplyTask.setPreferences(prefs.elements());
187:                    publishAdd(supplyTask);
188:                }
189:            }
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.