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

Classes in this File | Line Coverage | Branch Coverage | Complexity
ConnectorHandler |
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 |  |
     package com.sun.grizzly;
39 |  |
40 |  |
     import java.io.Closeable;
41 |  |
     import java.io.IOException;
42 |  |
     import java.net.SocketAddress;
43 |  |
     import java.nio.ByteBuffer;
44 |  |
     import java.nio.channels.SelectableChannel;
45 |  |
     import java.nio.channels.SelectionKey;
46 |  |
47 |  |
     /**
48 |  |
      * Client side interface used to implement non blocking client operation.
49 |  |
      * Implementation of this class must make sure the following methods are
50 |  |
      * invoked in that order:
51 |  |
      *
52 |  |
      * (1) connect()
53 |  |
      * (2) read() or write().
54 |  |
      *
55 |  |
      *
56 |  |
      * @param E a {@link SelectorHandler}
57 |  |
      * @param P a {@link CallbackHandler}
58 |  |
      * @author Jeanfrancois Arcand
59 |  |
      */
60 |  |
     public interface ConnectorHandler<E extends SelectorHandler, P extends CallbackHandler> extends Handler, Closeable {
61 |  |
62 |  |
63 |  |
          /**
64 |  |
          * A token decribing the protocol supported by an implementation of this
65 |  |
          * interface
66 |  |
          * @return <code>Controller.Protocol</code>
67 |  |
           */
68 |  |
         public Controller.Protocol protocol();
69 |  |
70 |  |
71 |  |
         /**
72 |  |
          * Connect to hostname:port. When an aysnchronous event happens (e.g
73 |  |
          * OP_READ or OP_WRITE), the {@link Controller} will invoke
74 |  |
          * the CallBackHandler.
75 |  |
          * @param remoteAddress remote address to connect
76 |  |
          * @param callbackHandler the handler invoked by the Controller when
77 |  |
          *        an non blocking operation is ready to be handled.
78 |  |
          * @param e {@link SelectorHandler}
79 |  |
          * @throws java.io.IOException
80 |  |
          */
81 |  |
         public void connect(SocketAddress remoteAddress,
82 |  |
                             P callbackHandler,
83 |  |
                             E e) throws IOException;
84 |  |
85 |  |
86 |  |
         /**
87 |  |
          * Connect to hostname:port. When an aysnchronous event happens (e.g
88 |  |
          * OP_READ or OP_WRITE), the {@link Controller} will invoke
89 |  |
          * the CallBackHandler.
90 |  |
          * @param remoteAddress remote address to connect
91 |  |
          * @param callbackHandler the handler invoked by the Controller when
92 |  |
          *        an non blocking operation is ready to be handled.
93 |  |
          * @throws java.io.IOException
94 |  |
          */
95 |  |
         public void connect(SocketAddress remoteAddress,
96 |  |
                             P callbackHandler) throws IOException;
97 |  |
98 |  |
99 |  |
         /**
100 |  |
          * Connect to hostname:port. Internally an instance of Controller and
101 |  |
          * its default SelectorHandler will be created everytime this method is
102 |  |
          * called. This method should be used only and only if no external
103 |  |
          * Controller has been initialized.
104 |  |
          * @param remoteAddress remote address to connect
105 |  |
          * @throws java.io.IOException
106 |  |
          */
107 |  |
         public void connect(SocketAddress remoteAddress)
108 |  |
             throws IOException;
109 |  |
110 |  |
111 |  |
         /**
112 |  |
          * Connect to hostname:port. When an aysnchronous event happens (e.g
113 |  |
          * OP_READ or OP_WRITE), the {@link Controller} will invoke
114 |  |
          * the CallBackHandler.
115 |  |
          * @param remoteAddress remote address to connect
116 |  |
          * @param localAddress local address to bind
117 |  |
          * @param callbackHandler the handler invoked by the Controller when
118 |  |
          *        an non blocking operation is ready to be handled.
119 |  |
          * @param e {@link SelectorHandler}
120 |  |
          * @throws java.io.IOException
121 |  |
          */
122 |  |
         public void connect(SocketAddress remoteAddress, SocketAddress localAddress,
123 |  |
                             P callbackHandler,
124 |  |
                             E e) throws IOException;
125 |  |
126 |  |
127 |  |
         /**
128 |  |
          * Connect to hostname:port. When an aysnchronous event happens (e.g
129 |  |
          * OP_READ or OP_WRITE), the {@link Controller} will invoke
130 |  |
          * the CallBackHandler.
131 |  |
          * @param remoteAddress remote address to connect
132 |  |
          * @param localAddress local address to bind
133 |  |
          * @param callbackHandler the handler invoked by the Controller when
134 |  |
          *        an non blocking operation is ready to be handled.
135 |  |
          * @throws java.io.IOException
136 |  |
          */
137 |  |
         public void connect(SocketAddress remoteAddress, SocketAddress localAddress,
138 |  |
                             P callbackHandler) throws IOException;
139 |  |
140 |  |
141 |  |
         /**
142 |  |
          * Connect to hostname:port. Internally an instance of Controller and
143 |  |
          * its default SelectorHandler will be created everytime this method is
144 |  |
          * called. This method should be used only and only if no external
145 |  |
          * Controller has been initialized.
146 |  |
          * @param remoteAddress remote address to connect
147 |  |
          * @param localAddress local address to bind
148 |  |
          * @throws java.io.IOException
149 |  |
          */
150 |  |
         public void connect(SocketAddress remoteAddress, SocketAddress localAddress)
151 |  |
             throws IOException;
152 |  |
153 |  |
154 |  |
         /**
155 |  |
          * Read bytes. If blocking is set to <tt>true</tt>, a pool of temporary
156 |  |
          * {@link Selector} will be used to read bytes.
157 |  |
          * @param byteBuffer The byteBuffer to store bytes.
158 |  |
          * @param blocking <tt>true</tt> if a a pool of temporary Selector
159 |  |
          *        is required to handle a blocking read.
160 |  |
          * @return number of bytes read
161 |  |
          * @throws java.io.IOException
162 |  |
          */
163 |  |
         public long read(ByteBuffer byteBuffer, boolean blocking) throws IOException;
164 |  |
165 |  |
166 |  |
         /**
167 |  |
          * Writes bytes. If blocking is set to <tt>true</tt>, a pool of temporary
168 |  |
          * {@link Selector} will be used to writes bytes.
169 |  |
          * @param byteBuffer The byteBuffer to write.
170 |  |
          * @param blocking <tt>true</tt> if a a pool of temporary Selector
171 |  |
          *        is required to handle a blocking write.
172 |  |
          * @return number of bytes written
173 |  |
          * @throws java.io.IOException
174 |  |
          */
175 |  |
         public long write(ByteBuffer byteBuffer, boolean blocking) throws IOException;
176 |  |
177 |  |
178 |  |
         /**
179 |  |
          * Close the underlying connection.
180 |  |
          * @throws java.io.IOException
181 |  |
          */
182 |  |
         public void close() throws IOException;
183 |  |
184 |  |
185 |  |
         /**
186 |  |
          * Decide how the OP_CONNECT final steps are handled.
187 |  |
          * @param key {@link SelectionKey}
188 |  |
          */
189 |  |
         public void finishConnect(SelectionKey key)  throws IOException;
190 |  |
191 |  |
192 |  |
         /**
193 |  |
          * Set the {@link Controller} associated with this instance.
194 |  |
          * @param controller {@link Controller}
195 |  |
          */
196 |  |
         public void setController(Controller controller);
197 |  |
198 |  |
199 |  |
         /**
200 |  |
          * Return the {@link Controller}
201 |  |
          * @return
202 |  |
          */
203 |  |
         public Controller getController();
204 |  |
205 |  |
206 |  |
         /**
207 |  |
          * Method returns {@link SelectorHandler}, which manages this
208 |  |
          * {@link ConnectorHandler}
209 |  |
          * @return {@link SelectorHandler}
210 |  |
          */
211 |  |
         public E getSelectorHandler();
212 |  |
213 |  |
         /**
214 |  |
          * Method returns {@link ConnectorHandler}'s underlying channel
215 |  |
          * @return channel
216 |  |
          */
217 |  |
         public SelectableChannel getUnderlyingChannel();
218 |  |
219 |  |
         /**
220 |  |
          * Returns {@link ConnectorHandler}'s callback handler instance,
221 |  |
          * which is used to process occuring events
222 |  |
          *
223 |  |
          * @return callback handler
224 |  |
          */
225 |  |
         public P getCallbackHandler();
226 |  |
227 |  |
         /**
228 |  |
          * Sets {@link ConnectorHandler}'s callback handler instance,
229 |  |
          * which is used to process occuring events
230 |  |
          *
231 |  |
          * @param callbackHandler handler
232 |  |
          */
233 |  |
         public void setCallbackHandler(P callbackHandler);
234 |  |
     }