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

Classes in this File | Line Coverage | Branch Coverage | Complexity
ProtocolChain |
N/A | N/A
N/A | N/A
| 1.0;1

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 |  |
     /**
42 |  |
      * <p>
43 |  |
      * This class implement the "Chain of Responsibility" pattern (for more info,
44 |  |
      * take a look at the classic "Gang of Four" design patterns book). Towards
45 |  |
      * that end, the Chain API models a computation as a series of "protocol filter"
46 |  |
      * that can be combined into a "protocol chain".
47 |  |
      * </p><p>
48 |  |
      * The API for ProtocolFilter consists of a two methods (execute() and
49 |  |
      * postExecute) which is passed a "protocol context" parameter containing the
50 |  |
      * dynamic state of the computation, and whose return value is a boolean
51 |  |
      * that determines whether or not processing for the current chain has been
52 |  |
      * completed (false), or whether processing should be delegated to the next
53 |  |
      * ProtocolFilter in the chain (true). The owning ProtocolChain  must call the
54 |  |
      * postExectute() method of each ProtocolFilter in a ProtocolChain in reverse
55 |  |
      * order of the invocation of their execute() methods.
56 |  |
      * </p><p>
57 |  |
      * The following picture describe how it ProtocolFilter(s)
58 |  |
      * </p><p><pre><code>
59 |  |
      * -----------------------------------------------------------------------------
60 |  |
      * - ProtocolFilter1.execute() --> ProtocolFilter2.execute() -------|          -
61 |  |
      * -                                                                |          -
62 |  |
      * -                                                                |          -
63 |  |
      * -                                                                |          -
64 |  |
      * - ProtocolFilter1.postExecute() <-- ProtocolFilter2.postExecute()|          -
65 |  |
      * -----------------------------------------------------------------------------
66 |  |
      * </code></pre></p><p>
67 |  |
      * The "context" abstraction is designed to isolate ProtocolFilter
68 |  |
      * implementations from the environment in which they are run
69 |  |
      * (such as a ProtocolFilter that can be used in either IIOP or HTTP parsing,
70 |  |
      * without being tied directly to the API contracts of either of these
71 |  |
      * environments). For ProtocolFilter that need to allocate resources prior to
72 |  |
      * delegation, and then release them upon return (even if a delegated-to
73 |  |
      * ProtocolFilter throws an exception), the "postExecute" method can be used
74 |  |
      * for cleanup.
75 |  |
      * </p>
76 |  |
      * @author Jeanfrancois Arcand
77 |  |
      */
78 |  |
     public interface ProtocolChain{
79 |  |
         /**
80 |  |
          * {@link ProtocolChain} result attribute name.
81 |  |
          */
82 |  |
         public static final String PROTOCOL_CHAIN_POST_INSTRUCTION =
83 |  |
                 "ChainPostInstruction";
84 |  |
85 |  |
         /**
86 |  |
          * Add a {@link ProtocolFilter} to the list. {@link ProtocolFilter}
87 |  |
          * will be invoked in the order they have been added.
88 |  |
          * @param protocolFilter {@link ProtocolFilter}
89 |  |
          * @return {@link ProtocolFilter} added successfully (yes/no) ?
90 |  |
          */
91 |  |
         public boolean addFilter(ProtocolFilter protocolFilter);
92 |  |
93 |  |
94 |  |
         /**
95 |  |
          * Remove the {@link ProtocolFilter} from this chain.
96 |  |
          * @param theFilter {@link ProtocolFilter}
97 |  |
          * @return {@link ProtocolFilter} removed successfully (yes/no) ?
98 |  |
          */
99 |  |
         public boolean removeFilter(ProtocolFilter theFilter);
100 |  |
101 |  |
102 |  |
         /**
103 |  |
          * Insert a {@link ProtocolFilter} to the list at position 'pos'.
104 |  |
          * @param pos The insertion position
105 |  |
          * @param protocolFilter {@link ProtocolFilter}
106 |  |
          */
107 |  |
         public void addFilter(int pos, ProtocolFilter protocolFilter);
108 |  |
109 |  |
110 |  |
         /**
111 |  |
          * Execute using the {@link Context} instance.
112 |  |
          * @param context <code>Context<code>
113 |  |
          * @throws java.lang.Exception
114 |  |
          */
115 |  |
         public void execute(Context context) throws Exception;
116 |  |
117 |  |
118 |  |
     }