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


001:        /*
002:         * <copyright>
003:         *  Copyright 1997-2004 BBNT Solutions, LLC
004:         *  under sponsorship of the Defense Advanced Research Projects Agency (DARPA).
005:         * 
006:         *  This program is free software; you can redistribute it and/or modify
007:         *  it under the terms of the Cougaar Open Source License as published by
008:         *  DARPA on the Cougaar Open Source Website (www.cougaar.org).
009:         * 
010:         *  THE COUGAAR SOFTWARE AND ANY DERIVATIVE SUPPLIED BY LICENSOR IS
011:         *  PROVIDED 'AS IS' WITHOUT WARRANTIES OF ANY KIND, WHETHER EXPRESS OR
012:         *  IMPLIED, INCLUDING (BUT NOT LIMITED TO) ALL IMPLIED WARRANTIES OF
013:         *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND WITHOUT
014:         *  ANY WARRANTIES AS TO NON-INFRINGEMENT.  IN NO EVENT SHALL COPYRIGHT
015:         *  HOLDER BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT OR CONSEQUENTIAL
016:         *  DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE OF DATA OR PROFITS,
017:         *  TORTIOUS CONDUCT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
018:         *  PERFORMANCE OF THE COUGAAR SOFTWARE.
019:         * </copyright>
020:         */
021:
022:        package org.cougaar.mts.corba;
023:
024:        import org.cougaar.mts.corba.idlj.*;
025:
026:        import org.cougaar.core.mts.MessageAddress;
027:        import org.cougaar.core.mts.MessageAttributes;
028:        import org.cougaar.core.mts.SerializationUtils;
029:        import org.cougaar.mts.base.CommFailureException;
030:        import org.cougaar.mts.base.DestinationLink;
031:        import org.cougaar.mts.base.DontRetryException;
032:        import org.cougaar.mts.base.LinkProtocol; // javadoc
033:        import org.cougaar.mts.base.MisdeliveredMessageException;
034:        import org.cougaar.mts.base.NameLookupException;
035:        import org.cougaar.mts.base.RPCLinkProtocol;
036:        import org.cougaar.mts.base.UnregisteredNameException;
037:        import org.cougaar.mts.std.AttributedMessage;
038:
039:        import org.omg.CORBA.ORB;
040:        import org.omg.PortableServer.POA;
041:        import org.omg.PortableServer.POAHelper;
042:
043:        import java.net.URI;
044:
045:        /**
046:         * This {@link LinkProtocol} uses CORBA for communication.
047:         */
048:        public class CorbaLinkProtocol extends RPCLinkProtocol {
049:            public static final String PROTOCOL_TYPE = "-CORBA";
050:
051:            private MT myProxy;
052:            private ORB orb;
053:            private POA poa;
054:
055:            public CorbaLinkProtocol() {
056:                super ();
057:                String[] args = null;
058:                orb = ORB.init(args, null);
059:                try {
060:                    org.omg.CORBA.Object raw = orb
061:                            .resolve_initial_references("RootPOA");
062:                    poa = POAHelper.narrow(raw);
063:                    poa.the_POAManager().activate();
064:                } catch (Exception error) {
065:                    loggingService.error(null, error);
066:                }
067:
068:            }
069:
070:            protected String getProtocolType() {
071:                return PROTOCOL_TYPE;
072:            }
073:
074:            protected Boolean usesEncryptedSocket() {
075:                return Boolean.FALSE;
076:            }
077:
078:            // If this is called, we've already found the remote reference.
079:            // The cost is currently hardwired at an arbitrary value of 1001
080:            // (a little more than RMI).
081:            protected int computeCost(AttributedMessage message) {
082:                return 1001;
083:            }
084:
085:            protected DestinationLink createDestinationLink(
086:                    MessageAddress address) {
087:                return new CorbaLink(address);
088:            }
089:
090:            protected void findOrMakeNodeServant() {
091:                if (myProxy != null)
092:                    return;
093:                MessageAddress myAddress = getNameSupport()
094:                        .getNodeMessageAddress();
095:                MTImpl impl = new MTImpl(myAddress, getDeliverer());
096:                try {
097:                    poa.activate_object(impl);
098:                } catch (Exception ex) {
099:                    loggingService.error(null, ex);
100:                }
101:                myProxy = impl._this ();
102:                setNodeURI(URI.create(orb.object_to_string(myProxy)));
103:            }
104:
105:            protected void remakeNodeServant() {
106:                if (myProxy != null) {
107:                    try {
108:                        byte[] oid = poa.reference_to_id(myProxy);
109:                        poa.deactivate_object(oid);
110:                    } catch (Exception ex) {
111:                        loggingService.error(null, ex);
112:                    }
113:                }
114:                myProxy = null;
115:                findOrMakeNodeServant();
116:            }
117:
118:            /**
119:             * The DestinationLink class for this transport.  Forwarding a
120:             * message with this link means looking up the MT proxy for a
121:             * remote MTImpl, and calling rerouteMessage on it.  */
122:            class CorbaLink extends Link {
123:
124:                CorbaLink(MessageAddress destination) {
125:                    super (destination);
126:                }
127:
128:                protected Object decodeRemoteRef(URI ref) throws Exception {
129:                    String ior = ref.toString();
130:                    org.omg.CORBA.Object raw = orb.string_to_object(ior);
131:                    MT mt = MTHelper.narrow(raw);
132:                    return mt;
133:                }
134:
135:                public Class getProtocolClass() {
136:                    return CorbaLinkProtocol.class;
137:                }
138:
139:                protected MessageAttributes forwardByProtocol(
140:                        Object remote_ref, AttributedMessage message)
141:                        throws NameLookupException, UnregisteredNameException,
142:                        CommFailureException, MisdeliveredMessageException {
143:                    byte[] bytes = null;
144:                    try {
145:                        bytes = SerializationUtils.toByteArray(message);
146:                    } catch (DontRetryException mex) {
147:                        throw new CommFailureException(mex);
148:                    } catch (java.io.IOException iox) {
149:                        // What would this mean?
150:                    }
151:
152:                    byte[] res = null;
153:                    try {
154:                        res = ((MT) remote_ref).rerouteMessage(bytes);
155:                    } catch (CorbaMisdeliveredMessage mis) {
156:                        // force recache of remote
157:                        decache();
158:                        throw new MisdeliveredMessageException(message);
159:                    } catch (CorbaDontRetryException mex) {
160:                        byte[] ex_bytes = mex.cause;
161:                        try {
162:                            DontRetryException mse = (DontRetryException) SerializationUtils
163:                                    .fromByteArray(ex_bytes);
164:                            throw new CommFailureException(mse);
165:                        } catch (Exception ex) {
166:                            // ???
167:                        }
168:                    } catch (Exception corba_ex) {
169:                        // Some other CORBA failure.  Decache and retry.
170:                        decache();
171:                        throw new CommFailureException(corba_ex);
172:                    }
173:
174:                    MessageAttributes attrs = null;
175:                    try {
176:                        attrs = (MessageAttributes) SerializationUtils
177:                                .fromByteArray(res);
178:                    } catch (DontRetryException mex) {
179:                        throw new CommFailureException(mex);
180:                    } catch (java.io.IOException iox) {
181:                        // What would this mean?
182:                    } catch (ClassNotFoundException cnf) {
183:                    }
184:
185:                    return attrs;
186:                }
187:
188:            }
189:
190:            protected void releaseNodeServant() {
191:            }
192:
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.