Source Code Cross Referenced for SocketHttpServerConnection.java in  » Net » httpcomponents-core-4.0-beta1 » org » apache » http » impl » 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 » Net » httpcomponents core 4.0 beta1 » org.apache.http.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java $
003:         * $Revision: 561083 $
004:         * $Date: 2007-07-30 20:31:17 +0200 (Mon, 30 Jul 2007) $
005:         *
006:         * ====================================================================
007:         * Licensed to the Apache Software Foundation (ASF) under one
008:         * or more contributor license agreements.  See the NOTICE file
009:         * distributed with this work for additional information
010:         * regarding copyright ownership.  The ASF licenses this file
011:         * to you under the Apache License, Version 2.0 (the
012:         * "License"); you may not use this file except in compliance
013:         * with the License.  You may obtain a copy of the License at
014:         *
015:         *   http://www.apache.org/licenses/LICENSE-2.0
016:         *
017:         * Unless required by applicable law or agreed to in writing,
018:         * software distributed under the License is distributed on an
019:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020:         * KIND, either express or implied.  See the License for the
021:         * specific language governing permissions and limitations
022:         * under the License.
023:         * ====================================================================
024:         *
025:         * This software consists of voluntary contributions made by many
026:         * individuals on behalf of the Apache Software Foundation.  For more
027:         * information on the Apache Software Foundation, please see
028:         * <http://www.apache.org/>.
029:         *
030:         */
031:
032:        package org.apache.http.impl;
033:
034:        import java.io.IOException;
035:        import java.net.InetAddress;
036:        import java.net.Socket;
037:        import java.net.SocketException;
038:
039:        import org.apache.http.HttpInetConnection;
040:        import org.apache.http.impl.io.SocketInputBuffer;
041:        import org.apache.http.impl.io.SocketOutputBuffer;
042:        import org.apache.http.io.SessionInputBuffer;
043:        import org.apache.http.io.SessionOutputBuffer;
044:        import org.apache.http.params.HttpConnectionParams;
045:        import org.apache.http.params.HttpParams;
046:
047:        /**
048:         * Implementation of a server-side HTTP connection that can be bound to a 
049:         * network Socket in order to receive and transmit data.
050:         *
051:         * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
052:         *
053:         * @version $Revision: 561083 $
054:         * 
055:         * @since 4.0
056:         */
057:        public class SocketHttpServerConnection extends
058:                AbstractHttpServerConnection implements  HttpInetConnection {
059:
060:            private volatile boolean open;
061:            private Socket socket = null;
062:
063:            public SocketHttpServerConnection() {
064:                super ();
065:            }
066:
067:            protected void assertNotOpen() {
068:                if (this .open) {
069:                    throw new IllegalStateException(
070:                            "Connection is already open");
071:                }
072:            }
073:
074:            protected void assertOpen() {
075:                if (!this .open) {
076:                    throw new IllegalStateException("Connection is not open");
077:                }
078:            }
079:
080:            protected SessionInputBuffer createHttpDataReceiver(
081:                    final Socket socket, int buffersize, final HttpParams params)
082:                    throws IOException {
083:                return new SocketInputBuffer(socket, buffersize, params);
084:            }
085:
086:            protected SessionOutputBuffer createHttpDataTransmitter(
087:                    final Socket socket, int buffersize, final HttpParams params)
088:                    throws IOException {
089:                return new SocketOutputBuffer(socket, buffersize, params);
090:            }
091:
092:            protected void bind(final Socket socket, final HttpParams params)
093:                    throws IOException {
094:                if (socket == null) {
095:                    throw new IllegalArgumentException("Socket may not be null");
096:                }
097:                if (params == null) {
098:                    throw new IllegalArgumentException(
099:                            "HTTP parameters may not be null");
100:                }
101:                this .socket = socket;
102:
103:                int buffersize = HttpConnectionParams
104:                        .getSocketBufferSize(params);
105:
106:                init(createHttpDataReceiver(socket, buffersize, params),
107:                        createHttpDataTransmitter(socket, buffersize, params),
108:                        params);
109:
110:                this .open = true;
111:            }
112:
113:            protected Socket getSocket() {
114:                return this .socket;
115:            }
116:
117:            public boolean isOpen() {
118:                return this .open;
119:            }
120:
121:            public InetAddress getLocalAddress() {
122:                if (this .socket != null) {
123:                    return this .socket.getLocalAddress();
124:                } else {
125:                    return null;
126:                }
127:            }
128:
129:            public int getLocalPort() {
130:                if (this .socket != null) {
131:                    return this .socket.getLocalPort();
132:                } else {
133:                    return -1;
134:                }
135:            }
136:
137:            public InetAddress getRemoteAddress() {
138:                if (this .socket != null) {
139:                    return this .socket.getInetAddress();
140:                } else {
141:                    return null;
142:                }
143:            }
144:
145:            public int getRemotePort() {
146:                if (this .socket != null) {
147:                    return this .socket.getPort();
148:                } else {
149:                    return -1;
150:                }
151:            }
152:
153:            public void setSocketTimeout(int timeout) {
154:                assertOpen();
155:                if (this .socket != null) {
156:                    try {
157:                        this .socket.setSoTimeout(timeout);
158:                    } catch (SocketException ignore) {
159:                        // It is not quite clear from the Sun's documentation if there are any 
160:                        // other legitimate cases for a socket exception to be thrown when setting 
161:                        // SO_TIMEOUT besides the socket being already closed
162:                    }
163:                }
164:            }
165:
166:            public int getSocketTimeout() {
167:                if (this .socket != null) {
168:                    try {
169:                        return this .socket.getSoTimeout();
170:                    } catch (SocketException ignore) {
171:                        return -1;
172:                    }
173:                } else {
174:                    return -1;
175:                }
176:            }
177:
178:            public void shutdown() throws IOException {
179:                this .open = false;
180:                Socket tmpsocket = this .socket;
181:                if (tmpsocket != null) {
182:                    tmpsocket.close();
183:                }
184:            }
185:
186:            public void close() throws IOException {
187:                if (!this .open) {
188:                    return;
189:                }
190:                this .open = false;
191:                doFlush();
192:                try {
193:                    this .socket.shutdownOutput();
194:                } catch (IOException ignore) {
195:                }
196:                try {
197:                    this .socket.shutdownInput();
198:                } catch (IOException ignore) {
199:                }
200:                this.socket.close();
201:            }
202:
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.