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  package org.apache.directory.server.protocol.shared;
20  
21  
22  import java.io.IOException;
23  import java.net.SocketAddress;
24  import java.util.concurrent.Executor;
25  import java.util.concurrent.Executors;
26  
27  import org.apache.mina.common.IoHandler;
28  import org.apache.mina.common.IoServiceConfig;
29  import org.apache.mina.common.ThreadModel;
30  import org.apache.mina.filter.executor.ExecutorFilter;
31  
32  
33  /**
34   * Extension around a MINA DatagramAcceptor to facilitate better usage with Spring.
35   *
36   * @version $Rev: 584802 $ $Date: 2007-10-15 17:11:31 +0200 (Mo, 15 Okt 2007) $
37   * @org.apache.xbean.XBean
38   */
39  public class DatagramAcceptor extends org.apache.mina.transport.socket.nio.DatagramAcceptor
40  {
41      private static final int DEFAULT_THREADS = 10;
42  
43  
44      public DatagramAcceptor( Executor logicExecutor )
45      {
46          super();
47          if ( logicExecutor == null )
48          {
49              logicExecutor = Executors.newFixedThreadPool( DEFAULT_THREADS );
50          }
51          getFilterChain().addLast( "executor", new ExecutorFilter( logicExecutor ) );
52      }
53  
54  
55      public void bind( SocketAddress address, IoHandler ioHandler, IoServiceConfig udpConfig ) throws IOException
56      {
57          udpConfig.setThreadModel( ThreadModel.MANUAL );
58          super.bind( address, ioHandler, udpConfig );
59      }
60  
61  
62      public void unbind( SocketAddress address )
63      {
64          super.unbind(address);
65      }
66  
67  }