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


001:        /* 
002:         * <copyright>
003:         *  
004:         *  Copyright 2002-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.core.adaptivity;
028:
029:        import java.util.Collections;
030:        import java.util.Set;
031:
032:        import org.cougaar.core.mts.MessageAddress;
033:        import org.cougaar.core.relay.Relay;
034:        import org.cougaar.core.util.UID;
035:        import org.cougaar.util.log.Logger;
036:        import org.cougaar.util.log.Logging;
037:
038:        /**
039:         * A remotely-controlled OperatingModePolicy. Allows a policy manager in one
040:         * agent to control a Policy of the in another. It is instantiated in 
041:         * the controlling agent and transferred
042:         * to the controlled agent using the Relay logic providers. A copy
043:         * of the instance is published in the controlled agent's blackboard
044:         * and used like any other OperatingModePolicy.
045:         **/
046:        public class InterAgentOperatingModePolicy extends OperatingModePolicy
047:                implements  Relay.Source, Relay.Target, java.io.Serializable {
048:            // this can't be transient like other relays, cause not storing
049:            // target separately
050:            private Set targets = Collections.EMPTY_SET;
051:            protected MessageAddress source;
052:            protected Relay.Token owner;
053:
054:            // Constructors
055:            public InterAgentOperatingModePolicy(PolicyKernel pk) {
056:                super (pk);
057:            }
058:
059:            public InterAgentOperatingModePolicy(ConstrainingClause ifClause,
060:                    ConstraintPhrase[] omConstraints) {
061:                super (ifClause, omConstraints);
062:            }
063:
064:            public InterAgentOperatingModePolicy(String name,
065:                    ConstrainingClause ifClause,
066:                    ConstraintPhrase[] omConstraints, String authority) {
067:                super (name, ifClause, omConstraints, authority);
068:            }
069:
070:            protected InterAgentOperatingModePolicy(
071:                    InterAgentOperatingModePolicy other, MessageAddress src,
072:                    Relay.Token owner) {
073:                this (other.getName(), other.getIfClause(), other
074:                        .getOperatingModeConstraints(), other.getAuthority());
075:                setUID(other.getUID());
076:                this .owner = owner;
077:                this .source = src;
078:            }
079:
080:            // Initialization methods
081:            /**
082:             * Set the message address of the target. This implementation
083:             * presumes that there is but one target.
084:             * @param targetAddress the address of the target agent.
085:             **/
086:            public void setTarget(MessageAddress targetAddress) {
087:                targets = Collections.singleton(targetAddress);
088:            }
089:
090:            /**
091:             * appliesToThisAgent - return true if InterAgentOperatingModePolicy applies to 
092:             * this Agent.
093:             * Default behaviour is to assume that InterAgentOperatingModePolicy does not
094:             * apply to the originating Agent.
095:             */
096:            public boolean appliesToThisAgent() {
097:                // Policy only valid is it did not originate here
098:                return (getSource() != null);
099:            }
100:
101:            // Relay.Source interface
102:            /**
103:             * Get all the addresses of the target agents to which this Relay
104:             * should be sent. For this implementation this is always a
105:             * singleton set contain just one target.
106:             **/
107:            public Set getTargets() {
108:                return targets;
109:            }
110:
111:            /**
112:             * Get an object representing the value of this Relay suitable
113:             * for transmission. This implementation uses itself to represent
114:             * its Content.
115:             **/
116:            public Object getContent() {
117:                return this ;
118:            }
119:
120:            /**
121:             * @return a factory to convert the content to a Relay Target.
122:             **/
123:            public Relay.TargetFactory getTargetFactory() {
124:                return InterAgentPolicyFactory.INSTANCE;
125:            }
126:
127:            /**
128:             * Set the response that was sent from a target. For LP use only.
129:             * This implemenation does nothing because responses are not needed
130:             * or used.
131:             **/
132:            public int updateResponse(MessageAddress target, Object response) {
133:                // No response expected
134:                return Relay.NO_CHANGE;
135:            }
136:
137:            // Relay.Target implementation
138:            /**
139:             * Get the address of the Agent holding the Source copy of
140:             * this Relay.
141:             **/
142:            public MessageAddress getSource() {
143:                return source;
144:            }
145:
146:            /**
147:             * Get the current response for this target. Null indicates that
148:             * this target has no response. This implementation never has a
149:             * response so it always returns null.
150:             **/
151:            public Object getResponse() {
152:                return null;
153:            }
154:
155:            /**
156:             * Update with new content. The only part of the source content used
157:             * is the value of the operating mode.
158:             * @return true if the update changed the Relay. The LP should
159:             * publishChange the Relay. This implementation returns true only
160:             * if the new value differs from the current value.
161:             **/
162:            public int updateContent(Object content, Relay.Token token) {
163:                if (token != owner) {
164:                    Logger logger = Logging.getLogger(getClass());
165:                    if (logger.isInfoEnabled()) {
166:                        logger
167:                                .info("Ignoring \"Not owner\" bug in \"updateContent()\","
168:                                        + " possibly a rehydration bug (token="
169:                                        + token + ", owner=" + owner + ")");
170:                    }
171:                }
172:                InterAgentOperatingModePolicy newOMP = (InterAgentOperatingModePolicy) content;
173:                // brute force, no brains
174:                setPolicyKernel(newOMP.getPolicyKernel());
175:                return Relay.CONTENT_CHANGE;
176:            }
177:
178:            /**
179:             * This factory creates a new InterAgentOperatingModePolicy.
180:             **/
181:            private static class InterAgentPolicyFactory implements 
182:                    Relay.TargetFactory, java.io.Serializable {
183:                public static final InterAgentPolicyFactory INSTANCE = new InterAgentPolicyFactory();
184:
185:                private InterAgentPolicyFactory() {
186:                }
187:
188:                public Relay.Target create(UID uid, MessageAddress source,
189:                        Object content, Relay.Token owner) {
190:                    InterAgentOperatingModePolicy iaomp = (InterAgentOperatingModePolicy) content;
191:                    return new InterAgentOperatingModePolicy(iaomp, source,
192:                            owner);
193:                }
194:
195:                private Object readResolve() {
196:                    return INSTANCE;
197:                }
198:            }
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.