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


001:        /*
002:         * CachedSocketFactory.java
003:         *
004:         * $Author: ss150821 $
005:         *
006:         * $Date: 2005/09/21 11:28:55 $ $Revision: 1.12 $
007:         *
008:         * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
009:         *
010:         * Developed by SunPS and SunIR
011:         */
012:
013:        package com.sun.portal.rproxy.connectionhandler;
014:
015:        import java.io.IOException;
016:        import java.net.Socket;
017:        import java.util.logging.Level;
018:        import java.util.logging.Logger;
019:
020:        import com.sun.portal.log.common.PortalLogger;
021:        import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
022:        import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
023:        import com.sun.portal.util.GWLocale;
024:        import com.sun.portal.util.GWLogManager;
025:        import com.sun.portal.util.SystemProperties;
026:        import com.sun.portal.util.SRAEvent;
027:
028:        /**
029:         * This class defines a factory used to create CachedSockets. The types of
030:         * Sockets that it can create are defined in a configuration file called
031:         * CachedSocketFactory.config.
032:         * 
033:         * @author Kevin Hartig
034:         */
035:
036:        public class CachedSocketFactory {
037:
038:            // private static SocketCache _cache;
039:            private static final String BLOCKED_SOCKET_TIMEOUT = "BlockedSocketTimeout";
040:
041:            private static final int DEFAULT_SOCKET_TIMEOUT = 200;
042:
043:            public static int _timeout;
044:
045:            // private static Logger logger =
046:            // Logger.getLogger("com.sun.portal.sra.rproxy");
047:            private static Logger logger = PortalLogger
048:                    .getLogger(CachedSocketFactory.class);
049:
050:            static {
051:                _timeout = GatewayProfile.getInt(BLOCKED_SOCKET_TIMEOUT,
052:                        DEFAULT_SOCKET_TIMEOUT) * 1000;
053:                // _cache = new SocketCache();
054:            }
055:
056:            /**
057:             * Create a new socket.
058:             * 
059:             * @param host
060:             *            the host address the client socket attaches to (d%.d%.d%.d%
061:             *            format)
062:             * @param port
063:             *            the port number to bind to the Socket
064:             * @param socketType
065:             *            the type of socket to create inside the CachedSocket
066:             * @return a CachedSocket bound to the designated host:port and containing a
067:             *         Socket of the requested type. This value is null if socket
068:             *         creation failed.
069:             */
070:            private static CachedSocket createSocket(String host, int port,
071:                    String socketType, Integer logId) {
072:                CachedSocket cachedSocket = null;
073:                Socket socket = null;
074:
075:                // Construct the socket desired and pass it to a newly constructed
076:                // CachedSocket.
077:                // logger.info("Connecting to " + host + ":" + port);
078:                Object[] params0 = { host, ":", port + "" };
079:                logger.log(Level.INFO, "PSSRRPROXY_CSPRCONHNDLR009", params0);
080:
081:                try {
082:                    socket = new Socket(host, port);
083:                    MonitoringSubsystem
084:                            .handleEvent(SRAEvent.PLAIN_SOCKET_CREATED);
085:                } catch (Exception se) {
086:                    // For some reason, we cannot open a new socket, retry!
087:                    // logger.log(Level.SEVERE, "CachedSocketFactory cannot open
088:                    // connection to " + host + ":" + port, se);
089:                    Object[] params1 = { host, ":", port + "", se };
090:                    logger.log(Level.SEVERE, "PSSRRPROXY_CSPRCONHNDLR010",
091:                            params1);
092:
093:                    String retryTimes = SystemProperties
094:                            .get("gateway.sockretries");
095:                    if (retryTimes == null) {
096:                        return null;
097:                    }
098:
099:                    int retries = Integer.parseInt(retryTimes);
100:                    for (int i = 1; i <= retries; i++) {
101:                        try {
102:                            Thread.sleep(3000); // sleep for 3 seconds
103:                        } catch (InterruptedException ie) {
104:                        }
105:
106:                        try {
107:                            logger
108:                                    .warning("CachedSocketFactory: Open new socket; retry #"
109:                                            + i);
110:                            socket = new Socket(host, port);
111:                            MonitoringSubsystem
112:                                    .handleEvent(SRAEvent.PLAIN_SOCKET_CREATED);
113:                            if (socket != null)
114:                                break; // socket creation retry is successful
115:                        } catch (Exception rse) {
116:                            // logger.log(Level.SEVERE, "CachedSocketFactory cannot open
117:                            // connection to " + host + ":" + port, rse);
118:                            Object[] params2 = { host, ":", port + "", rse };
119:                            logger.log(Level.SEVERE,
120:                                    "PSSRRPROXY_CSPRCONHNDLR011", params2);
121:                        }
122:                    }
123:
124:                    if (socket == null)
125:                        return null;
126:                }
127:
128:                if (GWLogManager.loggingEnabled) {
129:                    GWLogManager.write("RProxy", GWLocale.getPFString("csf1",
130:                            new Object[] { logId, host,
131:                                    new Integer(socket.getPort()) }));
132:                }
133:                try {
134:                    socket.setSoTimeout(_timeout);
135:                    socket.setTcpNoDelay(true);
136:
137:                    cachedSocket = new CachedSocket(socket);
138:                    /*
139:                     * cachedSocket.setType(socketType); cachedSocket.setActive();
140:                     */
141:                    // cachedSocket.setSocketCache(_cache);
142:                    // _cache.putSocket(cachedSocket);
143:                } catch (Exception e) {
144:                    // logger.log(Level.SEVERE, "CachedSocketFactory socket error", e);
145:                    logger.log(Level.SEVERE, "PSSRRPROXY_CSPRCONHNDLR012", e);
146:                    if (socket != null) {
147:                        try {
148:                            socket.close();
149:                            MonitoringSubsystem
150:                                    .handleEvent(SRAEvent.PLAIN_SOCKET_DESTROYED);
151:                        } catch (IOException e1) {
152:                        }
153:                        /**
154:                         * Bug 4710658
155:                         */
156:                        finally {
157:                            socket = null;
158:                        }
159:                        // End of code change for Bug 4710658
160:                    }
161:                }
162:
163:                return cachedSocket;
164:            }
165:
166:            /**
167:             * Get a CachedSocket with a Socket of appropriate type. The CachedSocket
168:             * returned could be a newly created one or one already in the socket cache
169:             * ready for reuse.
170:             * 
171:             * @param host
172:             *            the host address the client socket attaches to (d%.d%.d%.d%
173:             *            format)
174:             * @param port
175:             *            the port number to bind to the Socket
176:             * @param socketType
177:             *            the type of socket to create inside the CachedSocket
178:             * @return a CachedSocket bound to the designated host:port and containing a
179:             *         Socket of the requested type. This value is null if socket
180:             *         creation failed.
181:             * 
182:             */
183:            public static CachedSocket getCachedSocket(String host, int port,
184:                    String socketType, Integer logId) {
185:                // Try to get a socket already in the cache
186:                // There are problems with InetAddress.getByName().getHostAddress()
187:                // -- sometimes hangs for a period of time. Hence, use CachedSockets
188:
189:                return createSocket(host, port, socketType, logId);
190:            }
191:
192:            /**
193:             * Get a CachedSocket with a Socket of appropriate type. The CachedSocket
194:             * returned could be a newly created one or one already in the socket cache
195:             * ready for reuse.
196:             * 
197:             * @param host
198:             *            the host address the client socket attaches to (d%.d%.d%.d%
199:             *            format)
200:             * @param port
201:             *            the port number to bind to the Socket
202:             * @param socketType
203:             *            the type of socket to create inside the CachedSocket
204:             * @return a CachedSocket bound to the designated host:port and containing a
205:             *         Socket of the requested type. This value is null if socket
206:             *         creation failed.
207:             * 
208:             */
209:            public static CachedSocket getNewCachedSocket(String host,
210:                    int port, String socketType, Integer logId) {
211:                // get a newly created socket that was just put in the cache
212:                return createSocket(host, port, socketType, logId);
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.