Source Code Cross Referenced for Client.java in  » Collaboration » JacORB » demo » policies » 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 » Collaboration » JacORB » demo.policies 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package demo.policies;
002:
003:        import java.io.*;
004:        import org.omg.CORBA.*;
005:        import org.omg.Messaging.*;
006:
007:        /**
008:         * A simple demo that shows how to use CORBA QoS policies at the level
009:         * of individual objects, or ORB-wide. This is a variaton on hello
010:         * world and relies on IOR files rather than the naming service.
011:         *
012:         * @author Gerald Brose
013:         */
014:
015:        public class Client {
016:            public static final int MSEC_FACTOR = 10000;
017:            public static final int ONE_SECOND = 1000 * MSEC_FACTOR;
018:
019:            public static void main(String args[]) {
020:                if (args.length != 1) {
021:                    System.out
022:                            .println("Usage: jaco demo.policies.Client <ior_file>");
023:                    System.exit(1);
024:                }
025:
026:                try {
027:                    // read IOR from file
028:                    File f = new File(args[0]);
029:                    if (!f.exists()) {
030:                        System.out.println("File " + args[0]
031:                                + " does not exist.");
032:                        System.exit(-1);
033:                    }
034:
035:                    //check if args[0] points to a directory
036:                    if (f.isDirectory()) {
037:                        System.out.println("File " + args[0]
038:                                + " is a directory.");
039:                        System.exit(-1);
040:                    }
041:                    BufferedReader br = new BufferedReader(new FileReader(f));
042:
043:                    // initialize the ORB
044:                    ORB orb = ORB.init(args, null);
045:
046:                    // get object reference from command-line argument file
047:                    org.omg.CORBA.Object obj = orb.string_to_object(br
048:                            .readLine());
049:
050:                    br.close();
051:
052:                    // and narrow it to HelloWorld.GoodDay
053:                    // if this fails, a BAD_PARAM will be thrown
054:                    GoodDay goodDay = GoodDayHelper.narrow(obj);
055:
056:                    // get PolicyManager and create policies ....
057:
058:                    PolicyManager policyManager = PolicyManagerHelper
059:                            .narrow(orb
060:                                    .resolve_initial_references("ORBPolicyManager"));
061:
062:                    // create an timeout value of 1 sec. The unit is a time
063:                    // step of 100 nano secs., so 10000 of these make up a
064:                    // micro second.
065:                    Any rrtPolicyAny = orb.create_any();
066:                    rrtPolicyAny.insert_ulonglong(ONE_SECOND);
067:
068:                    // create a relative roundtrip timeout policy and set this
069:                    // policy ORB-wide
070:                    Policy rrtPolicy = orb
071:                            .create_policy(
072:                                    RELATIVE_RT_TIMEOUT_POLICY_TYPE.value,
073:                                    rrtPolicyAny);
074:
075:                    policyManager.set_policy_overrides(
076:                            new Policy[] { rrtPolicy },
077:                            SetOverrideType.ADD_OVERRIDE);
078:
079:                    // create a sync scope policy
080:                    Any syncPolicyAny = orb.create_any();
081:                    syncPolicyAny.insert_short(SYNC_WITH_SERVER.value);
082:                    Policy syncPolicy = orb.create_policy(
083:                            SYNC_SCOPE_POLICY_TYPE.value, syncPolicyAny);
084:
085:                    // set the sync scope policy on an object reference
086:                    goodDay._set_policy_override(new Policy[] { syncPolicy },
087:                            SetOverrideType.ADD_OVERRIDE);
088:
089:                    // try to invoke the operation and print the result: this
090:                    // should result in a timeout exception because the server
091:                    // will sleep longer than the timeout (sleep is int msecs.)
092:                    System.out
093:                            .println("Should see a TIMEOUT exception soon...");
094:                    try {
095:                        System.out.println(goodDay.hello(2000));
096:                        System.out
097:                                .println("... should not be here, no exception!");
098:                    } catch (org.omg.CORBA.TIMEOUT t) {
099:                        System.out.println("here it is: " + t.getMessage());
100:                    }
101:
102:                    // create another timeout poliy 
103:                    Any objRrtPolicyAny = orb.create_any();
104:                    objRrtPolicyAny.insert_ulonglong(4 * ONE_SECOND);
105:
106:                    Policy objRrtPolicy = orb.create_policy(
107:                            RELATIVE_RT_TIMEOUT_POLICY_TYPE.value,
108:                            objRrtPolicyAny);
109:
110:                    goodDay._set_policy_override(new Policy[] { objRrtPolicy },
111:                            SetOverrideType.ADD_OVERRIDE);
112:
113:                    // see what the effective policy is now...
114:                    Policy objPol = goodDay
115:                            ._get_policy(RELATIVE_RT_TIMEOUT_POLICY_TYPE.value);
116:
117:                    if (objPol != null) {
118:                        long timoutValue = ((RelativeRoundtripTimeoutPolicy) objPol)
119:                                .relative_expiry();
120:                        System.out.println("Object-level timeout is "
121:                                + timoutValue + " timesteps (100ns)");
122:
123:                        // try the invocation again, in this case the override
124:                        // policy's new timeout should be sufficient to let
125:                        // the call come back
126:                        System.out.println(goodDay.hello(100));
127:                    } else {
128:                        System.out
129:                                .println("ERROR, no Object-level timeout found");
130:                    }
131:                } catch (Exception ex) {
132:                    ex.printStackTrace();
133:                }
134:            }
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.