Coverage Report - com.sun.grizzly.Context
 
Classes in this File Line Coverage Branch Coverage Complexity
Context
62 %
83/134
53 %
23/43
0
Context$1
100 %
1/1
N/A
0
Context$AsyncQueueReadableContextWrapper
0 %
0/7
N/A
0
Context$AsyncQueueWritableContextWrapper
29 %
5/17
N/A
0
Context$AttributeScope
100 %
5/5
N/A
0
Context$KeyRegistrationState
100 %
4/4
N/A
0
Context$OpType
100 %
5/5
N/A
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 com.sun.grizzly.async.AsyncQueueDataProcessor;
 42  
 import com.sun.grizzly.async.AsyncQueueReadable;
 43  
 import com.sun.grizzly.async.AsyncQueueReader;
 44  
 import com.sun.grizzly.async.AsyncQueueWritable;
 45  
 import com.sun.grizzly.async.AsyncQueueWriter;
 46  
 import com.sun.grizzly.async.AsyncReadCallbackHandler;
 47  
 import com.sun.grizzly.async.AsyncReadCondition;
 48  
 import com.sun.grizzly.async.AsyncWriteCallbackHandler;
 49  
 import com.sun.grizzly.util.AttributeHolder;
 50  
 import com.sun.grizzly.util.Copyable;
 51  
 import com.sun.grizzly.util.SelectionKeyAttachment;
 52  
 import java.io.IOException;
 53  
 import java.net.SocketAddress;
 54  
 import java.nio.ByteBuffer;
 55  
 import java.nio.channels.SelectionKey;
 56  
 import java.util.HashMap;
 57  
 import java.util.Map;
 58  
 import java.util.logging.Level;
 59  
 
 60  
 /**
 61  
  * This Object is used to share information between the Grizzly Framework
 62  
  * classes and {@link ProtocolFilter} implementation.
 63  
  *
 64  
  * @author Jeanfrancois Arcand
 65  
  */
 66  219806
 public class Context implements AttributeHolder, Copyable {
 67  
 
 68  
 
 69  6
     public enum AttributeScope {
 70  1
         REQUEST,
 71  1
         CONNECTION,
 72  1
         SELECTOR,
 73  1
         CONTROLLER
 74  
     }
 75  
     
 76  
     /**
 77  
      * A {@link SelectionKey}'s registration state.
 78  
      */
 79  4
     public enum KeyRegistrationState {
 80  
         /** A cancelled {@link SelectionKey} registration state. */
 81  1
         CANCEL,
 82  
         /** A registered {@link SelectionKey} registration state. */
 83  1
         REGISTER,
 84  
         /** A {@link SelectionKey} with no registration state. */
 85  1
         NONE }
 86  
     
 87  
     
 88  
     /**
 89  
      * The list of possible {@link SelectionKey}.OP_XXXX.
 90  
      */
 91  7
     public enum OpType { OP_READ,
 92  1
         OP_WRITE,
 93  1
         OP_CONNECT,
 94  1
         OP_READ_WRITE,
 95  1
         OP_ACCEPT
 96  
     }
 97  
     
 98  
     
 99  
     /**
 100  
      * The current {@link SelectionKey} interest ops this Context is processing.
 101  
      */
 102  
     private OpType currentOpType;
 103  
     
 104  
     
 105  
     /**
 106  
      * The {@link ProtocolChain} used to execute this {@link Context}
 107  
      */
 108  
     private ProtocolChain protocolChain;
 109  
     
 110  
     
 111  
     /**
 112  
      * Constant 'throwable' String
 113  
      */
 114  
     public final static String THROWABLE ="throwable";
 115  
     
 116  
     
 117  
     /**
 118  
      * Used to share object between {@link ProtocolFilter}.
 119  
      * WARNING: Attributes which are added are never removed automatically
 120  
      * The removal operation must be done explicitly inside a  {@link ProtocolFilter}.
 121  
      */
 122  261
     private Map<String,Object> attributes = null;
 123  
     
 124  
     
 125  
     /**
 126  
      * The current connection (@link SelectionKey}.
 127  
      */
 128  
     private SelectionKey key;
 129  
     
 130  
     
 131  
     /**
 132  
      * The {@link SelectorHandler} associated with this Context.
 133  
      */
 134  
     private SelectorHandler selectorHandler;
 135  
 
 136  
     
 137  
     /**
 138  
      * The {@link Controller} associated with this Context.
 139  
      */
 140  
     private Controller controller;
 141  
     
 142  
     
 143  
     /**
 144  
      * The state's of the key registration.
 145  
      */
 146  261
     private KeyRegistrationState keyRegistrationState
 147  
             = KeyRegistrationState.REGISTER;
 148  
     
 149  
     
 150  
     /**
 151  
      * The current {@linl Pipeline} that execute this object.
 152  
      */
 153  
     private Pipeline pipeline;
 154  
     
 155  
     
 156  
     /**
 157  
      * An optional {@link IOEvent} that can be invoked
 158  
      * before the {@link ProtocolChain} is invoked.
 159  
      */
 160  
     private IOEvent<Context> ioEvent;
 161  
     
 162  
     
 163  
     /**
 164  
      * {@link AsyncQueueReader}
 165  
      */
 166  
     private AsyncQueueReader asyncQueueReader;
 167  
 
 168  
     /**
 169  
      * {@link AsyncQueueWriter}
 170  
      */
 171  
     private AsyncQueueWriter asyncQueueWriter;
 172  
     
 173  
     /**
 174  
      * {@link AsyncQueueReadable}
 175  
      */
 176  
     private AsyncQueueReadable asyncQueueReadable;
 177  
 
 178  
     /**
 179  
      * {@link AsyncQueueWritable}
 180  
      */
 181  
     private AsyncQueueWritable asyncQueueWritable;
 182  
     
 183  
     /**
 184  
      * Constructor
 185  
      */
 186  261
     public Context() {
 187  261
     }
 188  
     
 189  
     
 190  
     public void copyTo(Copyable copy) {
 191  0
         Context copyContext = (Context) copy;
 192  0
         copyContext.currentOpType = currentOpType;
 193  0
         copyContext.protocolChain = protocolChain;
 194  0
         if (attributes != null) {
 195  0
             copyContext.attributes = new HashMap<String, Object>(attributes);
 196  
         }
 197  0
         copyContext.key = key;
 198  0
         copyContext.selectorHandler = selectorHandler;
 199  0
         copyContext.controller = controller;
 200  0
         copyContext.keyRegistrationState = keyRegistrationState;
 201  0
         copyContext.pipeline = pipeline;
 202  0
         copyContext.ioEvent = ioEvent;
 203  0
         copyContext.asyncQueueReader = asyncQueueReader;
 204  0
         copyContext.asyncQueueWriter = asyncQueueWriter;
 205  0
         copyContext.asyncQueueReadable = asyncQueueReadable;
 206  0
         copyContext.asyncQueueWritable = asyncQueueWritable;
 207  0
     }
 208  
 
 209  
     /**
 210  
      * Remove a key/value object.
 211  
      * @param key - name of an attribute
 212  
      * @return  attribute which has been removed
 213  
      */
 214  
     public Object removeAttribute(String key){
 215  249305
         if (attributes == null){
 216  7606
             return null;
 217  
         }
 218  241699
         return attributes.remove(key);
 219  
     }
 220  
     
 221  
     
 222  
     /**
 223  
      * Set a key/value object.
 224  
      * @param key - name of an attribute
 225  
      * @param value - value of named attribute
 226  
      */
 227  
     public void setAttribute(String key,Object value){
 228  67736
         if (attributes == null){
 229  112
             attributes = new HashMap<String,Object>();
 230  
         }
 231  67736
         attributes.put(key,value);
 232  67736
     }
 233  
     
 234  
     
 235  
     /**
 236  
      * Return an object based on a key.
 237  
      * @param key - name of an attribute
 238  
      * @return - attribute value for the <tt>key</tt>, null if <tt>key</tt>
 239  
      *           does not exist in <tt>attributes</tt>
 240  
      */
 241  
     public Object getAttribute(String key){
 242  67626
         if (attributes == null){
 243  68
             return null;
 244  
         }
 245  67558
         return attributes.get(key);
 246  
     }
 247  
     
 248  
     
 249  
     /**
 250  
      * Return {@link AttributeHolder}, which corresponds to the 
 251  
      * given {@link AttributeScope}>
 252  
      * 
 253  
      * @param scope - {@link AttributeScope}>
 254  
      * @return - {@link AttributeHolder} instance, which contains
 255  
      *           {@link AttributeScope}> attributes
 256  
      */
 257  
     public AttributeHolder getAttributeHolderByScope(AttributeScope scope){
 258  53471
         AttributeHolder holder = null;
 259  1
         switch(scope) {
 260  
             case REQUEST: 
 261  0
                 holder = this;
 262  0
                 break;
 263  
             case CONNECTION:
 264  53471
                 Object attachment = getSelectionKey().attachment();
 265  53471
                 if (attachment instanceof AttributeHolder) {
 266  53470
                     holder = (AttributeHolder) attachment;
 267  
                 }
 268  
                 break;
 269  
             case SELECTOR:
 270  0
                 holder = selectorHandler;
 271  0
                 break;
 272  
             case CONTROLLER:
 273  0
                 holder = controller;
 274  
                 break;
 275  
         }
 276  
         
 277  53471
         return holder;
 278  
     }
 279  
 
 280  
     
 281  
     /**
 282  
      * Set a {@link Map} of attribute name/value pairs.
 283  
      * Old {@link AttributeHolder} values will not be available.
 284  
      * Later changes of this {@link Map} will lead to changes to the current
 285  
      * {@link AttributeHolder}.
 286  
      * 
 287  
      * @param attributes - map of name/value pairs
 288  
      */
 289  
     public void setAttributes(Map<String, Object> attributes) {
 290  0
         this.attributes = attributes;
 291  0
     }
 292  
 
 293  
     
 294  
     /**
 295  
      * Return a {@link Map} of attribute name/value pairs.
 296  
      * Updates, performed on the returned {@link Map} will be reflected in
 297  
      * this {@link AttributeHolder}
 298  
      * 
 299  
      * @return - {@link Map} of attribute name/value pairs
 300  
      */
 301  
     public Map<String, Object> getAttributes() {
 302  0
         return attributes;
 303  
     }
 304  
 
 305  
     
 306  
     /**
 307  
      * Return the current {@link SelectionKey}.
 308  
      * @return - this Context's SelectionKey
 309  
      */
 310  
     public SelectionKey getSelectionKey() {
 311  676713
         return key;
 312  
     }
 313  
     
 314  
     
 315  
     /**
 316  
      * Set the connection {@link SelectionKey}.
 317  
      * @param key - set this Context's SelectionKey
 318  
      */
 319  
     public void setSelectionKey(SelectionKey key) {
 320  229765
         this.key = key;
 321  229765
     }
 322  
     
 323  
     
 324  
     /**
 325  
      * Return the current {@link Controller}.
 326  
      * @return - this Context's current {@link Controller}
 327  
      */
 328  
     public Controller getController() {
 329  303451
         return controller;
 330  
     }
 331  
     
 332  
     
 333  
     /**
 334  
      * Set the current {@link Controller}.
 335  
      * @param {@link Controller}
 336  
      */
 337  
     public void setController(Controller controller) {
 338  405998
         this.controller = controller;
 339  405998
     }
 340  
 
 341  
 
 342  
     /**
 343  
      * Recycle this instance. 
 344  
      */
 345  
     public void recycle(){        
 346  156189
         getProtocolChainInstanceHandler().offer(protocolChain);            
 347  156188
         key = null;
 348  156189
         keyRegistrationState = KeyRegistrationState.REGISTER;
 349  156188
         currentOpType = null;
 350  156189
         protocolChain = null;
 351  156189
         ioEvent = null;
 352  156189
         asyncQueueReader = null;
 353  156188
         asyncQueueWriter = null;
 354  156188
         if (attributes != null) {
 355  144942
             attributes.clear();
 356  
         }
 357  156189
     }
 358  
     
 359  
     
 360  
     /**
 361  
      * Return {@link SelectionKey}'s next registration state.
 362  
      * @return this Context's SelectionKey registration state
 363  
      */
 364  
     public KeyRegistrationState getKeyRegistrationState() {
 365  183142
         return keyRegistrationState;
 366  
     }
 367  
     
 368  
     
 369  
     /**
 370  
      * Set the {@link SelectionKey}'s next registration state
 371  
      * @param {@link keyRegistrationState} - set this Context's SelectionKey
 372  
      *        registration state
 373  
      */
 374  
     public void setKeyRegistrationState(KeyRegistrationState keyRegistrationState) {
 375  54050
         this.keyRegistrationState = keyRegistrationState;
 376  54050
     }
 377  
     
 378  
     
 379  
     /**
 380  
      * Return {@link ProtocolChain} executed by this instance.
 381  
      * @return {@link ProtocolChain} instance
 382  
      */
 383  
     public ProtocolChain getProtocolChain() {
 384  82631
         return protocolChain;
 385  
     }
 386  
     
 387  
     
 388  
     /**
 389  
      * Set the {@link ProtocolChain} used by this {@link Context}.
 390  
      * @param protocolChain instance of {@link ProtocolChain} to be used by the Context
 391  
      */
 392  
     public void setProtocolChain(ProtocolChain protocolChain) {
 393  73567
         this.protocolChain = protocolChain;
 394  73567
     }
 395  
     
 396  
     
 397  
     /**
 398  
      * Get the current {@link SelectionKey} interest ops this instance is executing.
 399  
      * @return OpType the currentOpType.
 400  
      */
 401  
     public OpType getCurrentOpType() {
 402  129202
         return currentOpType;
 403  
     }
 404  
     
 405  
     
 406  
     /**
 407  
      * Set the current OpType value.
 408  
      * @param currentOpType sets current operation type
 409  
      */
 410  
     public void setCurrentOpType(OpType currentOpType) {
 411  156186
         this.currentOpType = currentOpType;
 412  156186
     }
 413  
 
 414  
     
 415  
     /**
 416  
      * Configure the {@link #currentOpType} based on the 
 417  
      * {@link SelectionKey#readyOps()} values.
 418  
      * @param key
 419  
      */
 420  
     protected void configureOpType(SelectionKey key) {
 421  12
         int readyOps = key.readyOps();   
 422  12
         switch (readyOps){
 423  
             case SelectionKey.OP_CONNECT:
 424  0
                 currentOpType = OpType.OP_CONNECT;
 425  0
                 break;
 426  
             case SelectionKey.OP_READ:
 427  12
                 currentOpType = OpType.OP_READ;
 428  12
                 break; 
 429  
             case SelectionKey.OP_WRITE:
 430  0
                 currentOpType = OpType.OP_WRITE;
 431  0
                 break; 
 432  
             case (SelectionKey.OP_WRITE | SelectionKey.OP_READ):
 433  0
                 currentOpType = OpType.OP_READ_WRITE;
 434  0
                 break;  
 435  
              case (SelectionKey.OP_ACCEPT):
 436  0
                 currentOpType = OpType.OP_ACCEPT;
 437  0
                 break;       
 438  
             /**
 439  
              * Fallback to an upcoming OP_CONNECT ops. This happens
 440  
              * because the {@link SocketChannel#finishConnect()} has not yet
 441  
              * been invoked.
 442  
              * 
 443  
              */
 444  
             default:
 445  0
                 currentOpType = OpType.OP_CONNECT;
 446  
                 break;
 447  
                 
 448  
         } 
 449  12
     }
 450  
     
 451  
         
 452  
     
 453  
     /**
 454  
      * Execute this Context using the Controller's Pipeline
 455  
      * @throws {@link PipelineFullException}
 456  
      * @deprecated
 457  
      */
 458  
     public void execute() throws PipelineFullException {
 459  
         // If a IOEvent has been defined, invoke it first and
 460  
         // let its associated CallbackHandler decide if the ProtocolChain
 461  
         // be invoked or not.
 462  0
         Object attachment = SelectionKeyAttachment.getAttachment(key);
 463  0
         if (ioEvent != null && (attachment instanceof CallbackHandler)) {
 464  0
             CallbackHandlerContextTask task = CallbackHandlerContextTask.poll();
 465  0
             task.setCallBackHandler((CallbackHandler) attachment);
 466  0
             execute(task);
 467  0
         } else {
 468  0
             execute(ProtocolChainContextTask.poll());
 469  
         }
 470  0
     }
 471  
 
 472  
     
 473  
     /**
 474  
      * Execute this Context using the Controller's Pipeline
 475  
      * @param contextTask {@link ContextTask}, which will be 
 476  
      *                    executed by {@link Pipeline}
 477  
      * @throws {@link PipelineFullException}
 478  
      */
 479  
     public void execute(ContextTask contextTask) throws PipelineFullException {
 480  94669
         execute(contextTask, true);
 481  94669
     }
 482  
     
 483  
     
 484  
     /**
 485  
      * Execute this Context using either Controller's Pipeline or current thread
 486  
      * @param contextTask {@link ContextTask}, which will be 
 487  
      *                    executed by {@link Pipeline}
 488  
      * @param runInSeparateThread if true - {@link ContextTask} will
 489  
      *      be executed in separate thread, false - in current thread.
 490  
      * @throws {@link PipelineFullException}
 491  
      */
 492  
     @SuppressWarnings("unchecked")
 493  
     public void execute(ContextTask contextTask, boolean runInSeparateThread) throws PipelineFullException {       
 494  156189
         if (protocolChain == null){
 495  
             ProtocolChainInstanceHandler 
 496  82622
                     pciHandler = getProtocolChainInstanceHandler();
 497  82622
             protocolChain = pciHandler.poll();
 498  
         }
 499  
         
 500  156189
         if (contextTask != null) {
 501  156189
             contextTask.setContext(this);
 502  156189
             if (runInSeparateThread) {
 503  156189
                 getPipeline().execute(contextTask);
 504  
             } else {
 505  
                 try {
 506  0
                     contextTask.call();
 507  0
                 } catch(Exception e) {
 508  0
                     Controller.logger().log(Level.SEVERE,
 509  
                             "Unexpected exception occured, when executing task: " + 
 510  
                             contextTask, e);
 511  0
                 }
 512  
             }
 513  
         }
 514  156189
     }
 515  
 
 516  
 
 517  
     /**
 518  
      * Return the {@link ProtocolChainInstanceListener} associated with this
 519  
      * {@link Context}
 520  
      * @return ProtocolChainInstanceListener
 521  
      */
 522  
     public ProtocolChainInstanceHandler getProtocolChainInstanceHandler() {
 523  238810
         ProtocolChainInstanceHandler protocolChainInstanceHandler =
 524  
                selectorHandler.getProtocolChainInstanceHandler();
 525  238811
         return protocolChainInstanceHandler != null ?
 526  
            protocolChainInstanceHandler :
 527  
            controller.getProtocolChainInstanceHandler();
 528  
     } 
 529  
     
 530  
     
 531  
     /**
 532  
      * Return the {@link Pipeline} executing this instance.
 533  
      * @return {@link Pipeline}
 534  
      */
 535  
     public Pipeline getPipeline() {
 536  156189
         if (pipeline == null && controller != null){
 537  82701
             pipeline = controller.getPipeline();
 538  
         }
 539  156189
         return pipeline;
 540  
     }
 541  
     
 542  
     
 543  
     /**
 544  
      * Set the {@link Pipeline} that will execute this instance.
 545  
      * @param pipeline  the {@link Pipeline} to set
 546  
      */
 547  
     public void setPipeline(Pipeline pipeline) {
 548  82622
         this.pipeline = pipeline;
 549  82622
     }
 550  
     
 551  
     
 552  
     /**
 553  
      * Set an optional CallbackHandler.
 554  
      * @param ioEvent  the {@link IOEvent} to set
 555  
      */
 556  
     protected void setIOEvent(IOEvent<Context> ioEvent){
 557  61520
         this.ioEvent = ioEvent;
 558  61520
     }
 559  
     
 560  
     /**
 561  
      * Return the current {@link IOEvent} associated with this
 562  
      * instance.
 563  
      * @return IOEvent the current {@link IOEvent} associated with this
 564  
      * instance.
 565  
      */
 566  
     protected IOEvent getIOEvent(){
 567  61520
         return ioEvent;
 568  
     }
 569  
     
 570  
     
 571  
     /**
 572  
      * Return the current {@link Controller#Protocol} this instance is executing.
 573  
      * @return the current Controller.Protocol this instance is executing.
 574  
      */
 575  
     public Controller.Protocol getProtocol() {
 576  216474
         return selectorHandler.protocol();
 577  
     }
 578  
     
 579  
     
 580  
     /**
 581  
      * @Deprecated
 582  
      *
 583  
      * Set the current {@link Controller#Protocol} this instance is executing.
 584  
      * @param protocol The current protocol.
 585  
      */
 586  
     public void setProtocol(Controller.Protocol protocol) {
 587  0
     }
 588  
     
 589  
     
 590  
     /**
 591  
      * Return the current {@link SelectorHandler} this instance is executing.
 592  
      * @return the current {@link SelectorHandler} this instance is executing.
 593  
      */
 594  
     public SelectorHandler getSelectorHandler() {
 595  450889
         return selectorHandler;
 596  
     }
 597  
     
 598  
     /**
 599  
      * Set the current {@link SelectorHandler} this instance is executing.
 600  
      * @param selectorHandler {@link SelectorHandler}
 601  
      */
 602  
     public void setSelectorHandler(SelectorHandler selectorHandler) {
 603  467509
         this.selectorHandler = selectorHandler;
 604  467509
     }
 605  
 
 606  
 
 607  
     /**
 608  
      * Returns {@link AsyncQueueReadable}, assciated with the current
 609  
      * {@link Context}. This method is not threadsafe.
 610  
      * 
 611  
      * @return {@link AsyncQueueReadable}
 612  
      */
 613  
     public AsyncQueueReadable getAsyncQueueReadable() {
 614  0
         if (asyncQueueReadable == null) {
 615  0
             asyncQueueReadable = new AsyncQueueReadableContextWrapper();
 616  
         }
 617  
         
 618  0
         return asyncQueueReadable;
 619  
     }
 620  
 
 621  
     /**
 622  
      * Returns {@link AsyncQueueWritable}, assciated with the current
 623  
      * {@link Context}. This method is not threadsafe.
 624  
      * 
 625  
      * @return {@link AsyncQueueWritable}
 626  
      */
 627  
     public AsyncQueueWritable getAsyncQueueWritable() {
 628  109903
         if (asyncQueueWritable == null) {
 629  40
             asyncQueueWritable = new AsyncQueueWritableContextWrapper();
 630  
         }
 631  
         
 632  109903
         return asyncQueueWritable;
 633  
     }
 634  
 
 635  
     /**
 636  
      * Return the {@linkAsyncQueueReader}
 637  
      * @return the {@linkAsyncQueueReader}
 638  
      */
 639  
     protected AsyncQueueReader getAsyncQueueReader() {
 640  0
         return asyncQueueReader;
 641  
     }
 642  
 
 643  
     /**
 644  
      * Set the {@linkAsyncQueueReader}
 645  
      * @param asyncQueueReader {@linkAsyncQueueReader}
 646  
      */
 647  
     protected void setAsyncQueueReader(AsyncQueueReader asyncQueueReader) {
 648  156189
         this.asyncQueueReader = asyncQueueReader;
 649  156189
     }
 650  
 
 651  
     /**
 652  
      * Return the {@linkAsyncQueueWriter}
 653  
      * @return the {@linkAsyncQueueWriter}
 654  
      */
 655  
     protected AsyncQueueWriter getAsyncQueueWriter() {
 656  0
         return asyncQueueWriter;
 657  
     }
 658  
 
 659  
     /**
 660  
      * Set the {@linkAsyncQueueWriter}
 661  
      * @param asyncQueueWriter {@linkAsyncQueueWriter}
 662  
      */
 663  
     protected void setAsyncQueueWriter(AsyncQueueWriter asyncQueueWriter) {
 664  156189
         this.asyncQueueWriter = asyncQueueWriter;
 665  156189
     }
 666  
     
 667  80
     private class AsyncQueueWritableContextWrapper implements AsyncQueueWritable {
 668  
         /**
 669  
         * {@inheritDoc}
 670  
         */
 671  
         public void writeToAsyncQueue(ByteBuffer buffer) throws IOException {
 672  0
             asyncQueueWriter.write(key, buffer);
 673  0
         }
 674  
 
 675  
         /**
 676  
          * {@inheritDoc}
 677  
          */
 678  
         public void writeToAsyncQueue(ByteBuffer buffer, 
 679  
                 AsyncWriteCallbackHandler callbackHandler) throws IOException {
 680  0
             asyncQueueWriter.write(key, buffer, callbackHandler);
 681  0
         }
 682  
 
 683  
         /**
 684  
          * {@inheritDoc}
 685  
          */
 686  
         public void writeToAsyncQueue(ByteBuffer buffer, 
 687  
                 AsyncWriteCallbackHandler callbackHandler,
 688  
                 AsyncQueueDataProcessor writePreProcessor) throws IOException {
 689  0
             asyncQueueWriter.write(key, buffer, callbackHandler, writePreProcessor);
 690  0
         }
 691  
 
 692  
         /**
 693  
          * {@inheritDoc}
 694  
          */
 695  
         public void writeToAsyncQueue(ByteBuffer buffer,
 696  
                 AsyncWriteCallbackHandler callbackHandler,
 697  
                 AsyncQueueDataProcessor writePreProcessor,
 698  
                 boolean isCloneByteBuffer) throws IOException {
 699  89903
             asyncQueueWriter.write(key, buffer, callbackHandler,
 700  
                     writePreProcessor, isCloneByteBuffer);
 701  89903
         }
 702  
         
 703  
         /**
 704  
         * {@inheritDoc}
 705  
         */
 706  
         public void writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer)
 707  
                 throws IOException {
 708  0
             asyncQueueWriter.write(key, dstAddress, buffer);
 709  0
         }
 710  
 
 711  
         /**
 712  
         * {@inheritDoc}
 713  
         */
 714  
         public void writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer,
 715  
                 AsyncWriteCallbackHandler callbackHandler) throws IOException {
 716  0
             asyncQueueWriter.write(key, dstAddress, buffer, 
 717  
                     callbackHandler);
 718  0
         }
 719  
 
 720  
         /**
 721  
         * {@inheritDoc}
 722  
         */
 723  
         public void writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer,
 724  
                 AsyncWriteCallbackHandler callbackHandler, 
 725  
                 AsyncQueueDataProcessor writePreProcessor) throws IOException {
 726  0
             asyncQueueWriter.write(key, dstAddress, buffer, 
 727  
                     callbackHandler, writePreProcessor);
 728  0
         }
 729  
 
 730  
         /**
 731  
         * {@inheritDoc}
 732  
         */
 733  
         public void writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer,
 734  
                 AsyncWriteCallbackHandler callbackHandler, 
 735  
                 AsyncQueueDataProcessor writePreProcessor, boolean isCloneByteBuffer)
 736  
                 throws IOException {
 737  20000
             asyncQueueWriter.write(key, dstAddress, buffer, 
 738  
                     callbackHandler, writePreProcessor, isCloneByteBuffer);
 739  20000
         }
 740  
     }
 741  
     
 742  0
     private class AsyncQueueReadableContextWrapper implements AsyncQueueReadable {
 743  
         /**
 744  
         * {@inheritDoc}
 745  
         */
 746  
         public void readFromAsyncQueue(ByteBuffer buffer, 
 747  
                 AsyncReadCallbackHandler callbackHandler) throws IOException {
 748  0
             asyncQueueReader.read(key, buffer, callbackHandler);
 749  0
         }
 750  
 
 751  
         /**
 752  
         * {@inheritDoc}
 753  
         */
 754  
         public void readFromAsyncQueue(ByteBuffer buffer, 
 755  
                 AsyncReadCallbackHandler callbackHandler, 
 756  
                 AsyncReadCondition condition) throws IOException {
 757  0
             asyncQueueReader.read(key, buffer, callbackHandler, condition);
 758  0
         }
 759  
 
 760  
         /**
 761  
         * {@inheritDoc}
 762  
         */
 763  
         public void readFromAsyncQueue(ByteBuffer buffer, 
 764  
                 AsyncReadCallbackHandler callbackHandler, 
 765  
                 AsyncReadCondition condition, 
 766  
                 AsyncQueueDataProcessor readPostProcessor) throws IOException {
 767  0
             asyncQueueReader.read(key, buffer, callbackHandler, 
 768  
                     condition, readPostProcessor);
 769  0
         }
 770  
     }
 771  
 }