Source Code Cross Referenced for SClientMgr.java in  » Portal » Open-Portal » com » sun » portal » netlet » client » common » 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 » Portal » Open Portal » com.sun.portal.netlet.client.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // %Z%%M% %I%     "%W% %E% Sun Microsystems"
002:
003:        package com.sun.portal.netlet.client.common;
004:
005:        import java.util.Hashtable;
006:        import java.util.Vector;
007:        import java.util.Enumeration;
008:
009:        public class SClientMgr implements  Runnable {
010:
011:            private SClient allproxies[];
012:
013:            //  could be another object, but this is temporary anyway!
014:            private int numConfig = 0;
015:            private String ruleNames[];
016:            private int srcPort[];
017:            private String serverPort[];
018:            private String serverHost[];
019:            private String threadname[];
020:            private int keyLength[];
021:            private String cipherName[];
022:            private int numProxies;
023:
024:            private Thread t = null;
025:
026:            private Hashtable clientPorts; // Mapping of clientPort to ruleName.
027:            private boolean started = false;
028:
029:            public SClientMgr(int numProxies) {
030:                this .numProxies = numProxies;
031:                ruleNames = new String[numProxies];
032:                srcPort = new int[numProxies];
033:                serverPort = new String[numProxies];
034:                serverHost = new String[numProxies];
035:                threadname = new String[numProxies];
036:                allproxies = new SClient[numProxies];
037:                keyLength = new int[numProxies];
038:                cipherName = new String[numProxies];
039:                clientPorts = new Hashtable();
040:
041:            }
042:
043:            public void start() {
044:                if (t == null) {
045:                    t = new Thread(this );
046:                    t.start();
047:                }
048:            }
049:
050:            public void run() {
051:                for (int i = 0; i < numConfig; i++) {
052:                    addproxy(ruleNames[i], srcPort[i], serverPort[i],
053:                            serverHost[i], threadname[i], false, cipherName[i],
054:                            keyLength[i]);
055:                }
056:                System.out.println("Local port configuration -> "
057:                        + clientPorts.toString());
058:                synchronized (this ) {
059:                    started = true;
060:                }
061:                notifyStart();
062:            }
063:
064:            /**
065:             * Wait until all the SClients are started
066:             */
067:            synchronized public void waitToStart() {
068:                if (started)
069:                    return;
070:                try {
071:                    wait();
072:                } catch (InterruptedException e) {
073:                    e.printStackTrace();
074:                }
075:            }
076:
077:            /**
078:             * Notify any events to the waiting threads.
079:             */
080:            synchronized public void notifyStart() {
081:                notify();
082:            }
083:
084:            /**
085:             * Create a Map with ruleName as key, set of ClientPorts as value.
086:             */
087:            public Hashtable getClientPorts() {
088:                return clientPorts;
089:            }
090:
091:            public String getFormattedClientPorts() {
092:        StringBuffer clientPortSB = new StringBuffer();
093:        Enumeration enum = clientPorts.keys();
094:        int htSize = clientPorts.size();
095:        while (enum.hasMoreElements()) {
096:            String ruleName = (String) enum.nextElement();
097:            clientPortSB.append(ruleName).append("->");
098:            Vector v = (Vector) clientPorts.get(ruleName);
099:            int vSize = v.size();
100:            Enumeration ports = v.elements();
101:            while (ports.hasMoreElements()) {
102:                String port = (String) ports.nextElement();
103:                clientPortSB.append(port);
104:                if (--vSize > 0) {
105:                    clientPortSB.append(",");
106:                }
107:            }
108:            if (--htSize > 0) {
109:                clientPortSB.append("|");
110:            }
111:        }
112:        return clientPortSB.toString();
113:    }
114:
115:            public void stop() {
116:                if (t != null) {
117:                    t.stop();
118:                    t = null;
119:                }
120:            }
121:
122:            public void addconfig(String ruleName, int srcp, String srvp,
123:                    String srvh, String tname, String ciphername) {
124:                ruleNames[numConfig] = ruleName;
125:                srcPort[numConfig] = srcp;
126:                serverPort[numConfig] = new String(srvp);
127:                serverHost[numConfig] = new String(srvh);
128:                threadname[numConfig] = new String(tname);
129:                cipherName[numConfig] = new String(ciphername);
130:                numConfig++;
131:            }
132:
133:            //  pretty heavyweight, but leave like this just in case we an a UI!
134:            //  then we'll put back ActionListener code...
135:
136:            public void addproxy(String ruleName, int srcp, String srvp,
137:                    String srvh, String tname, boolean trans,
138:                    String ciphername, int keylength) {
139:                //  see if this thread already exists, if not, then create it
140:
141:                boolean foundthread = false;
142:                int firstthread = -1;
143:                int i = 0;
144:                while (i < numProxies) {
145:                    if (allproxies[i] != null && !allproxies[i].stopped) {
146:                        if (allproxies[i].getName().equals(tname)) {
147:                            foundthread = true;
148:                        }
149:                    } else {
150:                        if (firstthread == -1) {
151:                            firstthread = i;
152:                        }
153:                    }
154:                    i++;
155:                }
156:                if (!foundthread && (firstthread != -1)) {
157:                    //  have a free slot and no match, create thread
158:                    SClient sc = new SClient(srcp, srvp, srvh, tname, this ,
159:                            trans, ciphername, keylength);
160:                    allproxies[firstthread] = sc;
161:                    allproxies[firstthread].start();
162:                    Object obj = clientPorts.get(ruleNames[firstthread]);
163:                    Vector v = null;
164:                    if (obj != null) {
165:                        v = (Vector) obj;
166:                    } else {
167:                        v = new Vector();
168:                    }
169:                    v.addElement(allproxies[firstthread].getSrcPortInRule()
170:                            + ":" + allproxies[firstthread].getSrcPort());
171:                    clientPorts.put(ruleNames[firstthread], v);
172:
173:                } else {
174:                    if (firstthread == -1) {
175:                        System.out
176:                                .println("Netlet: SCM Required number of proxies already started");
177:                    }
178:                }
179:            }
180:
181:            public void stopProcessing() {
182:                for (int i = 0; i < numConfig; i++) {
183:                    if (allproxies[i] != null) {
184:                        allproxies[i].stop();
185:                        allproxies[i] = null;
186:                    }
187:                }
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.