KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > connector > grizzly > TaskContext


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.web.connector.grizzly;
24
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.OutputStream JavaDoc;
28
29 import java.nio.ByteBuffer JavaDoc;
30
31
32 /**
33  * This class encapsulates the logic required to synchronized
34  * unblocking socket request with the blocked stream architecture of Tomcat.
35  *
36  * @author Jean-Francois Arcand
37  */

38 public class TaskContext{
39
40     
41     /**
42      * Use a PipeInputStream since we are using a non blocking byteChannel.
43      */

44     private InputStream JavaDoc inputStream;
45     
46     
47     /**
48      * Use a PipeInputStream since we are using a non blocking byteChannel.
49      */

50     private ByteBufferStream outputStream;
51     
52
53     // ------------------------------------------------------Constructor -----//
54

55     /**
56      * Create a instance of this object.
57      */

58     public TaskContext(){
59     }
60
61
62     //------------------------------------------------------------------------//
63

64         
65     /**
66      * Return the input stream used by this request. The default stream is an
67      * instance of <code>NonBlockinginputStream</code>
68      */

69     public InputStream JavaDoc getInputStream(){
70         return inputStream;
71     }
72     
73     public OutputStream JavaDoc getOutputStream(){
74         return (OutputStream JavaDoc)outputStream;
75     }
76     
77     public void setInputStream(InputStream JavaDoc inputStream){
78         this.inputStream = inputStream;
79     }
80     
81     public void setOutputStream(ByteBufferStream outputStream){
82         this.outputStream = outputStream;
83     }
84     
85     // ---------------------------------------------------------------------//
86

87         
88     /**
89      * Fill the current output stream with the available bytes
90      */

91     public void write(ByteBuffer JavaDoc byteBuffer) throws IOException JavaDoc {
92         outputStream.write(byteBuffer);
93     }
94         
95     
96     /**
97      * Flush bytes to the <code>NonBlockinginputStream</code>
98      */

99     public void flush() throws IOException JavaDoc {
100         if (outputStream != null) {
101             outputStream.flush();
102         }
103     }
104     
105     
106     /**
107      * Recycle all streams used by this object.
108      */

109     public void recycle() throws IOException JavaDoc{
110         if (inputStream != null){
111             flush();
112             inputStream.close();
113         }
114     }
115     
116 }
117
118
119
120
121
122
Popular Tags