View Javadoc

1   /*
2    * @(#) $Id: IoProtocolAcceptor.java 210062 2005-07-11 03:52:38Z trustin $
3    */
4   package org.apache.mina.protocol.io;
5   
6   import java.io.IOException;
7   import java.net.SocketAddress;
8   
9   import org.apache.mina.common.ExceptionMonitor;
10  import org.apache.mina.io.IoAcceptor;
11  import org.apache.mina.io.IoSession;
12  import org.apache.mina.protocol.ProtocolAcceptor;
13  import org.apache.mina.protocol.ProtocolFilterChain;
14  import org.apache.mina.protocol.ProtocolProvider;
15  import org.apache.mina.protocol.ProtocolSession;
16  
17  /***
18   * A {@link ProtocolAcceptor} which wraps {@link IoAcceptor} to provide
19   * low-level I/O.
20   * <p>
21   * Please note that the user-defined attributes of {@link ProtocolSession}
22   * and its wrapping {@link IoSession} are shared.
23   * 
24   * @author Trustin Lee (trustin@apache.org)
25   * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $
26   */
27  public class IoProtocolAcceptor implements ProtocolAcceptor
28  {
29      private final IoAcceptor acceptor;
30  
31      private final IoAdapter adapter = new IoAdapter( new IoProtocolSessionManagerFilterChain( this ) );
32  
33      /***
34       * Creates a new instance with the specified {@link IoAcceptor}.
35       */
36      public IoProtocolAcceptor( IoAcceptor acceptor )
37      {
38          if( acceptor == null )
39              throw new NullPointerException( "acceptor" );
40  
41          this.acceptor = acceptor;
42      }
43  
44      /***
45       * Returns the underlying {@link IoAcceptor} instance this acceptor is
46       * wrapping.
47       */
48      public IoAcceptor getIoAcceptor()
49      {
50          return acceptor;
51      }
52  
53      public void bind( SocketAddress address, ProtocolProvider provider )
54              throws IOException
55      {
56          acceptor.bind( address, adapter.adapt( provider ) );
57      }
58      
59      public void unbind( SocketAddress address )
60      {
61          acceptor.unbind( address );
62      }
63      
64      public ProtocolFilterChain getFilterChain()
65      {
66          return adapter.getFilterChain();
67      }
68      
69      public ExceptionMonitor getExceptionMonitor()
70      {
71          return acceptor.getExceptionMonitor();
72      }
73  
74      public void setExceptionMonitor( ExceptionMonitor monitor )
75      {
76          acceptor.setExceptionMonitor( monitor );
77      }
78  }