Spring Servlet 3拡張モジュールメモ


Servlet 3.0
Aync WebRequest.java
非同期要求インターフェースは、NativeWebRequest を継承する.
インターフェース
       
 /**
         * Set the time required for concurrent handling to complete.
         * This property should not be set when concurrent handling is in progress,
         * i.e. when {@link #isAsyncStarted()} is {@code true}.
         * @param timeout amount of time in milliseconds; {@code null} means no
         *  timeout, i.e. rely on the default timeout of the container.
         */
        //      
        void setTimeout(Long timeout);

        /**
         * Add a handler to invoke when concurrent handling has timed out.
         */
        //       
        void addTimeoutHandler(Runnable runnable);

        /**
         * Add a handle to invoke when request processing completes.
         */
        //           
        void addCompletionHandler(Runnable runnable);

        /**
         * Mark the start of asynchronous request processing so that when the main
         * processing thread exits, the response remains open for further processing
         * in another thread.
         * @throws IllegalStateException if async processing has completed or is not supported
         */
        //        ,    Context
        void startAsync();

        /**
         * Whether the request is in async mode following a call to {@link #startAsync()}.
         * Returns "false" if asynchronous processing never started, has completed,
         * or the request was dispatched for further processing.
         */
        //                 ,false          ,      ,              
        boolean isAsyncStarted();

        /**
         * Dispatch the request to the container in order to resume processing after
         * concurrent execution in an application thread.
         */
        //       ,        
        void dispatch();

        /**
         * Whether asynchronous processing has completed.
         */
        //          
        boolean isAsyncComplete();
Standard Servlet AsyncWebRequest.java
ServletWebRequestを継承し、AyncWebrequest、Aync Listener、標準非同期ウェブリクエストの実現クラスを実現します.コード
     
/**
      * {@inheritDoc}
      * <p>In Servlet 3 async processing, the timeout period begins after the
      * container processing thread has exited.
      */
     public void setTimeout(Long timeout) {
         Assert.state(!isAsyncStarted(), "Cannot change the timeout with concurrent handling in progress");//          
         this.timeout = timeout;
     }

     public boolean isAsyncStarted() {
         return ((this.asyncContext != null) && getRequest().isAsyncStarted());//       ,            ,     AsyncContext.dispatch()   ,  AsynContext.complete ,   false.


     }

     /**
      * Whether async request processing has completed.
      * <p>It is important to avoid use of request and response objects after async
      * processing has completed. Servlet containers often re-use them.
      */
     public boolean isAsyncComplete() {
         return this.asyncCompleted.get();//           
     }

     public void startAsync() {
         Assert.state(getRequest().isAsyncSupported(),
                 "Async support must be enabled on a servlet and for all filters involved " +
                 "in async request processing. This is done in Java code using the Servlet API " +
                 "or by adding \"<async-supported>true</async-supported>\" to servlet and " +
                 "filter declarations in
                web.xml.");//            
         Assert.state(!isAsyncComplete(), "Async processing has already completed");
         if (isAsyncStarted()) {//                
             return;
         }
         this.asyncContext = getRequest().startAsync(getRequest(), getResponse());
         this.asyncContext.addListener(this);
         if (this.timeout != null) {
             this.asyncContext.setTimeout(this.timeout);
         }
     }

     public void dispatch() {
         Assert.notNull(this.asyncContext, "Cannot dispatch without an AsyncContext");
         this.asyncContext.dispatch();
     }

     // ---------------------------------------------------------------------
     // Implementation of AsyncListener methods
     // ---------------------------------------------------------------------

     public void onStartAsync(AsyncEvent event) throws IOException {
     }

     public void onError(AsyncEvent event) throws IOException {
     }

     public void onTimeout(AsyncEvent event) throws IOException {
         for (Runnable handler : this.timeoutHandlers) {
             handler.run();
         }
     }

     public void onComplete(AsyncEvent event) throws IOException {
         for (Runnable handler : this.completionHandlers) {
             handler.run();
         }
         this.asyncContext = null;
         this.asyncCompleted.set(true);//          
     }
NoSupport Aync WebRequest.java
非同期処理モードに対応しないウェブ要求DeferredResoult Processing Interceptor.java
DeferredResoult処理プロセスブロックstart asyncの前で、タイムアウト後/非同期処理が完了した後/ネットワークがタイムアウトした後、ブロックをトリガします.
DeferredResoult Processing InterceptorAdapter.java
抽象類はDeferredResoult Processing Interceptorを実現して、暇を作ってを実現します.
DeferredResoult InterceptorChain.java
DeferredResoult Processing Interceptorを呼び出す補助類DeferredResoult.java
繰延結果は、2つのスレッドで伝達されるオブジェクト結果である.
Comprableインターフェースを実現し、PriorityQueキューへの加入の正確な順序を保証する.
Callable Processing Interceptor.java
CallableスクリーンCallable Processing InterceptorAdapter.java
抽象的なクラスはCallable Processing Interceptorインターフェースを実現して、暇はを実現します.
Callable InterceptorChain.java
Callable Processing Interceptorの補助クラスを呼び出します.
Timeout Callable Processing Interceptor.java
Callable Processing InterceptorAdapter を継承します.
タイムアウト処理を実現するTimeout DeferredResoult Processing Interceptor.java
DeferredResoult Processing InterceptorAdapter を継承します.
タイムアウト処理を実現するWebAsync Task.java
ウェブ非同期タスクCallableクラスを含み、タイムアウト時間、または名前を実行しています.
WebAsyncUtils.java
get Aync Managerを実現するcreateAsync Webrequestを実現するWebAsync Manager.java
CallabersとDeferredResoultsに対して起動する管理、スクリーンショットの注入、Excutorの注入などを含みます.
非同期処理のエントリクラス