| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SelectorHandler |
|
| 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 com.sun.grizzly.async.AsyncQueueReader; | |
| 41 | import com.sun.grizzly.async.AsyncQueueWriter; | |
| 42 | import com.sun.grizzly.util.AttributeHolder; | |
| 43 | import com.sun.grizzly.util.Copyable; | |
| 44 | import com.sun.grizzly.util.State; | |
| 45 | import com.sun.grizzly.util.SupportStateHolder; | |
| 46 | import java.io.IOException; | |
| 47 | import java.nio.channels.SelectableChannel; | |
| 48 | import java.nio.channels.SelectionKey; | |
| 49 | import java.nio.channels.Selector; | |
| 50 | import java.util.Set; | |
| 51 | ||
| 52 | /** | |
| 53 | * A SelectorHandler handles all java.nio.channels.Selector operations. | |
| 54 | * One or more instance of a Selector are handled by SelectorHandler. | |
| 55 | * The logic for processing of SelectionKey interest (OP_ACCEPT,OP_READ, etc.) | |
| 56 | * is usually defined using an instance of SelectorHandler. | |
| 57 | * | |
| 58 | * @author Jeanfrancois Arcand | |
| 59 | */ | |
| 60 | public interface SelectorHandler extends Handler, Copyable, | |
| 61 | AttributeHolder, SupportStateHolder<State> { | |
| 62 | ||
| 63 | /** | |
| 64 | * A token decribing the protocol supported by an implementation of this | |
| 65 | * interface | |
| 66 | * @return SelectorHandler supported protocol | |
| 67 | */ | |
| 68 | public Controller.Protocol protocol(); | |
| 69 | ||
| 70 | ||
| 71 | /** | |
| 72 | * Gets the underlying selector. | |
| 73 | * @return underlying {@link Selector} | |
| 74 | */ | |
| 75 | public Selector getSelector(); | |
| 76 | ||
| 77 | ||
| 78 | /** | |
| 79 | * Sets the underlying {@link Selector} | |
| 80 | * @param selector underlying {@link Selector} | |
| 81 | */ | |
| 82 | public void setSelector(Selector selector); | |
| 83 | ||
| 84 | ||
| 85 | /** | |
| 86 | * The SelectionKey that has been registered. | |
| 87 | * @return{@link Set} of {@link SelectionKey} | |
| 88 | */ | |
| 89 | public Set<SelectionKey> keys(); | |
| 90 | ||
| 91 | ||
| 92 | /** | |
| 93 | * Is the underlying Selector open. | |
| 94 | * @return true / false | |
| 95 | */ | |
| 96 | public boolean isOpen(); | |
| 97 | ||
| 98 | ||
| 99 | /** | |
| 100 | * Pause this {@link SelectorHandler} | |
| 101 | */ | |
| 102 | public void pause(); | |
| 103 | ||
| 104 | ||
| 105 | /** | |
| 106 | * Resume this {@link SelectorHandler} | |
| 107 | */ | |
| 108 | public void resume(); | |
| 109 | ||
| 110 | ||
| 111 | /** | |
| 112 | * Shutdown this instance. | |
| 113 | */ | |
| 114 | public void shutdown(); | |
| 115 | ||
| 116 | ||
| 117 | /** | |
| 118 | * This method is garantee to always be called before operation | |
| 119 | * Selector.select(). | |
| 120 | * @param controllerCtx {@link Context} | |
| 121 | * @throws java.io.IOException | |
| 122 | */ | |
| 123 | public void preSelect(Context controllerCtx) throws IOException; | |
| 124 | ||
| 125 | ||
| 126 | /** | |
| 127 | * Invoke the Selector.select() method. | |
| 128 | * @param controllerCtx | |
| 129 | * @return{@link Set} of {@link SelectionKey} | |
| 130 | * @throws java.io.IOException | |
| 131 | */ | |
| 132 | public Set<SelectionKey> select(Context controllerCtx) throws IOException; | |
| 133 | ||
| 134 | ||
| 135 | /** | |
| 136 | * This method is garantee to always be called after operation | |
| 137 | * Selector.select(). | |
| 138 | * @param controllerCtx {@link Context} | |
| 139 | * @throws java.io.IOException | |
| 140 | */ | |
| 141 | public void postSelect(Context controllerCtx) throws IOException; | |
| 142 | ||
| 143 | ||
| 144 | /** | |
| 145 | * Register the {@link SelectableChannel} on the {@link Selector}. | |
| 146 | * @param key | |
| 147 | * @param ops interested operations | |
| 148 | */ | |
| 149 | public void register(SelectableChannel channel,int ops); | |
| 150 | ||
| 151 | /** | |
| 152 | * Register the SelectionKey on the Selector. | |
| 153 | * @param key | |
| 154 | * @param ops interested operations | |
| 155 | */ | |
| 156 | public void register(SelectionKey key,int ops); | |
| 157 | ||
| 158 | ||
| 159 | /** | |
| 160 | * Accepts connection, without registering it for reading or writing | |
| 161 | * @param key | |
| 162 | * @return accepted {@link SelectableChannel} | |
| 163 | * @throws java.io.IOException | |
| 164 | */ | |
| 165 | public SelectableChannel acceptWithoutRegistration(SelectionKey key) | |
| 166 | throws IOException; | |
| 167 | ||
| 168 | ||
| 169 | /** | |
| 170 | * Handle OP_ACCEPT. | |
| 171 | * @param key {@link SelectionKey} | |
| 172 | * @param controllerCtx {@link Context} | |
| 173 | * @return true if and only if the ProtocolChain must be invoked after | |
| 174 | * executing this method. | |
| 175 | * @throws java.io.IOException | |
| 176 | */ | |
| 177 | public boolean onAcceptInterest(SelectionKey key,Context controllerCtx) | |
| 178 | throws IOException; | |
| 179 | ||
| 180 | /** | |
| 181 | * Handle OP_READ. | |
| 182 | * @param key {@link SelectionKey} | |
| 183 | * @param controllerCtx {@link Context} | |
| 184 | * @return true if and only if the ProtocolChain must be invoked after | |
| 185 | * executing this method. | |
| 186 | * @throws java.io.IOException | |
| 187 | */ | |
| 188 | public boolean onReadInterest(SelectionKey key,Context controllerCtx) | |
| 189 | throws IOException; | |
| 190 | ||
| 191 | ||
| 192 | /** | |
| 193 | * Handle OP_WRITE. | |
| 194 | * @param key {@link SelectionKey} | |
| 195 | * @param controllerCtx {@link Context} | |
| 196 | * @return true if and only if the ProtocolChain must be invoked after | |
| 197 | * executing this method. | |
| 198 | * @throws java.io.IOException | |
| 199 | */ | |
| 200 | public boolean onWriteInterest(SelectionKey key,Context controllerCtx) | |
| 201 | throws IOException; | |
| 202 | ||
| 203 | ||
| 204 | /** | |
| 205 | * Handle OP_CONNECT. | |
| 206 | * @param key {@link SelectionKey} | |
| 207 | * @param controllerCtx {@link Context} | |
| 208 | * @return true if and only if the ProtocolChain must be invoked after | |
| 209 | * executing this method. | |
| 210 | * @throws java.io.IOException | |
| 211 | */ | |
| 212 | public boolean onConnectInterest(SelectionKey key,Context controllerCtx) | |
| 213 | throws IOException; | |
| 214 | ||
| 215 | ||
| 216 | /** | |
| 217 | * Return an instance of the {@link ConnectorHandler} | |
| 218 | * @return {@link ConnectorHandler} | |
| 219 | */ | |
| 220 | public ConnectorHandler acquireConnectorHandler(); | |
| 221 | ||
| 222 | ||
| 223 | /** | |
| 224 | * Release a ConnectorHandler. | |
| 225 | * @param connectorHandler {@link ConnectorHandler} | |
| 226 | */ | |
| 227 | public void releaseConnectorHandler(ConnectorHandler connectorHandler); | |
| 228 | ||
| 229 | ||
| 230 | /** | |
| 231 | * Configure the channel operations. | |
| 232 | * @param channel {@link SelectableChannel} to configure | |
| 233 | * @throws java.io.IOException on possible configuration related error | |
| 234 | */ | |
| 235 | public void configureChannel(SelectableChannel channel) throws IOException; | |
| 236 | ||
| 237 | ||
| 238 | /** | |
| 239 | * Returns {@link AsyncQueueReader} associated with this | |
| 240 | * {@link SelectorHandler}. Method will return null, if this | |
| 241 | * {@link SelectorHandler} is not running. | |
| 242 | * | |
| 243 | * @return {@link AsyncQueueReader} | |
| 244 | */ | |
| 245 | public AsyncQueueReader getAsyncQueueReader(); | |
| 246 | ||
| 247 | ||
| 248 | /** | |
| 249 | * Returns {@link AsyncQueueWriter} associated with this | |
| 250 | * {@link SelectorHandler}. Method will return null, if this | |
| 251 | * {@link SelectorHandler} is not running. | |
| 252 | * | |
| 253 | * @return {@link AsyncQueueWriter} | |
| 254 | */ | |
| 255 | public AsyncQueueWriter getAsyncQueueWriter(); | |
| 256 | ||
| 257 | ||
| 258 | /** | |
| 259 | * Return the {@link Pipeline} used to execute this | |
| 260 | * {@link SelectorHandler}'s {@link SelectionKey} ops | |
| 261 | * @return The pipeline to use, or null if the {@link Controller}'s | |
| 262 | * {@link Pipeline} should be used. | |
| 263 | */ | |
| 264 | public Pipeline pipeline(); | |
| 265 | ||
| 266 | ||
| 267 | /** | |
| 268 | * Set the {@link Pipeline} used to execute this | |
| 269 | * {@link SelectorHandler}'s {@link SelectionKey} ops | |
| 270 | * @param The pipeline to use, or null if the {@link Controller}'s | |
| 271 | * {@link Pipeline} should be used. | |
| 272 | */ | |
| 273 | public void setPipeline(Pipeline pipeline); | |
| 274 | ||
| 275 | ||
| 276 | /** | |
| 277 | * Get the preffered SelectionKeyHandler implementation for this SelectorHandler. | |
| 278 | */ | |
| 279 | public Class<? extends SelectionKeyHandler> getPreferredSelectionKeyHandler(); | |
| 280 | ||
| 281 | ||
| 282 | /** | |
| 283 | * Get the SelectionKeyHandler associated with this SelectorHandler. | |
| 284 | */ | |
| 285 | public SelectionKeyHandler getSelectionKeyHandler(); | |
| 286 | ||
| 287 | ||
| 288 | /** | |
| 289 | * Set SelectionKeyHandler associated with this SelectorHandler. | |
| 290 | */ | |
| 291 | public void setSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler); | |
| 292 | ||
| 293 | ||
| 294 | /** | |
| 295 | * Set the {@link ProtocolChainInstanceHandler} to use for | |
| 296 | * creating instance of {@link ProtocolChain}. | |
| 297 | */ | |
| 298 | public void setProtocolChainInstanceHandler( | |
| 299 | ProtocolChainInstanceHandler protocolChainInstanceHandler); | |
| 300 | ||
| 301 | ||
| 302 | /** | |
| 303 | * Return the {@link ProtocolChainInstanceHandler} | |
| 304 | */ | |
| 305 | public ProtocolChainInstanceHandler getProtocolChainInstanceHandler(); | |
| 306 | ||
| 307 | /** | |
| 308 | * Closes {@link SelectableChannel} | |
| 309 | */ | |
| 310 | public void closeChannel(SelectableChannel channel); | |
| 311 | } |