View Javadoc

1   /*
2    *   @(#) $Id: IoSessionManagerFilterChain.java 210062 2005-07-11 03:52:38Z trustin $
3    *
4    *   Copyright 2004 The Apache Software Foundation
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   *
18   */
19  package org.apache.mina.io;
20  
21  import org.apache.mina.common.ByteBuffer;
22  import org.apache.mina.common.IdleStatus;
23  
24  /***
25   * An {@link IoFilterChain} that forwards all events
26   * except <tt>filterWrite</tt> to the {@link IoSessionFilterChain}
27   * of the recipient session.
28   * <p>
29   * This filter chain is used by implementations of {@link IoSessionManager}s.
30   * 
31   * @author The Apache Directory Project (dev@directory.apache.org)
32   * @author Trustin Lee (trustin@apache.org)
33   * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $
34   */
35  public abstract class IoSessionManagerFilterChain extends AbstractIoFilterChain {
36  
37      private final IoSessionManager manager;
38  
39      protected IoSessionManagerFilterChain( IoSessionManager manager )
40      {
41          this.manager = manager;
42      }
43      
44      public IoSessionManager getManager()
45      {
46          return manager;
47      }
48      
49      protected IoFilter createTailFilter()
50      {
51          return new IoFilter()
52          {
53              public void sessionOpened( NextFilter nextFilter, IoSession session ) throws Exception
54              {
55                  ( ( IoSessionFilterChain ) session.getFilterChain() ).sessionOpened( session );
56              }
57  
58              public void sessionClosed( NextFilter nextFilter, IoSession session ) throws Exception
59              {
60                  ( ( IoSessionFilterChain ) session.getFilterChain() ).sessionClosed( session );
61              }
62  
63              public void sessionIdle( NextFilter nextFilter, IoSession session,
64                                      IdleStatus status ) throws Exception
65              {
66                  ( ( IoSessionFilterChain ) session.getFilterChain() ).sessionIdle( session, status );
67              }
68  
69              public void exceptionCaught( NextFilter nextFilter,
70                                          IoSession session, Throwable cause ) throws Exception
71              {
72                  ( ( IoSessionFilterChain ) session.getFilterChain() ).exceptionCaught( session, cause );
73              }
74  
75              public void dataRead( NextFilter nextFilter, IoSession session,
76                                   ByteBuffer buf ) throws Exception
77              {
78                  ( ( IoSessionFilterChain ) session.getFilterChain() ).dataRead( session, buf );
79              }
80  
81              public void dataWritten( NextFilter nextFilter, IoSession session,
82                                      Object marker ) throws Exception
83              {
84                  ( ( IoSessionFilterChain ) session.getFilterChain() ).dataWritten( session, marker );
85              }
86  
87              public void filterWrite( NextFilter nextFilter,
88                                       IoSession session, ByteBuffer buf, Object marker ) throws Exception
89              {
90                  nextFilter.filterWrite( session, buf, marker );
91              }
92          };
93      }
94  }