View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  
21  package org.apache.directory.server.protocol.shared;
22  
23  import java.io.IOException;
24  import java.net.SocketAddress;
25  import java.util.concurrent.Executor;
26  import java.util.concurrent.Executors;
27  
28  import org.apache.mina.common.IoHandler;
29  import org.apache.mina.common.IoServiceConfig;
30  import org.apache.mina.common.ThreadModel;
31  import org.apache.mina.filter.executor.ExecutorFilter;
32  
33  /**
34   * @version $Rev: 655126 $ $Date: 2008-05-10 18:30:45 +0200 (Sa, 10 Mai 2008) $
35   * @org.apache.xbean.XBean
36   */
37  public class SocketAcceptor extends org.apache.mina.transport.socket.nio.SocketAcceptor
38  {
39  
40      private static final int DEFAULT_THREADS = 10;
41  
42      public SocketAcceptor( Executor logicExecutor )
43      {
44          super( Runtime.getRuntime().availableProcessors(), Executors.newCachedThreadPool());
45          
46          if ( logicExecutor == null )
47          {
48              logicExecutor = Executors.newFixedThreadPool( DEFAULT_THREADS );
49          }
50          
51          getFilterChain().addLast( "executor", new ExecutorFilter( logicExecutor ) );
52      }
53  
54      public void bind( SocketAddress address, IoHandler ioHandler, IoServiceConfig tcpConfig ) throws IOException
55      {
56          tcpConfig.setThreadModel( ThreadModel.MANUAL );
57          super.bind( address, ioHandler, tcpConfig );
58      }
59  
60      public void unbind( SocketAddress address )
61      {
62          super.unbind(address);
63      }
64  }