##### Coverage Report - com.sun.grizzly.ProtocolParser

Classes in this File | Line Coverage | Branch Coverage | Complexity
ProtocolParser |
N/A | N/A
N/A | N/A
| 0.0;0

1 |  |
     /*
2 |  |
      *
3 |  |
      * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 |  |
      *
5 |  |
      * Copyright 2007-2008 Sun Microsystems, Inc. All rights reserved.
6 |  |
      *
7 |  |
      * The contents of this file are subject to the terms of either the GNU
8 |  |
      * General Public License Version 2 only ("GPL") or the Common Development
9 |  |
      * and Distribution License("CDDL") (collectively, the "License").  You
10 |  |
      * may not use this file except in compliance with the License. You can obtain
11 |  |
      * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
12 |  |
      * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
13 |  |
      * language governing permissions and limitations under the License.
14 |  |
      *
15 |  |
      * When distributing the software, include this License Header Notice in each
16 |  |
      * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
17 |  |
      * Sun designates this particular file as subject to the "Classpath" exception
18 |  |
      * as provided by Sun in the GPL Version 2 section of the License file that
19 |  |
      * accompanied this code.  If applicable, add the following below the License
20 |  |
      * Header, with the fields enclosed by brackets [] replaced by your own
21 |  |
      * identifying information: "Portions Copyrighted [year]
22 |  |
      * [name of copyright owner]"
23 |  |
      *
24 |  |
      * Contributor(s):
25 |  |
      *
26 |  |
      * If you wish your version of this file to be governed by only the CDDL or
27 |  |
      * only the GPL Version 2, indicate your decision by adding "[Contributor]
28 |  |
      * elects to include this software in this distribution under the [CDDL or GPL
29 |  |
      * Version 2] license."  If you don't indicate a single choice of license, a
30 |  |
      * recipient has the option to distribute your version of this file under
31 |  |
      * either the CDDL, the GPL Version 2 or to extend the choice of license to
32 |  |
      * its licensees as provided above.  However, if you add GPL Version 2 code
33 |  |
      * and therefore, elected the GPL Version 2 license, then the option applies
34 |  |
      * only if the new code is made subject to such option by the copyright
35 |  |
      * holder.
36 |  |
      *
37 |  |
      */
38 |  |
39 |  |
     package com.sun.grizzly;
40 |  |
41 |  |
     import java.nio.ByteBuffer;
42 |  |
43 |  |
     /**
44 |  |
      * An interface that knows how to parse bytes into a protocol data unit.
45 |  |
      *
46 |  |
      * @author Charlie Hunt
47 |  |
      */
48 |  |
     public interface ProtocolParser<T> {
49 |  |
50 |  |
         /**
51 |  |
          * Is this ProtocolParser expecting more data ?
52 |  |
          *
53 |  |
          * This method is typically called after a call to
54 |  |
          * {@link ProtocolParser#hasNextMessage()} to determine if the
55 |  |
          * {@link ByteBuffer} which has been parsed contains a partial message
56 |  |
          *
57 |  |
          * @return - <tt>true</tt> if more bytes are needed to construct a
58 |  |
          *           message;  <tt>false</tt>, if no
59 |  |
          *           additional bytes remain to be parsed into a protocol data unit.
60 |  |
          *                  Note that if no partial message exists, this method should
61 |  |
          *                 return false.
62 |  |
          */
63 |  |
         public boolean isExpectingMoreData();
64 |  |
65 |  |
         /**
66 |  |
          * Are there more bytes to be parsed in the {@link ByteBuffer} given
67 |  |
          * to this ProtocolParser's {@link ProtocolParser#startBuffer()} ?
68 |  |
          *
69 |  |
          * This method is typically called after processing the protocol message,
70 |  |
          * to determine if the {@link ByteBuffer} has more bytes which
71 |  |
          * need to parsed into a next message.
72 |  |
          *
73 |  |
          * @return <tt>true</tt> if there are more bytes to be parsed.
74 |  |
          *         Otherwise <tt>false</tt>.
75 |  |
          */
76 |  |
         public boolean hasMoreBytesToParse();
77 |  |
78 |  |
79 |  |
         /**
80 |  |
          * Get the next complete message from the buffer, which can then be
81 |  |
          * processed by the next filter in the protocol chain. Because not all
82 |  |
          * filters will understand protocol messages, this method should also
83 |  |
          * set the position and limit of the buffer at the start and end
84 |  |
          * boundaries of the message. Filters in the protocol chain can
85 |  |
          * retrieve this message via context.getAttribute(MESSAGE)
86 |  |
          *
87 |  |
          * @return The next message in the buffer. If there isn't such a message,
88 |  |
          *        return <tt>null</tt>.
89 |  |
          *
90 |  |
          */
91 |  |
         public T getNextMessage();
92 |  |
93 |  |
         /**
94 |  |
          * Indicates whether the buffer has a complete message that can be
95 |  |
          * returned from {@link ProtocolParser#getNextMessage()}. Smart
96 |  |
          * implementations of this will set up all the information so that an
97 |  |
          * actual call to {@link ProtocolParser#getNextMessage()} doesn't need to
98 |  |
          * re-parse the data.
99 |  |
          */
100 |  |
         public boolean hasNextMessage();
101 |  |
102 |  |
         /**
103 |  |
          * Set the buffer to be parsed. This method should store the buffer and
104 |  |
          * its state so that subsequent calls to
105 |  |
          * {@link ProtocolParser#getNextMessage()} will return distinct messages,
106 |  |
          * and the buffer can be restored after parsing when the
107 |  |
          * {@link ProtocolParser#releaseBuffer()} method is called.
108 |  |
          */
109 |  |
         public void startBuffer(ByteBuffer bb);
110 |  |
111 |  |
         /**
112 |  |
          * No more parsing will be done on the buffer passed to
113 |  |
          * {@link ProtocolParser#startBuffer()}.
114 |  |
          * Set up the buffer so that its position is the first byte that was
115 |  |
          * not part of a full message, and its limit is the original limit of
116 |  |
          * the buffer.
117 |  |
          *
118 |  |
          * @return -- true if the parser has saved some state (e.g. information
119 |  |
          * data in the buffer that hasn't been returned in a full message);
120 |  |
          * otherwise false. If this method returns true, the framework will
121 |  |
          * make sure that the same parser is used to process the buffer after
122 |  |
          * more data has been read.
123 |  |
          */
124 |  |
         public boolean releaseBuffer();
125 |  |
126 |  |
         /**
127 |  |
          * Used to associate a particular parser with a connection
128 |  |
          */
129 |  |
         public static String PARSER = "ProtocolParser";
130 |  |
131 |  |
         /**
132 |  |
          * Holds the message returned from <code>getNextMessage</code> for
133 |  |
          * use by downstream filters
134 |  |
          */
135 |  |
         public static String MESSAGE = "ProtocolMessage";
136 |  |
     }
137 |  |