KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > transport > nio > tcp > RmiChannelHandlerFactory


1 package org.sapia.ubik.rmi.server.transport.nio.tcp;
2
3 import org.sapia.ubik.net.Pool;
4 import org.sapia.ubik.net.ServerAddress;
5 import org.sapia.ubik.net.nio.ChannelHandler;
6 import org.sapia.ubik.net.nio.ChannelHandlerFactory;
7 import org.sapia.ubik.rmi.RemoteRuntimeException;
8
9 /**
10  * @author Yanick Duchesne
11  *
12  * <dl>
13  * <dt><b>Copyright: </b>
14  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
15  * Source Software </a>. All Rights Reserved.</dd>
16  * </dt>
17  * <dt><b>License: </b>
18  * <dd>Read the license.txt file of the jar or visit the <a
19  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
20  * OSS web site</dd>
21  * </dt>
22  * </dl>
23  */

24 public class RmiChannelHandlerFactory implements ChannelHandlerFactory {
25
26   private AddressProvider _provider;
27   private Pool _handlers;
28   private int _bufsize;
29
30   RmiChannelHandlerFactory(AddressProvider provider, int bufsize) {
31     _handlers = new ChannelHandlerPool(this);
32     _provider = provider;
33     _bufsize = bufsize;
34   }
35
36   /**
37    * @see org.sapia.ubik.net.nio.ChannelHandlerFactory#createHandler()
38    */

39   public ChannelHandler createHandler() {
40     try {
41       return (RmiChannelHandler) _handlers.acquire();
42     } catch(Exception JavaDoc e) {
43       throw new RemoteRuntimeException("Could not acquire channel handler", e);
44     }
45   }
46
47   ServerAddress getServerAddress() {
48     return _provider.getAddress();
49   }
50
51   void release(RmiChannelHandler handler) {
52     _handlers.release(handler);
53   }
54
55   static final class ChannelHandlerPool extends Pool {
56
57     private RmiChannelHandlerFactory _owner;
58
59     public ChannelHandlerPool(RmiChannelHandlerFactory owner) {
60       _owner = owner;
61     }
62
63     /**
64      * @see org.sapia.ubik.net.Pool#doNewObject()
65      */

66     protected Object JavaDoc doNewObject() throws Exception JavaDoc {
67       return new RmiChannelHandler(_owner, _owner._bufsize);
68     }
69   }
70
71 }
72
Popular Tags