View Javadoc

1   /*
2    * @(#) $Id: IoProtocolAcceptor.java 327113 2005-10-21 06:59:15Z 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 The Apache Directory Project (dev@directory.apache.org)
25   * @version $Rev: 327113 $, $Date: 2005-10-21 15:59:15 +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 ProtocolSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
65      {
66          return adapter.toProtocolSession( acceptor.newSession( remoteAddress, localAddress ) );
67      }
68  
69      public ProtocolFilterChain getFilterChain()
70      {
71          return adapter.getFilterChain();
72      }
73      
74      public ExceptionMonitor getExceptionMonitor()
75      {
76          return acceptor.getExceptionMonitor();
77      }
78  
79      public void setExceptionMonitor( ExceptionMonitor monitor )
80      {
81          acceptor.setExceptionMonitor( monitor );
82      }
83  }