KickJava   Java API By Example, From Geeks To Geeks.

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


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.nio.ByteBuffer JavaDoc;
26 import java.nio.channels.SocketChannel JavaDoc;
27 /**
28  * This interface defines the methods an instance of a <code>ReadTask</code>
29  * will invoke. The <code>ReadTask</code> will use an implementation of this
30  * interface tp predict if the NIO code>ByteBuffer</code> has been fully
31  * read and can be processed.
32  *
33  * <code>ReadTask</code> will invoke the method in the following order:
34  *
35  * (a) allocate(...)
36  * (b) preParse(...)
37  * (c) parse(...)
38  * (d) contentLength() AND headerLength();
39  * (d) postParse(...)
40  *
41  * The algorithm will stop once (c) return <code>true</code>
42  *
43  * @author Jean-Francois Arcand
44  */

45 public interface StreamAlgorithm{
46     
47     
48     /**
49      * Return the stream content-length. If the content-length wasn't parsed,
50      * return -1.
51      */

52     public int contentLength();
53     
54     
55     /**
56      * Return the stream header length. The header length is the length between
57      * the start of the stream and the first occurance of character '\r\n' .
58      */

59     public int headerLength();
60     
61     
62     /**
63      * Allocate a <code>ByteBuffer</code>
64      * @param useDirect allocate a direct <code>ByteBuffer</code>.
65      * @param useView allocate a view <code>ByteBuffer</code>.
66      * @return a new <code>ByteBuffer</code>
67      */

68     public ByteBuffer JavaDoc allocate(boolean useDirect, boolean useView);
69     
70     
71     /**
72      * Before parsing the bytes, initialize and prepare the algorithm.
73      * @param byteBuffer the <code>ByteBuffer</code> used by this algorithm
74      * @return <code>ByteBuffer</code> used by this algorithm
75      */

76     public ByteBuffer JavaDoc preParse(ByteBuffer JavaDoc byteBuffer);
77     
78     
79     /**
80      * Parse the <code>ByteBuffer</code> and try to determine if the bytes
81      * stream has been fully read from the <code>SocketChannel</code>.
82      * @paran byteBuffer the bytes read.
83      * @return true if the algorithm determines the end of the stream.
84      */

85     public boolean parse(ByteBuffer JavaDoc byteBuffer);
86     
87     
88     /**
89      * After parsing the bytes, post process the <code>ByteBuffer</code>
90      * @param byteBuffer the <code>ByteBuffer</code> used by this algorithm
91      * @return <code>ByteBuffer</code> used by this algorithm
92      */

93     public ByteBuffer JavaDoc postParse(ByteBuffer JavaDoc byteBuffer);
94     
95     
96     /**
97      * Recycle the algorithm.
98      */

99     public void recycle();
100
101     
102     /**
103      * The <code>Handler</code> associated with this algorithm.
104      */

105     public Handler getHandler();
106
107     
108     /**
109      * Set the <code>SocketChannel</code> used by this algorithm
110      */

111     public void setSocketChannel(SocketChannel JavaDoc socketChannel);
112     
113     
114     /**
115      * Set the <code>port</code> this algorithm is used.
116      */

117     public void setPort(int port);
118     
119     
120     /**
121      * Return the port
122      */

123     public int getPort();
124 }
125
126
Popular Tags