Source Code Cross Referenced for AbstractSocket.java in  » Database-DBMS » myoodb-2.2.1 » org » myoodb » core » 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 » Database DBMS » myoodb 2.2.1 » org.myoodb.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        ///////////////////////////////////////////////////////////////////////////////
002:        //
003:        //   Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004:        //
005:        //                          All Rights Reserved
006:        //
007:        //   This program is free software; you can redistribute it and/or modify
008:        //   it under the terms of the GNU General Public License and GNU Library
009:        //   General Public License as published by the Free Software Foundation;
010:        //   either version 2, or (at your option) any later version.
011:        //
012:        //   This program is distributed in the hope that it will be useful,
013:        //   but WITHOUT ANY WARRANTY; without even the implied warranty of
014:        //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015:        //   GNU General Public License and GNU Library General Public License
016:        //   for more details.
017:        //
018:        //   You should have received a copy of the GNU General Public License
019:        //   and GNU Library General Public License along with this program; if
020:        //   not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021:        //   MA 02139, USA.
022:        //
023:        ///////////////////////////////////////////////////////////////////////////////
024:        package org.myoodb.core;
025:
026:        import java.io.*;
027:        import java.net.*;
028:        import javax.net.ssl.*;
029:
030:        public abstract class AbstractSocket extends AbstractConnection {
031:            private static volatile SSLContext s_sslContext = null;
032:
033:            private Timer m_timer;
034:
035:            protected Socket m_socket;
036:            protected ObjectInputStream m_in;
037:            protected ObjectOutputStream m_out;
038:
039:            public static void setSSLContextDefault(SSLContext sslContext) {
040:                s_sslContext = sslContext;
041:            }
042:
043:            public static SSLContext getSSLContextDefault() {
044:                return s_sslContext;
045:            }
046:
047:            public AbstractSocket(AbstractDatabase db, Socket socket)
048:                    throws java.io.IOException {
049:                super (db, null);
050:
051:                m_socket = socket;
052:
053:                init();
054:            }
055:
056:            public AbstractSocket(AbstractDatabase db, Long id, String host,
057:                    int port, int timeout, boolean secure, SSLContext ssl)
058:                    throws IOException {
059:                super (db, id);
060:
061:                if (secure == true) {
062:                    SSLSocketFactory sslsocketfactory = null;
063:
064:                    if (ssl != null) {
065:                        sslsocketfactory = (SSLSocketFactory) ssl
066:                                .getSocketFactory();
067:                    }
068:
069:                    if ((s_sslContext != null) && (sslsocketfactory == null)) {
070:                        sslsocketfactory = (SSLSocketFactory) s_sslContext
071:                                .getSocketFactory();
072:                    }
073:
074:                    if (sslsocketfactory == null) {
075:                        sslsocketfactory = (SSLSocketFactory) SSLSocketFactory
076:                                .getDefault();
077:                    }
078:
079:                    m_socket = (Socket) sslsocketfactory.createSocket();
080:                } else {
081:                    m_socket = new Socket();
082:                }
083:
084:                if (timeout != -1) {
085:                    m_socket
086:                            .connect(new InetSocketAddress(host, port), timeout);
087:                } else {
088:                    m_socket.connect(new InetSocketAddress(host, port));
089:                }
090:
091:                init();
092:            }
093:
094:            protected void init() throws IOException {
095:                m_timer = null;
096:
097:                m_socket.setKeepAlive(true);
098:                m_socket.setTcpNoDelay(true);
099:                m_socket.setSendBufferSize(getBufferSize());
100:                m_socket.setReceiveBufferSize(getBufferSize());
101:
102:                m_out = getObjectOutputStream(m_socket.getOutputStream());
103:                m_out.flush();
104:                m_in = getObjectInputStream(m_socket.getInputStream());
105:            }
106:
107:            protected void setSoTimeout(int timeout) throws SocketException {
108:                m_socket.setSoTimeout(timeout);
109:            }
110:
111:            protected int getSoTimeout() throws SocketException {
112:                return m_socket.getSoTimeout();
113:            }
114:
115:            public void send(Object obj) throws IOException {
116:                if (m_out != null) {
117:                    try {
118:                        m_out.writeObject(obj);
119:                    } finally {
120:                        m_out.flush();
121:                        m_out.reset();
122:                    }
123:                }
124:            }
125:
126:            public Object receive(int timeout) throws IOException,
127:                    ClassNotFoundException,
128:                    org.myoodb.exception.TimeoutException {
129:                if (m_in == null) {
130:                    throw new IOException("connection has been closed");
131:                }
132:
133:                if (timeout != -1) {
134:                    m_timer = new Timer(m_in, timeout);
135:                    m_timer.setDaemon(true);
136:                    m_timer.setName("MyOodb Receive Tcp Timeout Thread: "
137:                            + m_socket.getLocalAddress());
138:                    m_timer.start();
139:                }
140:
141:                Object result = null;
142:
143:                try {
144:                    result = m_in.readObject();
145:                } catch (IOException e) {
146:                    if ((timeout != -1) && (m_timer.hasExpired() == true)) {
147:                        throw new org.myoodb.exception.TimeoutException(
148:                                "Receive timed out");
149:                    } else {
150:                        throw e;
151:                    }
152:                } finally {
153:                    if (timeout != -1) {
154:                        m_timer.halt();
155:                        m_timer = null;
156:                    }
157:                }
158:
159:                return result;
160:            }
161:
162:            public void close() throws IOException {
163:                Socket socket = m_socket;
164:                m_socket = null;
165:
166:                ObjectInputStream in = m_in;
167:                m_in = null;
168:
169:                ObjectOutputStream out = m_out;
170:                m_out = null;
171:
172:                if (socket != null) {
173:                    socket.close();
174:                }
175:
176:                if (out != null) {
177:                    out.close();
178:                }
179:
180:                if (in != null) {
181:                    in.close();
182:                }
183:            }
184:
185:            public boolean isConnected() {
186:                return (m_socket != null) ? m_socket.isInputShutdown() == false
187:                        : false;
188:            }
189:
190:            public Socket getSocket() {
191:                return m_socket;
192:            }
193:
194:            public String toString() {
195:                return (m_socket != null) ? m_socket.toString() : super
196:                        .toString();
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.