KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > coyote > memory > MemoryProtocolHandler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.coyote.memory;
19
20 import java.io.IOException JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import org.apache.tomcat.util.buf.ByteChunk;
23
24 import org.apache.coyote.Adapter;
25 import org.apache.coyote.InputBuffer;
26 import org.apache.coyote.OutputBuffer;
27 import org.apache.coyote.ProtocolHandler;
28 import org.apache.coyote.Request;
29 import org.apache.coyote.Response;
30
31
32 /**
33  * Abstract the protocol implementation, including threading, etc.
34  * Processor is single threaded and specific to stream-based protocols,
35  * will not fit Jk protocols like JNI.
36  *
37  * @author Remy Maucherat
38  */

39 public class MemoryProtocolHandler
40     implements ProtocolHandler {
41
42
43     // ------------------------------------------------------------- Properties
44

45
46     /**
47      * Pass config info.
48      */

49     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
50     }
51
52     public Object JavaDoc getAttribute(String JavaDoc name) {
53         return null;
54     }
55
56     public Iterator JavaDoc getAttributeNames() { return null ; }
57     /**
58      * Associated adapter.
59      */

60     protected Adapter adapter = null;
61
62     /**
63      * The adapter, used to call the connector.
64      */

65     public void setAdapter(Adapter adapter) {
66         this.adapter = adapter;
67     }
68
69     public Adapter getAdapter() {
70         return (adapter);
71     }
72
73
74     // ------------------------------------------------ ProtocolHandler Methods
75

76
77     /**
78      * Init the protocol.
79      */

80     public void init()
81         throws Exception JavaDoc {
82     }
83
84
85     /**
86      * Start the protocol.
87      */

88     public void start()
89         throws Exception JavaDoc {
90     }
91
92
93     public void pause()
94         throws Exception JavaDoc {
95     }
96
97     public void resume()
98         throws Exception JavaDoc {
99     }
100
101     public void destroy()
102         throws Exception JavaDoc {
103     }
104
105
106     // --------------------------------------------------------- Public Methods
107

108
109     /**
110      * Process specified request.
111      */

112     public void process(Request request, ByteChunk input,
113                         Response response, ByteChunk output)
114         throws Exception JavaDoc {
115
116         InputBuffer inputBuffer = new ByteChunkInputBuffer(input);
117         OutputBuffer outputBuffer = new ByteChunkOutputBuffer(output);
118         request.setInputBuffer(inputBuffer);
119         response.setOutputBuffer(outputBuffer);
120
121         adapter.service(request, response);
122
123     }
124
125
126     // --------------------------------------------- ByteChunkInputBuffer Class
127

128
129     protected class ByteChunkInputBuffer
130         implements InputBuffer {
131
132         protected ByteChunk input = null;
133
134         public ByteChunkInputBuffer(ByteChunk input) {
135             this.input = input;
136         }
137
138         public int doRead(ByteChunk chunk, Request request)
139             throws IOException JavaDoc {
140             return input.substract(chunk);
141         }
142
143     }
144
145
146     // -------------------------------------------- ByteChunkOuptutBuffer Class
147

148
149     protected class ByteChunkOutputBuffer
150         implements OutputBuffer {
151
152         protected ByteChunk output = null;
153
154         public ByteChunkOutputBuffer(ByteChunk output) {
155             this.output = output;
156         }
157
158         public int doWrite(ByteChunk chunk, Response response)
159             throws IOException JavaDoc {
160             output.append(chunk);
161             return chunk.getLength();
162         }
163
164     }
165
166
167 }
168
Popular Tags