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


001:        package demo.concurrency;
002:
003:        import org.omg.CosConcurrencyControl.*;
004:        import org.omg.CosTransactions.*;
005:        import org.omg.CosNaming.*;
006:
007:        // import LogicLand.LLsSession.*;
008:        // import java.net.Socket.*;
009:        // import java.net.*;
010:        // import java.io.*;
011:
012:        public class Client {
013:            private static Control ctrl = null;
014:            private static TransactionalLockSet lockset = null;
015:            private static TransactionFactory tf = null;
016:
017:            public static void main(String[] args) {
018:                try {
019:                    //            jacorb.security.SecurityRoot.start( args );
020:                    //            org.omg.CORBA.ORB orb = jacorb.orb.Local.get_orb();
021:                    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
022:
023:                    org.omg.PortableServer.POA poa = org.omg.PortableServer.POAHelper
024:                            .narrow(orb.resolve_initial_references("RootPOA"));
025:
026:                    //            Session ss = get_session( orb );
027:                    //            org.omg.CosNaming.NamingContextExt nc = ss.get_naming();
028:                    NamingContextExt nc = NamingContextExtHelper.narrow(orb
029:                            .resolve_initial_references("NameService"));
030:                    NameComponent[] name = new NameComponent[1];
031:                    name[0] = new NameComponent("LogicLand", "transaction");
032:                    tf = TransactionFactoryHelper.narrow(nc.resolve(name));
033:
034:                    name[0] = new NameComponent("LogicLand", "lock");
035:                    LockSetFactory ls = LockSetFactoryHelper.narrow(nc
036:                            .resolve(name));
037:
038:                    name[0] = new NameComponent("LogicLand", "lockset");
039:                    lockset = TransactionalLockSetHelper.narrow(nc
040:                            .resolve(name));
041:                    print_help();
042:                    while (exec_command())
043:                        ;
044:
045:                } catch (Exception e) {
046:                    e.printStackTrace();
047:                }
048:            }
049:
050:            static void print_help() {
051:                System.out
052:                        .println(" ---------------------------------------------------------------------------");
053:                System.out
054:                        .println(" LogicLand group, Concurrency service test program");
055:                System.out
056:                        .println(" ---------------------------------------------------------------------------");
057:                System.out
058:                        .println(" LockMode: Read - r, Write - w, Upgrade - u, IRead - ir, IWrite iw");
059:                System.out
060:                        .println(" ---------------------------------------------------------------------------");
061:                System.out.println(" Commands :");
062:                System.out
063:                        .println(" ---------------------------------------------------------------------------");
064:                System.out
065:                        .println(" Lock     ::= l<LockMode>           // Lock resource ");
066:                System.out
067:                        .println(" Try_Lock ::= t<LockMode>           // Try lock resource ");
068:                System.out
069:                        .println(" Unlock   ::= u<LockMode>           // Unlock resource");
070:                System.out
071:                        .println(" Change   ::= c<LockMode><LockMode> // Change lock from->to");
072:                System.out
073:                        .println(" Start    ::= start[=n]             // n minuts timeout, default - 5");
074:                System.out
075:                        .println(" Commit   ::= commit                // commit transaction ");
076:                System.out
077:                        .println(" Rollback ::= rollback              // rollback transaction");
078:                System.out
079:                        .println(" Print    ::= print                 // print LockSet contents");
080:                System.out
081:                        .println(" Help     ::= help                  // this screen");
082:                System.out
083:                        .println(" Quit     ::= quit                  // quit from test");
084:                System.out
085:                        .println(" ---------------------------------------------------------------------------");
086:            };
087:
088:            static boolean exec_command() {
089:                System.out.print("Ready ;-)");
090:                String cmd = InConsole.read();
091:                System.out.println("Accept:" + cmd);
092:                try {
093:                    if (cmd.equals("quit")) {
094:                        return false;
095:                    } else if (cmd.equals("help")) {
096:                        print_help();
097:                    } else if (cmd.equals("print")) {
098:                        //                lockset.print();
099:                    } else if (cmd.equals("commit")) {
100:                        if (ctrl == null) {
101:                            System.out.println("Error: Transaction not active");
102:                        } else {
103:                            try {
104:                                ctrl.get_terminator().commit(false);
105:                                System.out.println("Commit complete");
106:                            } catch (org.omg.CORBA.OBJECT_NOT_EXIST e) {
107:                                System.out
108:                                        .println("Error: Transaction finnished");
109:                            }
110:                            ctrl = null;
111:                        }
112:                    } else if (cmd.equals("rollback")) {
113:                        if (ctrl == null) {
114:                            System.out.println("Error: Transaction not active");
115:                        } else {
116:                            try {
117:                                ctrl.get_terminator().rollback();
118:                                System.out.println("Rollback complete");
119:                            } catch (org.omg.CORBA.OBJECT_NOT_EXIST e) {
120:                                System.out
121:                                        .println("Error: Transaction finnished");
122:                            }
123:                            ctrl = null;
124:                        }
125:                    } else if (cmd.length() >= 5
126:                            && cmd.substring(0, 5).equals("start")) {
127:                        if (ctrl != null) {
128:                            System.out.println("Error: Transaction is active");
129:                        } else {
130:                            int minute = 5;
131:                            try {
132:                                minute = Integer.parseInt(cmd.substring(6));
133:                            } catch (Exception e) {
134:                                e.printStackTrace();
135:                                System.out.println("Use default 5 min.");
136:                            }
137:                            ctrl = tf.create(minute * 60);
138:                            System.out.println("Transaction started with "
139:                                    + minute + "min timeout");
140:                        }
141:                    } else {
142:                        if (ctrl == null) {
143:                            System.out.println("Error: Transaction not active");
144:                            return true;
145:                        }
146:                        try {
147:                            if (cmd.length() >= 2
148:                                    && cmd.substring(0, 1).equals("l")) {
149:                                lock_mode mode = parse_mode(cmd.substring(1));
150:                                lockset.lock(ctrl.get_coordinator(), mode);
151:                                System.out.println("Lock complete");
152:                            } else if (cmd.length() >= 2
153:                                    && cmd.substring(0, 1).equals("t")) {
154:                                lock_mode mode = parse_mode(cmd.substring(1));
155:                                if (lockset.try_lock(ctrl.get_coordinator(),
156:                                        mode)) {
157:                                    System.out.println("Lock complete");
158:                                } else {
159:                                    System.out.println("Lock uncomplete");
160:                                }
161:                            } else if (cmd.length() >= 2
162:                                    && cmd.substring(0, 1).equals("u")) {
163:                                lock_mode mode = parse_mode(cmd.substring(1));
164:                                lockset.unlock(ctrl.get_coordinator(), mode);
165:                                System.out.println("Unlock complete");
166:                            } else if (cmd.length() >= 3
167:                                    && cmd.substring(0, 1).equals("c")) {
168:                                lock_mode mode = parse_mode(cmd.substring(1));
169:                                lock_mode mode1;
170:                                if (mode.equals(lock_mode.intention_read)
171:                                        || mode
172:                                                .equals(lock_mode.intention_write)) {
173:                                    mode1 = parse_mode(cmd.substring(3));
174:                                } else {
175:                                    mode1 = parse_mode(cmd.substring(2));
176:                                }
177:                                lockset.change_mode(ctrl.get_coordinator(),
178:                                        mode, mode1);
179:                                System.out.println("Change mode complete");
180:                            }
181:                        } catch (org.omg.CORBA.TRANSACTION_ROLLEDBACK e) {
182:                            System.out.println("Error: Transaction RolledBack");
183:                            ctrl = null;
184:                        } catch (org.omg.CORBA.INVALID_TRANSACTION e) {
185:                            System.out.println("Error: Transaction invalid");
186:                            ctrl = null;
187:                        } catch (org.omg.CORBA.OBJECT_NOT_EXIST e) {
188:                            System.out.println("Error: Transaction finnished");
189:                            ctrl = null;
190:                        }
191:                    }
192:                } catch (Exception e) {
193:                    e.printStackTrace();
194:                }
195:                return true;
196:            }
197:
198:            static lock_mode parse_mode(String mode) {
199:                if (mode.substring(0, 1).equals("r")) {
200:                    return lock_mode.read;
201:                } else if (mode.substring(0, 1).equals("w")) {
202:                    return lock_mode.write;
203:                } else if (mode.substring(0, 1).equals("u")) {
204:                    return lock_mode.upgrade;
205:                } else if (mode.substring(0, 2).equals("ir")) {
206:                    return lock_mode.intention_read;
207:                } else if (mode.substring(0, 2).equals("iw")) {
208:                    return lock_mode.intention_write;
209:                }
210:                return lock_mode.read;
211:            };
212:            /*
213:             static Session get_session( org.omg.CORBA.ORB orb ) throws Exception {
214:             String line;
215:             BufferedReader in;
216:             Socket quote = new Socket("192.168.1.9", 9000);
217:             in = new BufferedReader(new InputStreamReader(quote.getInputStream()));
218:             line = in.readLine();
219:             while (line.indexOf("IOR:") != 0) {
220:             line = in.readLine();
221:             }
222:             in.close();
223:             quote.close();
224:
225:             org.omg.CORBA.Object o = orb.string_to_object(line);
226:             return SessionHelper.narrow(o);
227:             }
228:             */
229:        };
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.