Source Code Cross Referenced for NioChannel.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » tomcat » util » net » 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 » Sevlet Container » apache tomcat 6.0.14 » org.apache.tomcat.util.net 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.tomcat.util.net;
019:
020:        import java.io.IOException;
021:        import java.nio.ByteBuffer;
022:        import java.nio.channels.ByteChannel;
023:        import java.nio.channels.SocketChannel;
024:
025:        import org.apache.tomcat.util.net.NioEndpoint.Poller;
026:        import org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandler;
027:        import java.nio.channels.Selector;
028:        import java.nio.channels.SelectionKey;
029:
030:        /**
031:         * 
032:         * Base class for a SocketChannel wrapper used by the endpoint.
033:         * This way, logic for a SSL socket channel remains the same as for
034:         * a non SSL, making sure we don't need to code for any exception cases.
035:         * 
036:         * @author Filip Hanik
037:         * @version 1.0
038:         */
039:        public class NioChannel implements  ByteChannel {
040:
041:            protected static ByteBuffer emptyBuf = ByteBuffer.allocate(0);
042:
043:            protected SocketChannel sc = null;
044:
045:            protected ApplicationBufferHandler bufHandler;
046:
047:            protected Poller poller;
048:
049:            public NioChannel(SocketChannel channel,
050:                    ApplicationBufferHandler bufHandler) throws IOException {
051:                this .sc = channel;
052:                this .bufHandler = bufHandler;
053:            }
054:
055:            public void reset() throws IOException {
056:                bufHandler.getReadBuffer().clear();
057:                bufHandler.getWriteBuffer().clear();
058:            }
059:
060:            public int getBufferSize() {
061:                if (bufHandler == null)
062:                    return 0;
063:                int size = 0;
064:                size += bufHandler.getReadBuffer() != null ? bufHandler
065:                        .getReadBuffer().capacity() : 0;
066:                size += bufHandler.getWriteBuffer() != null ? bufHandler
067:                        .getWriteBuffer().capacity() : 0;
068:                return size;
069:            }
070:
071:            /**
072:             * returns true if the network buffer has 
073:             * been flushed out and is empty
074:             * @return boolean
075:             */
076:            public boolean flush(boolean block, Selector s, long timeout)
077:                    throws IOException {
078:                return true; //no network buffer in the regular channel
079:            }
080:
081:            /**
082:             * Closes this channel.
083:             *
084:             * @throws IOException If an I/O error occurs
085:             * @todo Implement this java.nio.channels.Channel method
086:             */
087:            public void close() throws IOException {
088:                getIOChannel().socket().close();
089:                getIOChannel().close();
090:            }
091:
092:            public void close(boolean force) throws IOException {
093:                if (isOpen() || force)
094:                    close();
095:            }
096:
097:            /**
098:             * Tells whether or not this channel is open.
099:             *
100:             * @return <tt>true</tt> if, and only if, this channel is open
101:             * @todo Implement this java.nio.channels.Channel method
102:             */
103:            public boolean isOpen() {
104:                return sc.isOpen();
105:            }
106:
107:            /**
108:             * Writes a sequence of bytes to this channel from the given buffer.
109:             *
110:             * @param src The buffer from which bytes are to be retrieved
111:             * @return The number of bytes written, possibly zero
112:             * @throws IOException If some other I/O error occurs
113:             * @todo Implement this java.nio.channels.WritableByteChannel method
114:             */
115:            public int write(ByteBuffer src) throws IOException {
116:                return sc.write(src);
117:            }
118:
119:            /**
120:             * Reads a sequence of bytes from this channel into the given buffer.
121:             *
122:             * @param dst The buffer into which bytes are to be transferred
123:             * @return The number of bytes read, possibly zero, or <tt>-1</tt> if the channel has reached end-of-stream
124:             * @throws IOException If some other I/O error occurs
125:             * @todo Implement this java.nio.channels.ReadableByteChannel method
126:             */
127:            public int read(ByteBuffer dst) throws IOException {
128:                return sc.read(dst);
129:            }
130:
131:            public Object getAttachment(boolean remove) {
132:                Poller pol = getPoller();
133:                Selector sel = pol != null ? pol.getSelector() : null;
134:                SelectionKey key = sel != null ? getIOChannel().keyFor(sel)
135:                        : null;
136:                Object att = key != null ? key.attachment() : null;
137:                if (key != null && att != null && remove)
138:                    key.attach(null);
139:                return att;
140:            }
141:
142:            /**
143:             * getBufHandler
144:             *
145:             * @return ApplicationBufferHandler
146:             * @todo Implement this org.apache.tomcat.util.net.SecureNioChannel method
147:             */
148:            public ApplicationBufferHandler getBufHandler() {
149:                return bufHandler;
150:            }
151:
152:            public Poller getPoller() {
153:                return poller;
154:            }
155:
156:            /**
157:             * getIOChannel
158:             *
159:             * @return SocketChannel
160:             * @todo Implement this org.apache.tomcat.util.net.SecureNioChannel method
161:             */
162:            public SocketChannel getIOChannel() {
163:                return sc;
164:            }
165:
166:            /**
167:             * isClosing
168:             *
169:             * @return boolean
170:             * @todo Implement this org.apache.tomcat.util.net.SecureNioChannel method
171:             */
172:            public boolean isClosing() {
173:                return false;
174:            }
175:
176:            /**
177:             * isInitHandshakeComplete
178:             *
179:             * @return boolean
180:             * @todo Implement this org.apache.tomcat.util.net.SecureNioChannel method
181:             */
182:            public boolean isInitHandshakeComplete() {
183:                return true;
184:            }
185:
186:            public int handshake(boolean read, boolean write)
187:                    throws IOException {
188:                return 0;
189:            }
190:
191:            public void setPoller(Poller poller) {
192:                this .poller = poller;
193:            }
194:
195:            public void setIOChannel(SocketChannel IOChannel) {
196:                this .sc = IOChannel;
197:            }
198:
199:            public String toString() {
200:                return super .toString() + ":" + this.sc.toString();
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.