Source Code Cross Referenced for SimpleAddRescindPlugin.java in  » Science » Cougaar12_4 » org » cougaar » lib » quo » performance » 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.lib.quo.performance 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 1997-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:         *  THIS SOFTWARE IS MODIFIED FOR TESTING QUO_ULTRALLOG INTEGRATION
026:         */
027:
028:        package org.cougaar.lib.quo.performance;
029:
030:        //package org.cougaar.lib.quo;
031:        import java.io.FileWriter;
032:        import java.util.Date;
033:        import java.util.Enumeration;
034:        import java.util.Vector;
035:
036:        import org.cougaar.core.blackboard.IncrementalSubscription;
037:        import org.cougaar.planning.ldm.asset.Asset;
038:        import org.cougaar.planning.ldm.asset.NewItemIdentificationPG;
039:        import org.cougaar.planning.ldm.plan.Allocation;
040:        import org.cougaar.planning.ldm.plan.AllocationResult;
041:        import org.cougaar.planning.ldm.plan.AspectType;
042:        import org.cougaar.planning.ldm.plan.AspectValue;
043:        import org.cougaar.planning.ldm.plan.NewPrepositionalPhrase;
044:        import org.cougaar.planning.ldm.plan.NewTask;
045:        import org.cougaar.planning.ldm.plan.Preference;
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.util.UnaryPredicate;
050:
051:        /**
052:         * Adds multiple task and removes them after allocation result for the 
053:         * previous task arrives
054:         */
055:        public class SimpleAddRescindPlugin extends CommonUtilPlugin {
056:
057:            // Two assets to use as direct objects for the CODE tasks
058:            protected Asset what_to_code;
059:            protected IncrementalSubscription allocations; // My allocations
060:            protected IncrementalSubscription forceExecute; // My allocations
061:
062:            protected int CPUCONSUME;
063:            protected int MESSAGESIZE;
064:            protected String FILENAME;
065:            protected int MAXCOUNT;
066:            protected int MYCOUNT = 1;
067:            protected int OUTSTANDING_MESSAGES;
068:            protected boolean DEBUG = false;
069:            protected boolean LOG = false;
070:            protected int BURST_TIME = 0;
071:            protected String VERB;//="CODE1";
072:
073:            private Date startTime;
074:            private Task t, changedMind;
075:            private int sequenceNum = 1;
076:            private AspectValue aspectVal;
077:
078:            private int count = 1;
079:            private long minDelta;
080:
081:            private FileWriter fw;
082:            //    private double lastReceived=0;
083:
084:            private int wakeUpCount, taskAllocationCount;
085:            private int expectedTask;
086:            private int receivedTask;
087:
088:            /**
089:             * parsing the plugIn arguments and setting the values for CPUCONSUME and MESSAGESIZE
090:             */
091:            protected void parseParameter() {
092:                Vector p = getParameters();
093:                CPUCONSUME = getParameterIntValue(p, "CPUCONSUME");
094:                MESSAGESIZE = getParameterIntValue(p, "MESSAGESIZE");
095:                FILENAME = getParameterValue(p, "FILENAME");
096:                MAXCOUNT = getParameterIntValue(p, "MAXCOUNT");
097:                OUTSTANDING_MESSAGES = getParameterIntValue(p,
098:                        "OUTSTANDING_MESSAGES");
099:                DEBUG = getParameterBooleanValue(p, "DEBUG");
100:                LOG = getParameterBooleanValue(p, "LOG");
101:                BURST_TIME = getParameterIntValue(p, "BURST_TIME");
102:                VERB = getParameterValue(p, "VERB");
103:            }
104:
105:            public UnaryPredicate myAllocationPredicate = new UnaryPredicate() {
106:                public boolean execute(Object o) {
107:                    if (o instanceof  Allocation) {
108:                        Task t = ((Allocation) o).getTask();
109:                        return (t != null)
110:                                && (t.getVerb().equals(Verb.get(VERB)));
111:                    }
112:                    return false;
113:                }
114:            };
115:
116:            /**
117:             * Using setupSubscriptions to create the initial CODE tasks
118:             */
119:            protected void setupSubscriptions() {
120:                parseParameter(); //read the plugIn arguments
121:                for (int i = 0; i < OUTSTANDING_MESSAGES; i++) {
122:                    // System.out.println("enetring loop");
123:                    addTask();
124:                }
125:                allocations = (IncrementalSubscription) subscribe(myAllocationPredicate);
126:            }
127:
128:            /**
129:             * This Plugin has no subscriptions so this method does nothing
130:             */
131:            protected void execute() {
132:                wakeUpCount++;
133:
134:                System.out.println("....Wokenup @" + System.currentTimeMillis()
135:                        + "   wakeUpcount: " + wakeUpCount);
136:                //publishRemove(t);
137:                allocateChangedtasks(allocations.getChangedList()); // Process changed allocations
138:            }
139:
140:            protected void addTask() {
141:                publishAsset(what_to_code, "The next Killer App",
142:                        "e something java");
143:                t = makeTask(what_to_code, VERB);
144:                setPreference(t, AspectType._ASPECT_COUNT, sequenceNum);
145:
146:                publishAdd(t);
147:
148:            }
149:
150:            public void publishAsset(Asset asset, String nameOfAsset,
151:                    String itemIdentification) {
152:                asset = theLDMF.createPrototype("AbstractAsset", nameOfAsset);
153:                NewItemIdentificationPG iipg = (NewItemIdentificationPG) theLDMF
154:                        .createPropertyGroup("ItemIdentificationPG");
155:                iipg.setItemIdentification(itemIdentification);
156:                asset.setItemIdentificationPG(iipg);
157:                publishAdd(asset);
158:            }
159:
160:            protected void allocateChangedtasks(Enumeration allo_enum) {
161:
162:                AllocationResult est, rep;
163:                double val = 0;
164:                //double arr[] = null;
165:                //double received = 0;
166:                while (allo_enum.hasMoreElements()) {
167:                    taskAllocationCount++;
168:                    int taskCount = (int) t
169:                            .getPreferredValue(AspectType._ASPECT_COUNT);
170:                    debug(DEBUG,
171:                            "ManagerPlugin:allocateChangedTasks ....taskAllocationCount.."
172:                                    + taskAllocationCount + " for task# "
173:                                    + taskCount);
174:                    Allocation alloc = (Allocation) allo_enum.nextElement();
175:                    est = null;
176:                    rep = null;
177:                    est = alloc.getEstimatedResult();
178:                    rep = alloc.getReportedResult();
179:                    if (rep != null) {
180:                        //debug(DEBUG, FILENAME, fw,"ManagerPlugin:allocateChangedTasks ........" + received);
181:                        receivedTask = (int) t
182:                                .getPreferredValue(AspectType._ASPECT_COUNT);
183:                        affert(expectedTask, receivedTask);
184:                        printTheChange();
185:                        debug(DEBUG, t.getVerb() + "=>expectedTask:received::"
186:                                + expectedTask + ":" + receivedTask);
187:                        waitFor(BURST_TIME);
188:                        for (int i = 0; i < OUTSTANDING_MESSAGES; i++) {
189:                            //addTask();
190:                            //sequenceNum++; 
191:                            changeTasks(t);
192:                            publishRemove(t);
193:                        }
194:                    }
195:                    breakFromLoop(count, MAXCOUNT);
196:                }
197:                //lastReceived = received;
198:            }
199:
200:            protected void setPreference(Task t, int aspectType,
201:                    int sequenceOfTask) {
202:                startTime = new Date(); // Add a start_time and end_time strict preference
203:                aspectVal = AspectValue.newAspectValue(aspectType,
204:                        sequenceOfTask);
205:                ScoringFunction scorefcn = ScoringFunction
206:                        .createStrictlyAtValue(aspectVal);
207:                Preference pref = theLDMF.newPreference(aspectType, scorefcn);
208:                ((NewTask) t).setPreference(pref);
209:            }
210:
211:            /**
212:             * Create a CODE task.
213:             * @param what the direct object of the task
214:             */
215:            protected Task makeTask(Asset what, String verb) {
216:                NewTask new_task = theLDMF.newTask();
217:                new_task.setVerb(Verb.get(verb));// Set the verb as given
218:                new_task.setPlan(theLDMF.getRealityPlan());// Set the reality plan for the task
219:                new_task.setDirectObject(what);
220:
221:                NewPrepositionalPhrase npp = theLDMF.newPrepositionalPhrase();
222:                npp.setPreposition("USING_LANGUAGE");
223:                if (MESSAGESIZE == -1)
224:                    npp.setIndirectObject(alterMessageSize(0));
225:                else
226:                    npp.setIndirectObject(alterMessageSize(MESSAGESIZE));
227:                new_task.setPrepositionalPhrases(npp);
228:                return new_task;
229:            }
230:
231:            protected void changeTasks(Task t) {
232:                if (CPUCONSUME != -1) //i.e. cpuconsume passed to plugin as a arg
233:                    consumeCPU(CPUCONSUME);
234:                startTime = new Date();
235:                if (t.getVerb().equals(VERB))
236:                    sequenceNum++;
237:                setPreference(t, AspectType._ASPECT_COUNT, sequenceNum);
238:                //debug(DEBUG, FILENAME, fw,"\nManagerPlugin::Changing task " + t.getVerb() + " with num  " 
239:                //  +t.getPreferredValue(AspectType._ASPECT_COUNT )); 
240:                publishChange(t);
241:                expectedTask++;
242:            }
243:
244:            protected void printTheChange() {
245:                Date endTime = new Date();
246:                long delta = endTime.getTime() - startTime.getTime();
247:                if (count == 1)
248:                    minDelta = delta;
249:                else
250:                    minDelta = Math.min(minDelta, delta);
251:                int taskCount = (int) t
252:                        .getPreferredValue(AspectType._ASPECT_COUNT);
253:                String msg = t.getVerb() + "=>" + taskCount + "," + delta + ","
254:                        + minDelta;
255:                log(LOG, FILENAME, fw, msg);
256:                count++;
257:            }
258:
259:            // renamed to "affert" from "assert".  Better option would be to use the real jdk1.4 assert
260:            // functionality once we've got a full set of complient compilers.
261:            protected void affert(int expectedTask, int receivedTask) {
262:                if (expectedTask != receivedTask) {
263:                    System.out
264:                            .println("ERROR!!!!! expectedTask is different from receivedTask");
265:
266:                }
267:            }
268:
269:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.