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


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2003-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:        package org.cougaar.lib.vishnu.client;
027:
028:        import org.cougaar.lib.param.ParamMap;
029:        import com.bbn.vishnu.scheduling.Assignment;
030:        import com.bbn.vishnu.scheduling.MultitaskAssignment;
031:        import com.bbn.vishnu.scheduling.Resource;
032:        import com.bbn.vishnu.scheduling.Scheduler;
033:        import com.bbn.vishnu.scheduling.SchedulingData;
034:        import com.bbn.vishnu.scheduling.TimeOps;
035:        import org.cougaar.util.StringKey;
036:        import org.cougaar.util.log.Logger;
037:
038:        import org.cougaar.planning.ldm.plan.Task;
039:        import org.cougaar.planning.ldm.asset.Asset;
040:
041:        import java.util.Date;
042:        import java.util.ArrayList;
043:        import java.util.List;
044:        import java.util.Vector;
045:        import org.w3c.dom.Document;
046:
047:        /** 
048:         * Direct mode.  
049:         * <p>
050:         * Creates an internal instance of the scheduler and talks to it, instead
051:         * of to a web server.  Uses direct translation of Cougaar to Vishnu objects,
052:         * and reads the assignments directly.  <b>No XML involved.</b>
053:         *
054:         * Needs the plugin to be a DirectResultListener.  Mainly this means implementing
055:         * the prepareVishnuObjects method.
056:         * @see DirectResultListener
057:         */
058:        public class DirectMode extends InternalMode {
059:            public DirectMode(ModeListener parent, VishnuComm comm,
060:                    XMLProcessor xmlProcessor, VishnuDomUtil domUtil,
061:                    VishnuConfig config, ResultHandler resultHandler,
062:                    ParamMap myParamTable, Logger logger) {
063:                super (parent, comm, xmlProcessor, domUtil, config,
064:                        resultHandler, myParamTable, logger);
065:                localSetup();
066:            }
067:
068:            protected void localSetup() {
069:                super .localSetup();
070:
071:                try {
072:                    debugParseAnswer = getMyParams().getBooleanParam(
073:                            "debugParseAnswer");
074:                } catch (Exception e) {
075:                    debugParseAnswer = false;
076:                }
077:            }
078:
079:            /**  
080:             * Handles direct mode differently from external/internal. 
081:             * <p> 
082:             * Calls prepareVishnuObjects on listener to populate <tt>vishnuTasks</tt> and 
083:             * <tt>vishnuResources</tt> lists with Vishnu objects.  
084:             * <p>
085:             * Also sends header with the time window information, and any other 
086:             * data to scheduler via the internal buffer (in VishnuComm). 
087:             * @param stuffToSend Cougaar tasks and assets
088:             * @param objectFormatDoc used to figure out info about fields
089:             */
090:            public void prepareData(List stuffToSend, Document objectFormatDoc) {
091:                vishnuTasks = new ArrayList();
092:                vishnuResources = new ArrayList();
093:                changedVishnuResources = new ArrayList();
094:
095:                Date start = new Date();
096:
097:                ((DirectModeListener) parent).prepareVishnuObjects(stuffToSend,
098:                        parent.getChangedAssets(), vishnuTasks,
099:                        vishnuResources, changedVishnuResources,
100:                        objectFormatDoc, sched.getData());
101:                parent.clearChangedAssets();
102:
103:                if (logger.isDebugEnabled())
104:                    logger.debug(getName()
105:                            + ".prepareData - clearing changed assets!");
106:
107:                if (showTiming)
108:                    domUtil
109:                            .reportTime(
110:                                    ".prepareData - prepared vishnu objects in ",
111:                                    start);
112:
113:                // think it's OK to send this more than once
114:                serializeAndPostDoc(xmlProcessor.getVanillaHeader());
115:
116:                sendOtherData();
117:            }
118:
119:            /**
120:             * Run directly.  Give Vishnu tasks and resources to scheduler and get assignments
121:             * back, <i>without</i> using XML. <p>
122:             *
123:             * Uses <tt>internalBuffer</tt> to send the specs, the object format and other data.<br>
124:             * Adds the task and resources (<tt>addTasksDirectly</tt>), and then runs the scheduler
125:             * (<tt>Scheduler.scheduleInternal</tt>).  Reads the assignments with 
126:             * <tt>directlyHandleAssignments</tt>. 
127:             * <p>
128:             * <tt>vishnuTasks</tt> and <tt>vishnuResources</tt> are created in prepareData and populated
129:             * in #prepareVishnuObjects. <p>
130:             *
131:             * @see #addTasksDirectly
132:             * @see #prepareData
133:             * @see org.cougaar.lib.vishnu.client.VishnuPlugin#prepareVishnuObjects
134:             * @see com.bbn.vishnu.scheduling.Scheduler#scheduleInternal
135:             */
136:            public void run() {
137:                Date start = new Date();
138:
139:                int unhandledTasks = prepareScheduler();
140:
141:                // These are things created by the scheduler during setup that
142:                // are needed for direct object writing.
143:                TimeOps timeOps = sched.getTimeOps();
144:                SchedulingData data = sched.getData();
145:                //    sched.clearCaches ();
146:
147:                // add tasks and resources to data
148:                // vishnuTasks & Resources created in prepareData and set in prepareVishnuObjects
149:                addTasksDirectly(data, vishnuTasks, vishnuResources,
150:                        changedVishnuResources);
151:
152:                // Call scheduleInternal after adding all the data
153:                Date start2 = new Date();
154:
155:                try {
156:                    sched.scheduleInternal(null, false);
157:
158:                    dumpPostProcess();
159:                    if (showTiming)
160:                        domUtil.reportTime(
161:                                ".runDirectly - scheduler processed "
162:                                        + parent.getNumTasks() + " tasks in ",
163:                                start2);
164:
165:                    // get the assignments the scheduler made, make plan elements
166:                    ((DirectResultHandler) resultHandler)
167:                            .directlyHandleAssignments(sched, data, timeOps);
168:                } catch (Exception e) {
169:                    logger.error(getName()
170:                            + ".runDirectly - Got error running scheduler : "
171:                            + e.getMessage(), e);
172:                } finally {
173:                    cleanUpAfterScheduling(unhandledTasks);
174:                }
175:            }
176:
177:            /** calls methods on SchedulingData to add tasks, resources, and changed resources */
178:            protected void addTasksDirectly(SchedulingData data,
179:                    List vishnuTasks, List vishnuResources,
180:                    List changedVishnuResources) {
181:                Date start = new Date();
182:
183:                if (logger.isInfoEnabled())
184:                    logger.info(getName() + ".runDirectly - adding "
185:                            + vishnuTasks.size() + " tasks, "
186:                            + vishnuResources.size() + " resources, "
187:                            + changedVishnuResources.size()
188:                            + " changed resources to scheduler data.");
189:
190:                for (int i = 0; i < vishnuTasks.size(); i++) {
191:                    Object vishnuObject = vishnuTasks.get(i);
192:                    data.addTask((com.bbn.vishnu.scheduling.Task) vishnuObject);
193:                }
194:                for (int i = 0; i < vishnuResources.size(); i++) {
195:                    Object vishnuObject = vishnuResources.get(i);
196:                    data.addResource((Resource) vishnuObject);
197:                }
198:                for (int i = 0; i < changedVishnuResources.size(); i++) {
199:                    Object vishnuObject = changedVishnuResources.get(i);
200:                    data.replaceResource((Resource) vishnuObject);
201:                }
202:                if (logger.isDebugEnabled())
203:                    for (int i = 0; i < data.getResources().length; i++) {
204:                        logger.debug(getName()
205:                                + ".addTasksDirectly - Known Resource #" + i
206:                                + " : \n" + data.getResources()[i]);
207:                    }
208:            }
209:
210:            protected String getName() {
211:                return parent.getName() + "-DirectMode";
212:            }
213:
214:            protected List vishnuTasks, vishnuResources,
215:                    changedVishnuResources;
216:            protected boolean debugParseAnswer = false;
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.