Source Code Cross Referenced for MultipleOutStandingPlugin.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:         * This COUGAAR Plugin creates and publishes "CODE" tasks and if allocationResult is a success
053:         * it keeps producing more task
054:         * It also reads the Plugin arguments and may alter MessageSize or slurp CPU
055:         */
056:        public class MultipleOutStandingPlugin extends CommonUtilPlugin {
057:
058:            // Two assets to use as direct objects for the CODE tasks
059:            protected Asset what_to_code;
060:            protected IncrementalSubscription allocations; // My allocations
061:            protected IncrementalSubscription forceExecute; // My allocations
062:
063:            protected int CPUCONSUME;
064:            protected int MESSAGESIZE;
065:            protected String FILENAME;
066:            protected int MAXCOUNT;
067:            protected int MYCOUNT = 1;
068:            protected int OUTSTANDING_MESSAGES;
069:            protected boolean DEBUG = false;
070:            protected boolean LOG = false;
071:
072:            protected int BURST_TIME = 0;
073:            protected String VERB;//="CODE1";
074:
075:            private Date startTime;
076:            private Task t, changedMind;
077:            private int sequenceNum = 1;
078:            private AspectValue aspectVal;
079:
080:            private int count = 1;
081:            private long minDelta;
082:
083:            private FileWriter fw;
084:            //    private double lastReceived=0;
085:
086:            private int wakeUpCount, taskAllocationCount;
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:
123:                    addTask();
124:                    printTheChange();
125:                    sequenceNum++;
126:                }
127:                allocations = (IncrementalSubscription) subscribe(myAllocationPredicate);
128:            }
129:
130:            /**
131:             * This Plugin has no subscriptions so this method does nothing
132:             */
133:            protected void execute() {
134:                wakeUpCount++;
135:                debug(DEBUG, "" + System.currentTimeMillis()
136:                        + "   wakeUpcount: " + wakeUpCount
137:                        + "------------------------");
138:                //publishRemove(t);
139:                allocateChangedtasks(allocations.getChangedList()); // Process changed allocations
140:            }
141:
142:            protected void addTask() {
143:                publishAsset(what_to_code, "The next Killer App",
144:                        "e something java");
145:                t = makeTask(what_to_code, VERB);
146:                setPreference(t, AspectType._ASPECT_COUNT, sequenceNum);
147:                publishAdd(t);
148:
149:            }
150:
151:            public void publishAsset(Asset asset, String nameOfAsset,
152:                    String itemIdentification) {
153:                asset = theLDMF.createPrototype("AbstractAsset", nameOfAsset);
154:                NewItemIdentificationPG iipg = (NewItemIdentificationPG) theLDMF
155:                        .createPropertyGroup("ItemIdentificationPG");
156:                iipg.setItemIdentification(itemIdentification);
157:                asset.setItemIdentificationPG(iipg);
158:                publishAdd(asset);
159:            }
160:
161:            protected void allocateChangedtasks(Enumeration allo_enum) {
162:                AllocationResult est, rep;
163:                double val = 0;
164:                while (allo_enum.hasMoreElements()) {
165:                    taskAllocationCount++;
166:
167:                    Allocation alloc = (Allocation) allo_enum.nextElement();
168:                    est = null;
169:                    rep = null;
170:                    est = alloc.getEstimatedResult();
171:                    rep = alloc.getReportedResult();
172:                    if (rep != null) {
173:                        double tasksNum[] = rep.getResult();
174:
175:                        System.out.println(tasksNum[0] + "----------------");
176:                        if (tasksNum[0] == (t
177:                                .getPreferredValue(AspectType._ASPECT_COUNT))) {
178:                            //debug(DEBUG, FILENAME, fw,"ManagerPlugin:allocateChangedTasks ........" + received);
179:                            //printTheChange();
180:                            waitFor(BURST_TIME);
181:
182:                            for (int i = 0; i < OUTSTANDING_MESSAGES; i++) {
183:                                addTask();
184:                                sequenceNum++;
185:                                //changeTasks(t);
186:                                printTheChange();
187:                                //publishRemove(t);
188:                            }
189:                        }
190:                    }
191:                    breakFromLoop(count, MAXCOUNT);
192:                }
193:                //lastReceived = received;
194:            }
195:
196:            protected void setPreference(Task t, int aspectType,
197:                    int sequenceOfTask) {
198:                startTime = new Date(); // Add a start_time and end_time strict preference
199:                aspectVal = AspectValue.newAspectValue(aspectType,
200:                        sequenceOfTask);
201:                ScoringFunction scorefcn = ScoringFunction
202:                        .createStrictlyAtValue(aspectVal);
203:                Preference pref = theLDMF.newPreference(aspectType, scorefcn);
204:                ((NewTask) t).setPreference(pref);
205:            }
206:
207:            /**
208:             * Create a CODE task.
209:             * @param what the direct object of the task
210:             */
211:            protected Task makeTask(Asset what, String verb) {
212:                NewTask new_task = theLDMF.newTask();
213:                new_task.setVerb(Verb.get(verb));// Set the verb as given
214:                new_task.setPlan(theLDMF.getRealityPlan());// Set the reality plan for the task
215:                new_task.setDirectObject(what);
216:
217:                NewPrepositionalPhrase npp = theLDMF.newPrepositionalPhrase();
218:                npp.setPreposition("USING_LANGUAGE");
219:                if (MESSAGESIZE == -1)
220:                    npp.setIndirectObject(alterMessageSize(0));
221:                else
222:                    npp.setIndirectObject(alterMessageSize(MESSAGESIZE));
223:                new_task.setPrepositionalPhrases(npp);
224:                return new_task;
225:            }
226:
227:            protected void changeTasks(Task t) {
228:                if (CPUCONSUME != -1) //i.e. cpuconsume passed to plugin as a arg
229:                    consumeCPU(CPUCONSUME);
230:                startTime = new Date();
231:                if (t.getVerb().equals(VERB))
232:                    sequenceNum++;
233:                setPreference(t, AspectType._ASPECT_COUNT, sequenceNum);
234:                //debug(DEBUG, FILENAME, fw,"\nManagerPlugin::Changing task " + t.getVerb() + " with num  " 
235:                //  +t.getPreferredValue(AspectType._ASPECT_COUNT )); 
236:                publishChange(t);
237:            }
238:
239:            protected void printTheChange() {
240:                Date endTime = new Date();
241:                long delta = endTime.getTime() - startTime.getTime();
242:                if (count == 1)
243:                    minDelta = delta;
244:                else
245:                    minDelta = Math.min(minDelta, delta);
246:                int taskCount = (int) t
247:                        .getPreferredValue(AspectType._ASPECT_COUNT);
248:                String msg = t.getVerb() + "=>" + taskCount + "," + delta + ","
249:                        + minDelta + " TaskAllocationCount:"
250:                        + taskAllocationCount;
251:                log(LOG, FILENAME, fw, msg);
252:                count++;
253:            }
254:
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.